-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MultiAgentWorkflow #17237
base: main
Are you sure you want to change the base?
MultiAgentWorkflow #17237
Conversation
llama-index-core/llama_index/core/agent/multi_agent/multi_agent_workflow.py
Outdated
Show resolved
Hide resolved
```python | ||
workflow = MultiAgentWorkflow( | ||
agents=[...], | ||
initial_state={"counter": 0}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ooc how is the state modified? by the user or by the agent?
are there constraints in 1) number of keys, and 2) the types of the values?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the state is thrown into the workflow context, so FunctionToolWithContext
can access it and modify it. The constraints are the same as a normal workflow context imo -- if its not serializable, you might have issues in certain runtimes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh i see
return result.confirmation | ||
``` | ||
|
||
When this function is called, it will block the workflow execution until the user sends the required confirmation event. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when is this function called?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By an agent, its meant to be an agent tool. I'll make this clearer.
You could also subclass or use this in your own workflows though
@@ -0,0 +1,257 @@ | |||
# Multi-Agent Workflows | |||
|
|||
The MultiAgentWorkflow uses Workflow Agents to allow you to create a system of multiple agents that can collaborate and hand off tasks to each other based on their specialized capabilities. This enables building more complex agent systems where different agents handle different aspects of a task. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we mention that this is built upon our core workflows classes?
the user will at least know that the syntax for running workflows and handling the output event stream is the same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea I should at least link to it somewhere, good point
async for event in handler.stream_events(): | ||
if hasattr(event, "delta"): | ||
print(event.delta, end="", flush=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are these agents streaming dedicated events that can be shown in the UI (we're using this in create-llama).
There we're having the AgentRunEvent
see
https://github.com/run-llama/create-llama/blob/main/templates/components/multiagent/python/app/workflows/events.py
(ignore to_response
- this is for conversion to vercel data streams, this concern can be done outside of this PR)
here is an example using it to send the progress of tool calls:
https://github.com/run-llama/create-llama/blob/eec237c5feea1af9cdd5b276d34ebe3b8d0fd185/templates/components/multiagent/python/app/workflows/tools.py#L141
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! That is the main intention for these events, to show progress in some UI.
I didn't capture the concept of "in progress" or "completed" with this, its mostly all just events at points in time (here's the agent input, here's the agent stream, here's the agent output, heres a tool im about to call, here's the tool output) -- I could refactor, but not sure if its needed or not
workflow = MultiAgentWorkflow( | ||
agent_configs=[calculator_agent, retriever_agent] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about defining the entrypoint here?
workflow = MultiAgentWorkflow( | |
agent_configs=[calculator_agent, retriever_agent] | |
workflow = MultiAgentWorkflow( | |
entrypoint=[retriever_agent] | |
agent_configs=[calculator_agent, retriever_agent] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yea, that is actually a better UX (although I think there can only be one entry point 🤔)
async for event in handler.stream_events(): | ||
if hasattr(event, "delta"): | ||
print(event.delta, end="", flush=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could then also add a helper that is printing the events in a nice way for examples:
async for event in handler.stream_events(): | |
if hasattr(event, "delta"): | |
print(event.delta, end="", flush=True) | |
async for event in handler.stream_events(): | |
print_event(event) |
tools=[ | ||
FunctionTool.from_defaults(fn=add), | ||
FunctionTool.from_defaults(fn=subtract), | ||
], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
possible in Python to wrap FunctionTool automatically, e.g.?
tools=[ | |
FunctionTool.from_defaults(fn=add), | |
FunctionTool.from_defaults(fn=subtract), | |
], | |
tools=[ | |
add, subtract, | |
], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be possible, although now with FunctionTool and FunctionToolWithContext, I'll need to think a little harder about how to detect when each one is needed
A multi agent system implemented as a prebuilt workflow.
Currently, supports
FunctionToolWithContext
ctx.wait_for_event()
Usage Example:
https://gist.github.com/logan-markewich/f91929a4d0c7e41515bed1d2851c566c
Current Diagram:
Todo: