Your multi-agent framework has several issues affecting agent iteration control and error handling. Here’s a lined explanation and practical suggestions for each problem:
Agents not stopping at one iteration
Agents consistently reaching the max iteration count (and then the END node) is usually a logic or termination-condition problem in the agent loop—either in your Supervisor logic or in the agent-node response handling. You should check:
-
The stopping condition after each agent step (i.e., are you checking for a response/event that signals completion, or only waiting for max iterations?)
-
Whether your agents return a message or status that is supposed to end the iteration. If not, agents will loop until forced to stop.
Suggestion:
Add a proper check after each iteration for a completion signal (“done”, “end”, or a special token/message), and exit early from the loop if found. Ensure that your agent nodes update their state correctly to flag completion.
Coder agent validation error
Error:
validation error for ChatAgentMessage Value error, Either 'content' or 'tool_calls' must be provided.
This error means you’re creating a message dictionary for the agent, but it’s missing both the 'content' and 'tool_calls' fields—which are both required. Most frameworks (like LangChain, UC, or custom ones) check for at least one to exist per message object.
Cause:
Your agent isn’t returning a valid message; either its output is empty, not returning a dict with these keys, or you aren’t formatting the output properly before building the agent message.
Suggestion:
Make sure the Coder agent always returns something like:
{
"role": "assistant",
"content": response_content, # This should be a string
"tool_calls": tool_calls # Or None if not using tools
}
At least one of content or tool_calls must be not None . If you’re not using tools, ensure content is a non-empty string.
Weather agent error and fix
Previous error:
'PyFuncModel' object has no attribute 'invoke'
You tried to fix this by writing:
def agent_node_existing_model(state, agent, name):
result = agent.predict(state)
return {
"messages": [
{
"role": "assistant",
"content": result["messages"][-1].content,
"name": name,
}
]
}
Current error:
AttributeError: 'list' object has no attribute 'get'
Cause:
This comes from the format of result. You are calling result["messages"][-1].content, expecting result to be a dict with a "messages" key containing a list of message objects.
But result from agent.predict(state) is apparently a list, not a dict, or its structure is different.
Suggestion:
Print or inspect the exact format of result returned by agent.predict(state). Is it a dict? Or is it a list of dicts? Adjust your code accordingly:
If result is a list of messages:
result = agent.predict(state)
last_message = result[-1] # If result is a list
return {
"messages": [
{
"role": "assistant",
"content": last_message.get("content", ""),
"name": name,
}
]
}
If result is a dict:
last_message = result["messages"][-1]
return {
"messages": [
{
"role": "assistant",
"content": last_message.get("content", ""),
"name": name,
}
]
}
Add checks and debug with print(result) to confirm its structure.
Key Code Patterns for Debugging
-
Always print or inspect agent outputs before trying to access nested keys.
-
Make sure message dicts always have valid fields (role, content, and optionally name or tool_calls).
-
Ensure the loop termination in your Supervisor is tied to agent-completion logic.