-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
triage agent tool choice requried + respond to user #339
Open
jhills20
wants to merge
2
commits into
main
Choose a base branch
from
tc_cs_exmpl
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,9 @@ | |
HandoffOutputItem, | ||
ItemHelpers, | ||
MessageOutputItem, | ||
ModelSettings, | ||
RunContextWrapper, | ||
RunConfig, | ||
Runner, | ||
ToolCallItem, | ||
ToolCallOutputItem, | ||
|
@@ -74,9 +76,13 @@ async def update_seat( | |
assert context.context.flight_number is not None, "Flight number is required" | ||
return f"Updated seat to {new_seat} for confirmation number {confirmation_number}" | ||
|
||
|
||
### HOOKS | ||
|
||
@function_tool | ||
async def respond_to_user(response: str) -> str: | ||
""" | ||
Use this function to send a message back to the end user. The agent should call this whenever | ||
you want to produce a user-facing response. | ||
""" | ||
return response | ||
|
||
async def on_seat_booking_handoff(context: RunContextWrapper[AirlineAgentContext]) -> None: | ||
flight_number = f"FLT-{random.randint(100, 999)}" | ||
|
@@ -95,7 +101,7 @@ async def on_seat_booking_handoff(context: RunContextWrapper[AirlineAgentContext | |
1. Identify the last question asked by the customer. | ||
2. Use the faq lookup tool to answer the question. Do not rely on your own knowledge. | ||
3. If you cannot answer the question, transfer back to the triage agent.""", | ||
tools=[faq_lookup_tool], | ||
tools=[faq_lookup_tool, respond_to_user], | ||
) | ||
|
||
seat_booking_agent = Agent[AirlineAgentContext]( | ||
|
@@ -109,7 +115,7 @@ async def on_seat_booking_handoff(context: RunContextWrapper[AirlineAgentContext | |
2. Ask the customer what their desired seat number is. | ||
3. Use the update seat tool to update the seat on the flight. | ||
If the customer asks a question that is not related to the routine, transfer back to the triage agent. """, | ||
tools=[update_seat], | ||
tools=[update_seat, respond_to_user], | ||
) | ||
|
||
triage_agent = Agent[AirlineAgentContext]( | ||
|
@@ -122,7 +128,12 @@ async def on_seat_booking_handoff(context: RunContextWrapper[AirlineAgentContext | |
handoffs=[ | ||
faq_agent, | ||
handoff(agent=seat_booking_agent, on_handoff=on_seat_booking_handoff), | ||
respond_to_user | ||
], | ||
tools=[respond_to_user], | ||
model_settings=ModelSettings(tool_choice="required"), | ||
tool_use_behavior={"stop_at_tool_names": ["respond_to_user"]}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need this any more after #335? |
||
|
||
) | ||
|
||
faq_agent.handoffs.append(triage_agent) | ||
|
@@ -145,8 +156,9 @@ async def main(): | |
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) | ||
result = await Runner.run(current_agent, input_items, context=context,run_config=RunConfig(tracing_disabled=True)) | ||
|
||
last_tool_name: str | None = None | ||
for new_item in result.new_items: | ||
agent_name = new_item.agent.name | ||
if isinstance(new_item, MessageOutputItem): | ||
|
@@ -156,9 +168,13 @@ async def main(): | |
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") | ||
last_tool_name = getattr(new_item.raw_item, "name", None) | ||
print(f"{agent_name} called tool:{f' {last_tool_name}' if last_tool_name else ''}") | ||
elif isinstance(new_item, ToolCallOutputItem): | ||
print(f"{agent_name}: Tool call output: {new_item.output}") | ||
if last_tool_name == "respond_to_user": | ||
print(f"{agent_name}: {new_item.output}") | ||
else: | ||
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() | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add links to these? Makes it more useful that way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes good call