-
Notifications
You must be signed in to change notification settings - Fork 29
fix(ToolNode): pass correct inputs to tool nodes #389
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
base: main
Are you sure you want to change the base?
Conversation
507bbdf to
22bb0d3
Compare
Scenario: 1. LLM invokes multiple instances of the same tool, such as ["Web Search", "Web Search"] 1. This line schedules multiple tool nodes to run in parallel. 1. Each tool node picks up the first matching tool call from the state. This means that both of the web search tools will execute the first tool call.
22bb0d3 to
61b4635
Compare
andreitava-uip
left a comment
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 design is overall what I was going for as well, however this PR has 2 issues:
- We still need to pass the entire state to the node, even with the send API. The wrapper requires the state to be passed as many of them rely on it (static args wrapper, job attachments wrapper)
- This is more of a nit, but It would be nice for our ToolNode to support both direct ToolCalls and entire state passing. These changes as they are now force anybody wanting to use the node into the Send API.
|
|
||
| async def _afunc( | ||
| self, state: Any, config: RunnableConfig | None = None | ||
| self, state: AgentGraphState, config: RunnableConfig | None = None |
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.
We need the entire state here, including the input args, for which there is the runtime dynamically created type CompleteAgentGraphState. Unfortunately since it's created at runtime we cannot annotate with it.
Generally for nodes langgraph validates the state using the annotation info, that being said, now that I think about it more, I think here it's always passing the entire state no matter what.
We should also probably configure AgentGraphState to allow extra fields on model validation... hmm
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.
I'm OK with Any. Both of them are fine because there's no type enforcement at runtime anyway.
| tool_call: Optional[ToolCall] = ( | ||
| None # This field is used to pass tool inputs to tool nodes. | ||
| ) |
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.
- why is this added to the state?
- it should be added under internal_state
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.
We don't want to merge it back to the state, right?
Great, so the change to this PR is quite small, we can just pass in something along the lines of |
Scenario:
Fix is to send the correct
ToolCalldetails to the tool node. This also simplifies the tool node implementation.Development Package