Skip to content

Commit

Permalink
Fixes Issue #126: adding conditionals to workflow shema (#144)
Browse files Browse the repository at this point in the history
* first version of the JSON schema. Fixes issue #27

* addressing feedback from review

* addressed steps and agents definition

* made agents also array

* first version of the agent schema that validares the agents used in POC0

* added code section

* included suggestions and changes from @akihikokuroda's PR #139 review comments

* first version of schema with conditionals (both if/then/else and case/do/default). Added some tests files in test/schema/conditional_workdlow.<yml/json>

* feat(internal): Refactor to provide base Agent class & allow for alternate runtimes (#146)

Signed-off-by: Nigel Jones <[email protected]>

* feat(bee-hive) add schema validator (#147)

Signed-off-by: Akihiko Kuroda <[email protected]>

* corrected schema according to @akihikokuroda comments and added a new test based on comments discussions: funnier_workflow.<yml|json>

---------

Signed-off-by: Nigel Jones <[email protected]>
Signed-off-by: Akihiko Kuroda <[email protected]>
Co-authored-by: Nigel Jones <[email protected]>
Co-authored-by: Akihiko (Aki) Kuroda <[email protected]>
  • Loading branch information
3 people authored and George Liu committed Jan 28, 2025
1 parent 0722a6f commit e80b4ea
Show file tree
Hide file tree
Showing 6 changed files with 302 additions and 38 deletions.
66 changes: 66 additions & 0 deletions test/schema/conditional_workflow.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"apiVersion": "beehive/v1",
"kind": "Workflow",
"metadata": {
"name": "beehive-deployment",
"labels": {
"app": "example2"
}
},
"spec": {
"strategy": {
"type": "sequence"
},
"template": {
"metadata": {
"name": "beehive-deployment",
"labels": {
"app": "example",
"use-case": "test"
}
}
},
"agents": [
"agent1",
"agent2",
"agent3"
],
"exception": "step3",
"steps": [
{
"name": "step1",
"agent": "agent1",
"condition": [
{
"if": "{$in.some_condition == True}",
"then": "step2",
"else": "step3"
}
]
},
{
"name": "step2",
"agent": "agent2"
},
{
"name": "step3",
"agent": "agent3",
"condition": [
{
"case": "{$in.some_condition == True}",
"do": "step2"
},
{
"case": "{$in.some_condition == False}",
"do": "step3"
},
{
"default": {
"do": "step3"
}
}
]
}
]
}
}
38 changes: 38 additions & 0 deletions test/schema/conditional_workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
apiVersion: beehive/v1
kind: Workflow
metadata:
name: beehive-deployment
labels:
app: example2
spec:
strategy:
type: sequence
template:
metadata:
name: beehive-deployment
labels:
app: example
use-case: test
agents:
- agent1
- agent2
- agent3
exception: step3
steps:
- name: step1
agent: agent1
condition:
- if: '{$in.some_condition == True}'
then: step2
else: step3
- name: step2
agent: agent2
- name: step3
agent: agent3
condition:
- case: '{$in.some_condition == True}'
do: step2
- case: '{$in.some_condition == False}'
do: step3
- default:
do: step3
56 changes: 56 additions & 0 deletions test/schema/funnier_workflow.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"apiVersion": "beehive/v1alpha1",
"kind": "Workflow",
"metadata": {
"name": "beehive-deployment",
"labels": {
"app": "mas-example"
}
},
"spec": {
"strategy": {
"type": "condition",
"output": "nonal"
},
"template": {
"metadata": {
"labels": {
"app": "mas-example"
}
},
"agents": [
{
"name": "expert"
},
{
"name": "colleague"
}
],
"prompt": "Tell me a joke about IBM",
"start": "expert",
"steps": [
{
"name": "expert",
"agent": "expert",
"condition": [
{
"default": null,
"do": "colleague"
}
]
},
{
"name": "colleague",
"agent": "colleague",
"condition": [
{
"if": "(input.find('funnier') != -1)",
"then": "expert",
"else": "end"
}
]
}
]
}
}
}
31 changes: 31 additions & 0 deletions test/schema/funnier_workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: beehive/v1alpha1
kind: Workflow
metadata:
name: beehive-deployment
labels:
app: mas-example
spec:
strategy:
type: condition
output: nonal
template:
metadata:
labels:
app: mas-example
agents:
- name: expert
- name: colleague
prompt: Tell me a joke about IBM
start: expert
steps:
- name: expert
agent: expert
condition:
- default:
do: colleague
- name: colleague
agent: colleague
condition:
- if: { input.find('funnier') != -1 }
then: expert
else: end
File renamed without changes.
149 changes: 111 additions & 38 deletions tools/workflow_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,121 @@
"title": "BeeAI Hive",
"description": "A schema for defining Bee Hive workflows in YAML or JSON",
"type": "object",
"metadata": {
"type": "object",
"properties": {
"name": {
"properties": {
"metadata": {
"apiVersion": {
"type": "string",
"description": "workflow name"
"description": "beehive/v1"
},
"labels": {
"type": "object",
"description": "workflow labels, key: value pairs"
}
},
"required": [
"name"
]
},
"spec": {
"strategy": {
"type": "sequence"
},
"properties": {
"name": {
"kind": {
"type": "string",
"description": "workflow name"
"description": "Workflow"
},
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "workflow name"
},
"labels": {
"type": "object",
"description": "workflow labels, key: value pairs"
}
},
"labels": {
"type": "object",
"description": "workflow labels, key: value pairs"
"required": [
"name"
]
},
"spec": {
"type": "object",
"properties": {
"strategy": {
"type": "object",
"properties": {
"type": {
"type":"string",
"description": "sequence, condition"
}
}
},
"template": {
"type": "object",
"properties": {
"meatdata": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "workflow name"
},
"labels": {
"type": "object",
"description": "workflow labels, key: value pairs"
}
}
}
}
},
"agents": {
"type": "array",
"items": {
"type": "string"
}
},
"exception": {
"type": "string"
},
"prompt": {
"type": "string"
},
"steps": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "step name"
},
"agent": {
"type": "string",
"description": "the agent for this step"
},
"condition": {
"type": "array",
"description": "if/then/else or case/do/default condition",
"items": {
"type": "object",
"properties": {
"if": {
"type": "string"
},
"then": {
"type": "string"
},
"else": {
"type": "string"
},
"case": {
"type": "string"
},
"do": {
"type": "string"
},
"default": {
"type": "string"
}
}
}
}
},
"required": [
"name",
"agent"
]
}
}
}
}
},
"agents": {
"type": "array",
"items": {
"type": "string"
}
},
"steps": {
"type": "array",
"items": {
"type": "string"
}
},
"exception": "string"
}
}

0 comments on commit e80b4ea

Please sign in to comment.