-
Notifications
You must be signed in to change notification settings - Fork 878
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
feat(1/n): api: unify agents for handling server & client tools #1178
Merged
Conversation
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
yanxi0830
commented
Feb 20, 2025
new_messages: List[ | ||
Union[ | ||
UserMessage, | ||
ToolResponseMessage, |
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.
remove UserMessage
ehhuang
approved these changes
Feb 21, 2025
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.
LGTM
hardikjshah
approved these changes
Feb 21, 2025
yanxi0830
added a commit
that referenced
this pull request
Feb 21, 2025
# What does this PR do? - #1178 - #1187 - #1194 **client changes** - meta-llama/llama-stack-client-python#157 - meta-llama/llama-stack-client-python#158 ## Test Plan ``` LLAMA_STACK_BASE_URL=http://localhost:8321 pytest -v tests/client-sdk/agents/test_agents.py --inference-model meta-llama/Llama-3.1-8B-Instruct ``` ``` LLAMA_STACK_CONFIG=fireworks pytest -v tests/client-sdk/agents/test_agents.py --inference-model meta-llama/Llama-3.1-8B-Instruct ``` <img width="1080" alt="image" src="https://github.com/user-attachments/assets/6c48e062-5d00-4fed-98de-ecca627e5195" /> **llama-stack-apps** ``` python -m examples.agents.react_agent localhost 8321 ``` - Test with script: https://gist.github.com/yanxi0830/f2e407527f468998a700cd29fd271b15 **Output Before**: we have 2 `turn_id` with 2 turns - https://gist.github.com/yanxi0830/9fbd7a80fcddc784a28c59d4a9c1d943 **Output After**: we have 1 `turn_id`, the final turn have all 3 steps - https://gist.github.com/yanxi0830/17754d56d08ccbeaec419b693137500c <img width="622" alt="image" src="https://github.com/user-attachments/assets/ed7f42ca-41c8-4ee9-b6fa-2299901cafb4" /> **Telemetry** <img width="1389" alt="image" src="https://github.com/user-attachments/assets/031bf6ab-959c-46a7-aa85-70a511cba296" /> [//]: # (## Documentation)
# What does this PR do? - 1/n: #1178 This is a backward compat change. Default `allow_resume_turn=False` to work with client v0.1.3. **Expected Behaviour** 1. User sends out `agent.create_turn`. When user receives a custom client_tool_call. The last chunk should be ```python chunk = AgentTurnResponseStreamChunk( event=AgentTurnResponseEvent( payload=AgentTurnResponseTurnAwaitingInputPayload( turn=turn, ) ) ) ``` There should be a `tool_execution` step. 2. When user sees turn_pending as the event_type or if there's tool call in the response. They will execute the client tools, and submits back the tool response. E.g. ```python client.continue_turn( [ToolResponseMessage(...)] ) ``` The agent will then send back & record `tool_execution` step finish on server. and continue with the execution. [//]: # (If resolving an issue, uncomment and update the line below) [//]: # (Closes #[issue-number]) > NOTE: This PR handles (1). Next PR handle (2). ## Test Plan - Testing w/ Client SDK 0.1.3 ``` LLAMA_STACK_BASE_URL=http://localhost:8321 pytest -v tests/client-sdk/agents/test_agents.py --inference-model meta-llama/Llama-3.1-8B-Instruct ``` <img width="1075" alt="image" src="https://github.com/user-attachments/assets/c94e9cc6-a326-405c-a2ef-925dbc3ae58e" /> [//]: # (## Documentation)
yanxi0830
added a commit
to meta-llama/llama-stack-client-python
that referenced
this pull request
Feb 21, 2025
…anxi0830/dev) (#157) # What does this PR do? - Adapt to meta-llama/llama-stack#1178 ## Test Plan - test in following PR [//]: # (## Documentation) [//]: # (- [ ] Added a Changelog entry if the change is significant)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
Our current Agent framework has discrepancies in definition on how we handle server side and client side tools.
ToolExecutionStep
in agenstcreate_agent_turn
is called in loop with client agent lib yielding the agent chunkhttps://github.com/meta-llama/llama-stack-client-python/blob/ad6ffc63df658674f275267b1befc2b7046dbf33/src/llama_stack_client/lib/agents/agent.py#L186-L211
This makes it inconsistent to work with server & client tools. It also complicates the logs to telemetry to get information about agents turn / history for observability.
Principle
The same
turn_id
should be used to represent the steps required to complete a user message including client tools.Solution
AgentTurnResponseEventType.turn_awaiting_input
status to indicate that the current turn is not completed, and awaiting tool inputcontinue_agent_turn
endpoint to update agent turn with client's tool response.What does this PR do?
Test Plan
[Describe the tests you ran to verify your changes with result summaries. Provide clear instructions so the plan can be easily re-executed.]