Skip to content
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

Turn-based Conversation with Agents #193

Open
PaulSGit1 opened this issue Mar 17, 2025 · 2 comments
Open

Turn-based Conversation with Agents #193

PaulSGit1 opened this issue Mar 17, 2025 · 2 comments
Labels
question Question about using the SDK

Comments

@PaulSGit1
Copy link

Please read this first

  • Have you read the docs? Yes
  • Have you searched for related issues? Yes

Question

Hi, I have the following question:
Let's say I have an usecase where I need to ask the user for several inputs turn-based.
So first question is his name, afterwards I ask him for his age.

How would I achieve this the best way possible with the SDK?
I need to incooperate such tasks with my existing agents which process these informations later down the line to make informed decisions.

Any help or point into a direction would be super helpful!

Thanks,
Paul

@PaulSGit1 PaulSGit1 added the question Question about using the SDK label Mar 17, 2025
@heartkilla
Copy link
Contributor

Take a look at the "customer service" example:

while True:
user_input = input("Enter your message: ")
with trace("Customer service", group_id=conversation_id):
input_items.append({"content": user_input, "role": "user"})
result = await Runner.run(current_agent, input_items, context=context)
for new_item in result.new_items:
agent_name = new_item.agent.name
if isinstance(new_item, MessageOutputItem):
print(f"{agent_name}: {ItemHelpers.text_message_output(new_item)}")
elif isinstance(new_item, HandoffOutputItem):
print(
f"Handed off from {new_item.source_agent.name} to {new_item.target_agent.name}"
)
elif isinstance(new_item, ToolCallItem):
print(f"{agent_name}: Calling a tool")
elif isinstance(new_item, ToolCallOutputItem):
print(f"{agent_name}: Tool call output: {new_item.output}")
else:
print(f"{agent_name}: Skipping item: {new_item.__class__.__name__}")
input_items = result.to_input_list()
current_agent = result.last_agent

@rm-openai
Copy link
Collaborator

If you want to ask a fixed list of questions, you can just build that directly (e.g. via a form or a Q&A type system).

If you have a non-fixed list of questions, or want to get an Agent to check the answers, you can check out the Customer Service example mentioned above! You can also prompt the agent e.g. by saying "Ask the user about their name, age, etc. Go back and forth until you have all the required information".

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

3 participants