Repository navigation
Description
Describe the bug
When you have two agents in sequence, in this case in a LoopAgent, the second agent is often unable to see items stored in the state of the previous agent.
To Reproduce
This has been hard to replicate as a timing issue, but seems to be OK on smaller prompts, but more noticable on a larger prompt.
e.g
graph_builder1 = LlmAgent(
name="GraphBuilder1",
model=LLM_MODEL1,
generate_content_config=types.GenerateContentConfig(
temperature=0.2
),
instruction=GENERATE_KG_PROMPT.format(knowledge_graph_key="knowledge_graph1"),
tools=[store_knowledge_graph],
output_key='knowledge_graph1',
)
graph_reviewer1 = LlmAgent(
name="GraphReviewer1",
model=LLM_MODEL2,
instruction=REVIEW_PROMPT.format(knowledge_graph_key="knowledge_graph1"),
tools=[validate_turtle, load_knowledge_graph], # <--- can't find key knowledge_graph1
)
kg_refinement_loop1 = LoopAgent(
name="KGRefinementLoop1",
max_iterations=5,
sub_agents=[
graph_builder1,
graph_reviewer1,
StopIfComplete(name="StopChecker1", status_key="graph_status1"),
],
)
from: https://github.com/hammertoe/GraphCycle/blob/main/graphcycle/agent.py#L220C1-L235C2
**Expected
**
A subsequent agent should be able to reliably access state keys from the previous agent
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
- OS: Darwin Matts-MacBook-Pro-2.local 23.6.0 Darwin Kernel Version 23.6.0: Thu Mar 6 22:01:15 PST 2025; root:xnu-10063.141.1.704.6~1/RELEASE_ARM64_T6000 arm64
- Python version(python -V): Python 3.13.3
- ADK version(pip show google-adk): 1.1.1
Additional context
Like I said, a timing issue... so intermittent. Seems like the second agent is starting before the first has finished saving state or something.
Activity
xuanyang15 commentedon Jul 7, 2025
Hi @hammertoe,
Thanks for reporting this issue! I took a look at your code at https://github.com/hammertoe/GraphCycle/blob/main/graphcycle/agent.py and noticed something you might want to consider changing:
store_knowledge_graphtool and theoutput_key?My recommendation is to update the code to use only the tool to store the graph:
output_key="knowledge_graph1"For example:
Could you please try the updated code and see if it fixed the issue?
hammertoe commentedon Jul 7, 2025
I shouldn't need the tool. According to the docs the output key should be sufficient. Either way the next stage is not able to reliably load the state and fails.
xuanyang15 commentedon Jul 7, 2025
Thanks for the quick response! Do you mind trying the tool instead of the output key? I want to confirm if the issue is output key only or both.
hammertoe commentedon Jul 7, 2025
I have tried both. First I just used the output key, then I added the tool, then I put in both. But regardless it is the next agent in the pipeline that cannot load from the state reliably. Sometimes it works, sometimes it doesn't.
xuanyang15 commentedon Jul 8, 2025
Thanks a lot for the information! I will try to reproduce this issue and debug from there.
seanzhou1023 commentedon Jul 8, 2025
when you same somtime it works and sometime it doesn't. do you have the logs for both case ? Mainly I want to see whether the model generate the correct function call for loading the state.
One thing I don't understand is that given your output key is fixed, why did you make it an argument of the load_knowledge_graph tool ? could you try hard code the key in the load tool ? ( that can verify whether it's related to model responding a correct function call )
xuanyang15 commentedon Jul 9, 2025
Hi @hammertoe, I tried running your code at https://github.com/hammertoe/GraphCycle/blob/main/graphcycle/agent.py, and didn't hit the error. I ran about 20+ times.
I also noticed the following potential mistakes in the code for which you might want to consider change:
LOADER_PROMPT, which might not work. I doubt the LLM can store raw_text following the instruction.output_key="raw_text"in thefile_loader, its instruction is actually "Report the length of the text and the file path / url in the output.", which means what you end up storing in thestate['raw_text']is actually just the length of the text and file url, not the file content.graph_reviewer1andgraph_reviewer2do not haveoutput_keyset, which means their conclusion ("pass" or "fail") are never stored in the state.Here is a diff of change I made to your code to address the above issues:
Could you please try these fixes? If you still hit the error, could you please share the logs so that we can locate the root cause of the problem as mentioned in the above comment #1119 (comment)?
DeanChensj commentedon Jul 16, 2025
Hi @hammertoe , the fix by @iwknow was merged in, could you try again?
jwiejulie commentedon Aug 14, 2025
Hi @hammertoe and thanks to everyone who participated in this thread.
We're currently doing some housekeeping on our issue tracker. Given the rapid pace of development and the number of updates since this was last active, there's a good chance this issue has been resolved in a newer version. To help us keep our backlog focused on current issues, we are closing this as stale.
If you're still facing this problem, could you please update to the very latest version of the library and confirm the issue still exists? If it does, please comment here, and we will be happy to reopen this issue and investigate further.
Thanks for your contribution and understanding!