-
Notifications
You must be signed in to change notification settings - Fork 1.4k
How can I pass dynamic instruction to the agent #482
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
Comments
Hi, there is a section in the documentation that explains how to use dynamic data in the prompt. |
@DanieleMorotti Hi! Thanks. How can I implement logic that will stop the |
I'm not entirely sure what you mean by "stop the main agent." When using handoffs, the main agent delegates the task to another agent, which then continues the conversation. Could you please provide more details if this doesn't address your question? |
okay, I have After handing off |
If you pass the import asyncio
import traceback
from agents import Agent, Runner, handoff
from agents.extensions import handoff_filters
from agents.extensions.handoff_prompt import prompt_with_handoff_instructions
from agents.model_settings import ModelSettings
from openai.types.responses import ResponseTextDeltaEvent
async def main():
input_items = []
# Agents
english_agent = Agent(
name="english interpreter",
model="gpt-4o-mini",
instructions="You are in charge of speaking with an english user.",
model_settings=ModelSettings(temperature=0.4, max_tokens=2048)
)
italian_agent = Agent(
name="italian interpreter",
model="gpt-4o-mini",
instructions="Tu sei incaricato di parlare con gli utenti italiani.",
model_settings=ModelSettings(temperature=0.4, max_tokens=2048),
)
mn_agent = Agent(
name="manager agent",
model="gpt-4o-mini",
instructions=prompt_with_handoff_instructions("Your task is to pass the control of the conversation to the english or italian agents based on the user's nationality. You can't directly respond to the user."),
model_settings=ModelSettings(temperature=0.3, max_tokens=2048),
handoffs=[
handoff(english_agent, input_filter=handoff_filters.remove_all_tools),
handoff(italian_agent, input_filter=handoff_filters.remove_all_tools)
]
)
current_agent = mn_agent
while True:
user_input = input("> User: ")
if user_input == "quit":
print("\n> Stopping Agent ...")
break
input_items.append({"content": user_input, "role": "user"})
result = Runner.run_streamed(
current_agent,
input=input_items
#run_config=RunConfig(tracing_disabled=True)
)
print(f"> Agent: ")
async for event in result.stream_events():
if event.type == "raw_response_event" and isinstance(event.data, ResponseTextDeltaEvent):
print(event.data.delta, end="", flush=True)
print("\n")
input_items = result.to_input_list()
current_agent = result.last_agent
if __name__ == "__main__":
try:
asyncio.run(main())
except Exception as exc:
print(f"Error while agent execution: {traceback.format_exc()}") In this example, when control is transferred to one of the two agents, that agent leads the conversation. If you need the capability to hand off from secondary agents to the main one, you should include the main agent as an handoff option for the other two. Hope this is helpful. |
|
It removes all tool calls from the history. You can also remove the input filter if you want, it's optional |
This issue is stale because it has been open for 7 days with no activity. |
This issue was closed because it has been inactive for 3 days since being marked as stale. |
I want to implement a handoff agent, but in this agent I have dynamic data in the system prompt.
i was thinking to do smth like that
To pass handoff agent to a main agent, I need the following

Can anyone help me with this?
The text was updated successfully, but these errors were encountered: