julep-ai / julep

A new DSL and server for AI agents and multi-step tasks
https://julep.ai
Apache License 2.0
2.67k stars 904 forks source link

[Bug]: client.tasks.create does not handle subworkflows #867

Closed creatorrr closed 2 days ago

creatorrr commented 1 week ago

📜 Description

No response

👟 Reproduction steps

[ins] In [1]: from julep import Julep, Client; import yaml

[ins] In [2]: [api_key, *_] = !jwt encode --secret YOUR_API_KEY --alg HS512 --exp=$(date -d '+60 day' +%s) --sub
         ...: '00000000-0000-0000-0000-000000000000' '{}'

[ins] In [3]: client = Client(api_key=api_key, environment="local_multi_tenant")

[ins] In [4]: task_def = yaml.safe_load(open("computer-use.yaml"))

[ins] In [5]: task_def.keys()
Out[5]: dict_keys(['name', 'tools', 'input_schema', 'main', 'run_browser', 'check_goal_status'])

[ins] In [6]: [agent, *_] = client.agents.list().items

[ins] In [7]: task = client.tasks.create(agent_id=agent.id, **task_def)

[ins] In [8]: task = client.tasks.get(task_id=task.id)

[ins] In [9]: task.model_dump().keys()
Out[9]: dict_keys(['id', 'created_at', 'main', 'name', 'updated_at', 'description', 'inherit_tools', 'input_schema', 'metadata', 'tools', 'agent_id'])

👀 Have you searched previous issues to see if this has been raised before?

whiterabbit1983 commented 4 days ago

@creatorrr could you plz elaborate what to fix here? Here's the code sample:

client = Client(base_url=base_url, api_key=dev_api_key)

agent = client.agents.create(
    name="Jessica",
    about="a helpful AI assistant",
    model="gpt-4o",
)
print(f"agent: {agent.id}")
task_def = yaml.safe_load(open("wf.yaml"))
task = client.tasks.create(agent_id=agent.id, **task_def)
print("task ID", task.id)
t = client.tasks.get(task_id=task.id)
print("+++", t.run_browser)
print("++++", t.check_goal_status)

and here's the output

+++ [{'arguments': {'messages': '_.messages', 'recall': 'False', 'session_id': '_.julep_session_id'}, 'kind_': 'tool_call', 'tool': 'session_chat'}, {'evaluate': {'content': '_.choices[0].message.content', 'tool_calls': "[ { 'tool_call_id': tool_call.id, 'action': load_json(tool_call.function.arguments)['action'], 'text': load_json(tool_call.function.arguments).get('text'), 'coordinate': load_json(tool_call.function.arguments).get('coordinate') } for tool_call in _.choices[0].message.tool_calls or [] if tool_call.type == 'function']"}, 'kind_': 'evaluate'}, {'foreach': {'do': {'arguments': {'action': "_.action if not (str(_.get('text', '')).startswith('http') and _.action == 'type') else 'navigate'", 'connect_url': 'inputs[0].cdp_url', 'coordinate': "_.get('coordinate')", 'text': "_.get('text')"}, 'kind_': 'tool_call', 'tool': 'perform_browser_action'}, 'in_': '_.tool_calls'}, 'kind_': 'foreach'}, {'evaluate': {'contents': "[{ 'type': 'image_url', 'image_url': { 'url': result['base64_image'], } } if result['base64_image'] is not None else { 'type': 'text', 'text': result['output'] if result['output'] is not None else 'done' } for result in _]"}, 'kind_': 'evaluate'}, {'evaluate': {'messages': "[{'content': [_.contents[i]], 'role': 'tool', 'name': 'computer', 'tool_call_id': outputs[1].tool_calls[i].tool_call_id} for i in range(len(_.contents))]"}, 'kind_': 'evaluate'}, {'arguments': {'cdp_url': 'inputs[0].cdp_url', 'julep_session_id': 'inputs[0].julep_session_id', 'messages': '_.messages', 'workflow_label': "'check_goal_status'"}, 'kind_': 'yield', 'workflow': 'check_goal_status'}]
++++ [{'if_': 'len(_.messages) > 0', 'kind_': 'if_else', 'then': {'arguments': {'cdp_url': '_.cdp_url', 'julep_session_id': '_.julep_session_id', 'messages': '_.messages', 'workflow_label': "'run_browser'"}, 'kind_': 'yield', 'workflow': 'run_browser'}}]

I can't do model_dump() because I am getting an exception: TypeError: 'MockValSer' object cannot be converted to 'SchemaSerializer', but this is out of scope

HamadaSalhab commented 4 days ago

@whiterabbit1983 which sdk version are you using? I've just checked it again on the latest version as of now which is1.42.0, and it still produces the same behaviour as reported in the issue.

whiterabbit1983 commented 4 days ago

@HamadaSalhab I use the latest from the repo

Upd: Wait, now this is reproducible