-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Unable to use the input function with run_stream #5041
Labels
Milestone
Comments
I too face the same issue. AutoGen version Which package was this bug in Model used Python version Operating system |
Adding the complete script here for debugging, removing the code that catches exceptions: import asyncio
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.conditions import HandoffTermination, TextMentionTermination
from autogen_agentchat.messages import HandoffMessage
from autogen_agentchat.teams import Swarm
from autogen_agentchat.ui import Console
from autogen_ext.models.openai import OpenAIChatCompletionClient
def refund_flight(flight_id: str) -> str:
"""Simulate refunding a flight."""
return f"Flight {flight_id} refunded successfully"
def check_flight_status(flight_id: str) -> str:
"""Simulate checking flight status."""
return f"Flight {flight_id} is scheduled and on time"
def create_model_client(model: str = "gpt-4o") -> OpenAIChatCompletionClient:
"""Create a model client with the specified model."""
return OpenAIChatCompletionClient(model=model)
def create_travel_agent(model_client: OpenAIChatCompletionClient) -> AssistantAgent:
"""Create the travel agent that handles general inquiries."""
return AssistantAgent(
"travel_agent",
model_client=model_client,
handoffs=["refund_agent", "user"],
system_message="""You are a travel agent.
The refund_agent is in charge of processing flight refunds.
If you need information from the user, first send your message, then handoff to the user.
Use TERMINATE when the travel planning is complete.""",
)
def create_refund_agent(model_client: OpenAIChatCompletionClient) -> AssistantAgent:
"""Create the refund agent that handles refund processing."""
return AssistantAgent(
"refund_agent",
model_client=model_client,
handoffs=["travel_agent", "user"],
tools=[refund_flight, check_flight_status],
system_message="""You are an agent specialized in refunding flights.
You need flight reference numbers to refund a flight.
You can refund flights using the refund_flight tool.
You can check flight status using the check_flight_status tool.
If you need information from the user, first send your message, then handoff to the user.
When the transaction is complete, handoff to the travel agent to finalize.""",
)
async def run_customer_support(task: str, model: str = "gpt-4o") -> None:
"""Run the customer support swarm with the given task."""
# Create model client
model_client = create_model_client(model)
# Create agents
travel_agent = create_travel_agent(model_client)
refund_agent = create_refund_agent(model_client)
# Create team
termination = HandoffTermination(target="user") | TextMentionTermination("TERMINATE")
team = Swarm(participants=[travel_agent, refund_agent], termination_condition=termination)
print("\nStarting customer support chat. Type 'exit' to quit or Ctrl+C to interrupt.\n")
# Run initial task
task_result = await Console(team.run_stream(task=task))
last_message = task_result.messages[-1]
# Handle user interactions
while isinstance(last_message, HandoffMessage) and last_message.target == "user":
print("\nUser (type 'exit' to quit): ")
print("Waiting for user input...") # Debug print
user_message = input("User: ")
if not user_message or user_message.lower() == "exit":
print("\nChat ended by user.")
break
task_result = await Console(
team.run_stream(task=HandoffMessage(source="user", target=last_message.source, content=user_message))
)
last_message = task_result.messages[-1]
def run_customer_support_sync(task: str, model: str = "gpt-4o") -> None:
"""Synchronous wrapper for run_customer_support."""
asyncio.run(run_customer_support(task=task, model=model))
task = "I need to refund my flight"
asyncio.run(run_customer_support(task))
|
Use import aioconsole
user_message = await aioconsole.ainput("User: ")
# user_message = input("User: ") |
@jackgerrits we need to update all usage of |
ekzhu
added
proj-agentchat
documentation
Improvements or additions to documentation
labels
Jan 14, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What happened?
The input() function does not work with
run_stream
. Theinput()
function returns immediately without waiting.Run: test-autogen/src/e4/swarm.py#L32-L68
Ouput
What did you expect to happen?
I can use the
input()
function as in the example from the documentation https://microsoft.github.io/autogen/stable/user-guide/agentchat-user-guide/swarm.htmlSee my similar test code here: test-autogen/src/e4/swarm.py#L32-L68
How can we reproduce it (as minimally and precisely as possible)?
You will find all the code to reproduce the problem in the repository test-autogen.
AutoGen version
0.4.1
Which package was this bug in
Core
Model used
gpt4-o
Python version
3.12
Operating system
Ubuntu 20.04.1
Any additional info you think would be helpful for fixing this bug
No response
The text was updated successfully, but these errors were encountered: