Skip to content

How to make the conversation finally back to the MAIN AGENT #527

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

Open
shinianzhihou opened this issue Apr 16, 2025 · 7 comments
Open

How to make the conversation finally back to the MAIN AGENT #527

shinianzhihou opened this issue Apr 16, 2025 · 7 comments
Labels
question Question about using the SDK

Comments

@shinianzhihou
Copy link

Please read this first

  • Have you read the docs?Agents SDK docs
  • Have you searched for related issues? Others may have had similar requests

Yes

Question

Describe your question. Provide details if available.

My Agents is:

Image

When i input a TASK to main_agent, it divide the main task into several tasks and deliever them to different agents. But the conversation(also the stream) always stop in some agent.

I want the other agents finally back to main_agents. Any functions or docs can help me solve it?

THANKS MY BEST MULTI-AGENTS-FRAMEWORK

@shinianzhihou shinianzhihou added the question Question about using the SDK label Apr 16, 2025
@jackien1
Copy link

jackien1 commented Apr 16, 2025

I had the same issue since I wanted to reduce costs by having different agents use cheaper or specialized models. Using agents as tools with a supervisor agent could work but I don't think the agent tools have access to message history. You could try using a while loop with a supervisor agent that hands off to other agents every turn and passes message history. To break the loop, use a LLM judge or some external code.

https://github.com/openai/openai-agents-python/blob/main/examples/agent_patterns/llm_as_a_judge.py

@rm-openai
Copy link
Collaborator

Can you share some sample code? In general there are a couple of ways to force this:

  1. Prompting, telling the model to always pass back
  2. Requiring a specific handoff tool to be used via tool_choice in ModelSettings

@shinianzhihou
Copy link
Author

I had the same issue since I wanted to reduce costs by having different agents use cheaper or specialized models. Using agents as tools with a supervisor agent could work but I don't think the agent tools have access to message history. You could try using a while loop with a supervisor agent that hands off to other agents every turn and passes message history. To break the loop, use a LLM judge or some external code.

https://github.com/openai/openai-agents-python/blob/main/examples/agent_patterns/llm_as_a_judge.py

This helps me.
I use a judge to continue the loop conversation.

@dataclass
class EvaluationFeedback:
    feedback: str
    score: Literal["任务完成", "任务没有完成", "需要用户输入"]

@shinianzhihou
Copy link
Author

Can you share some sample code? In general there are a couple of ways to force this:

  1. Prompting, telling the model to always pass back
  2. Requiring a specific handoff tool to be used via tool_choice in ModelSettings

I have tried the first way and it sometimes works.

The second way seems more elegant and could u plz provide some example codes?

I had the same issue since I wanted to reduce costs by having different agents use cheaper or specialized models. Using agents as tools with a supervisor agent could work but I don't think the agent tools have access to message history. You could try using a while loop with a supervisor agent that hands off to other agents every turn and passes message history. To break the loop, use a LLM judge or some external code.
https://github.com/openai/openai-agents-python/blob/main/examples/agent_patterns/llm_as_a_judge.py

This helps me. I use a judge to continue the loop conversation.

@DataClass
class EvaluationFeedback:
feedback: str
score: Literal["任务完成", "任务没有完成", "需要用户输入"]

use a judge also works but i cannot connect the agent with other agents.

@goooodle
Copy link

I had the same issue

@koakuma-chan
Copy link

@rm-openai Is there a better way to write this?

from agents import Agent

sponge_bob_agent = Agent(
    name="sponge_bob_agent",
    instructions="You are Sponge Bob.",
    handoffs=[patrick_agent], # Error: Agent Patrick is undefined
)

patrick_agent = Agent(
    name="patrick_agent",
    instructions="You are Patrick.",
    handoffs=[sponge_bob_agent],
)
from agents import Agent

sponge_bob_agent = Agent(
    name="sponge_bob_agent",
    instructions="You are Sponge Bob.",
    handoffs=[],
)

patrick_agent = Agent(
    name="patrick_agent",
    instructions="You are Patrick.",
    handoffs=[sponge_bob_agent],
)

sponge_bob_agent.handoffs.append(patrick_agent) # Awkward

@RoniFinTech
Copy link

Is there a good solution?

  1. I tried with handoffs but I was facing an unreliable plan no matter how I changed the prompt of the supervisor agent instructions.
  2. I tried the tools, but was facing hallucinations at different stages especially when I needed information that was generated in one agent to be used in the next agent.

any thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question about using the SDK
Projects
None yet
Development

No branches or pull requests

6 participants