-
Notifications
You must be signed in to change notification settings - Fork 586
Add Optional files/todos Propagation and Fix Sub-Agent State Issues #55
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: master
Are you sure you want to change the base?
Conversation
…in create_deep_agent
…d recursion errors
fix silly bug, let sub agents be None
* Cloudflare MCP used * cleanup * Add example output * example log fixed, removed unused internet_search to not confuse example * Remove edit to reqs * Remove edit * Update to simplify mcp adapter example, adds to readme only * cleanup title and comments * Make more uniform with previous example lang * More direct linkage to lc-mcp-adapter repo * clean up example output to match some examples from docs * Update README.md * Update README.md * Update README.md * Update README.md --------- Co-authored-by: Harrison Chase <hw.chase.17@gmail.com>
* FROM ryaneggz/13-use-custom-model-with-ollama TO hwchase17/deepagents@main (langchain-ai#24) Co-authored-by: Ryan Eggleston <kre8mymedia@gmail.com>
…chain-ai#34) This pull request addresses a performance inefficiency in the example code located in README.md and examples/research/research_agent.py. Changes: The TavilyClient was previously being instantiated inside the internet_search tool function. This resulted in a new client object being created on every single tool call, which is inefficient. This commit refactors the code to initialize the TavilyClient once at the module level. The single client instance is then reused across all subsequent calls to the internet_search tool. Benefits: Performance: Reduces the overhead of creating new client objects repeatedly in an agentic loop. Best Practices: Aligns the example code with the best practice for handling API clients, providing a better template for users of the library.
This comment was marked as spam.
This comment was marked as spam.
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.
Excellent work on identifying and fixing these critical state management issues! This PR addresses fundamental problems that could break multi-step workflows.
Key Strengths:
- State Isolation: The
sub_state
approach prevents parent state corruption - crucial for maintaining conversation history - Schema Consistency: Adding
state_schema=DeepAgentState
ensures proper field propagation - Memory Optimization: Optional propagation flags reduce overhead for lightweight agents
- Backward Compatibility: Maintains async support and existing interfaces
Technical Review:
- The isolated state approach is architecturally sound
- Optional propagation flags provide good flexibility
- Performance optimization through config reuse is well thought out
Suggestions:
- Consider adding unit tests for state isolation scenarios
- Documentation update for the new propagation flags would be helpful
- Migration guide for existing sub-agent implementations
This fix is essential for production stability. The state corruption issue could cause significant problems in real-world deployments.
Problem
The original
sub_agent.py
had two critical issues that disrupted workflows:task
tool overwrote the parent agent's state withstate["messages"] = [...]
, erasing prior user/assistant messages. This broke multi-step workflows requiring preserved context.general-purpose
sub-agent was created withoutstate_schema
, defaulting to LangGraph'sAgentState
. This causedfiles
andtodos
fields to be dropped during delegation, breaking state persistence.Additionally, the tool passed the full
state
(includingfiles
andtodos
) to all sub-agents, causing unnecessary memory overhead for lightweight agents likeanalyzer
.Fix
To address these issues, I made the following changes to
sub_agent.py
:sub_state
:state["messages"]
mutation with a newsub_state
dictionary containing only the task description and selected fields.state_schema=DeepAgentState
to thegeneral-purpose
sub-agent creation.files
andtodos
fields consistently.include_files
andinclude_todos
flags toSubAgent
(default:False
).subagent_configs
dictionary for efficient flag lookups at initialization.files
/todos
tosub_state
and update inCommand(update=...)
if flagged.Command
return to reuse the existingconfig
variable, removing a redundant lookup.ainvoke
for asynchronous execution, ensuring compatibility.Behavior
files
andtodos
for compatibility.messages
unlessinclude_files
orinclude_todos
is explicitly enabled, reducing memory overhead.