Description
Please read this first
- Have you read the docs?Agents SDK docs
- yes
- Have you searched for related issues? Others may have had similar requests
- yes
Question
Describe your question. Provide details if available.
So basically, suppose I have 4 agents, one triage and two child agents and one stranger agent. Usually the conversation will start from triage agent. But sometimes it can start from the stranger agent too, based on some backend logic.
Now my question is, triage agent doesn't have any context about the stranger agent. The stranger agent knows about the triage agent (through the handoff tool). But once a request is handed off, the stranger agent can't get the control back (since triage agent doesn't have handoff tool for stranger agent).
so TL;DR would be: Stranger can handoff to triage (only once). Triage can't handoff to stranger.
Now I want to implement a blocking logic here in this handoff from stranger to triage, which blocks the handoff if certain conditions are not matched (for more deterministic flow and to prevent handoff due to hallucinations).
One thing to note is, this stranger agent is completely independent and has all the tools required. When it performs it's tasks, it needs to handoff to the triage for continuing the conversation.
My use case is similar to the customer service example in the documentation but a little more complex.
I want something similar to on_handoff
parameter, but it should be able to control whether to allow the handoff to happen or not.
This would be preferred. But if not possible then, I have an idea:
Run the stranger agent as a completely separate agent and provide it a tool to end the conversation, add the logic to control whether ending the conversation is allowed or not here. If not allowed, the stranger agent will continue conversing else, I'll take the context / chat history and give it to the separate triage agent to continue the conversation from where the stranger left ?
Edit: On searching further I found: on_invoke_handoff
exists. Can I use this function in any way, what will happen if I return the stranger agent's name and append an additional message in the context instructing the agent what to do: "Tell the user this action is not allowed before you complete this" or something ?