cancel
Showing results for 
Search instead for 
Did you mean: 
Generative AI
Explore discussions on generative artificial intelligence techniques and applications within the Databricks Community. Share ideas, challenges, and breakthroughs in this cutting-edge field.
cancel
Showing results for 
Search instead for 
Did you mean: 

Issue with Multi agent supervisor based agentic framework

SandipCoder
New Contributor II

I  have three agents in my multi agent framework (code attached)

 
Supervisor : This is the main controller
    "Genie":           #this is a genai agent
    "Coder":          #this is a re-act agent created on the fly
    "Weather":      #this is an existing model in UC based on single agent
 
The problem I am facing is :
 
1. For my agent they are not stopping after one iteration they are always reaching to max iteration count and then they find the END node.
 
2. For coder agent I am getting an error like : 
validation error for ChatAgentMessage Value error, Either 'content' or 'tool_calls' must be provided. [type=value_error, input_value={'role': 'assistant', 'co...4f5d-b5b9-248fc6785f9b'}, input_type=dict]
 
3. For Weather agent also I was getting error :
         'PyFuncModel' object has no attribute 'invoke' .
So I added the below function for existing model and called that while creating node for weather .But since then started getting another error :  AttributeError: 'list' object has no attribute 'get'
def agent_node_existing_model(state, agent, name😞
    result = agent.predict(state)
    return {
        "messages": [
            {
                "role": "assistant",
                "content": result["messages"][-1].content,
                "name": name,
            }
        ]
    }
 
weather_node = functools.partial(agent_node_existing_model, agent=weather_agent, name="Weather")
Sandip Bhowmick
1 REPLY 1

mark_ott
Databricks Employee
Databricks Employee

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:

python
{ "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:

python
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:

python
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:

python
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.

Join Us as a Local Community Builder!

Passionate about hosting events and connecting people? Help us grow a vibrant local community—sign up today to get started!

Sign Up Now