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

feat: tool outputs metadata #1155

Merged
merged 1 commit into from
Feb 21, 2025
Merged

feat: tool outputs metadata #1155

merged 1 commit into from
Feb 21, 2025

Conversation

ehhuang
Copy link
Contributor

@ehhuang ehhuang commented Feb 19, 2025

Summary:

Allows tools to output metadata. This is useful for evaluating tool outputs, e.g. RAG tool will output document IDs, which can be used to score recall.

Will need to make a similar change on the client side to support ClientTool outputting metadata.

Test Plan:

LLAMA_STACK_CONFIG=fireworks pytest -s -v tests/client-sdk/agents/test_agents.py

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Meta Open Source bot. label Feb 19, 2025
@ehhuang ehhuang changed the title tool output metadata feat: tool outputs metadata Feb 19, 2025
@ehhuang ehhuang force-pushed the pr1153 branch 5 times, most recently from 593efac to 7beaf65 Compare February 19, 2025 19:30
@ehhuang ehhuang marked this pull request as ready for review February 19, 2025 19:30
@ehhuang ehhuang added this to the v0.1.4 milestone Feb 19, 2025
@@ -916,12 +925,12 @@ async def execute_tool_call_maybe(
messages: List[CompletionMessage],
toolgroup_args: Dict[str, Dict[str, Any]],
tool_to_group: Dict[str, str],
) -> List[ToolResponseMessage]:
) -> Tuple[ToolCall, ToolInvocationResult]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not related to the PR and up for discussion:

but since we now have both client side agent loop (https://github.com/meta-llama/llama-stack-client-python/blob/ad6ffc63df658674f275267b1befc2b7046dbf33/src/llama_stack_client/lib/agents/agent.py#L179-L198) + server side agent loop.

Perhaps we should unify the behaviour/interface for the agent loop.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea we'll need to make a similar change on the client side to support ClientTool outputting metadata. I've been putting off unifying since this is a relatively simple change.

@ehhuang ehhuang force-pushed the pr1153 branch 2 times, most recently from 6a28777 to fde4e86 Compare February 20, 2025 00:11
@ehhuang ehhuang requested a review from ashwinb February 20, 2025 00:12
@@ -165,6 +165,7 @@ class ToolResponse(BaseModel):
call_id: str
tool_name: Union[BuiltinTool, str]
content: InterleavedContent
metadata: Optional[Dict[str, Any]] = None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also add metadata to ToolResponseMessage. This is s.t. we can continue the turn with new_messages (e.g. https://github.com/meta-llama/llama-stack/pull/1178/files)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

metadata is meant as auxiliary data for the user, so I don't think we need to pass it along to continue the conversation?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need consistent metadata whether the tool is executed server side or client side. So, it will be good to include it in ToolResponseMessage.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@raghotham I don't think this is related to server/client side. ToolMessage is only used in the output, i.e. ToolExecutionStep, where adding the metadata makes sense as it is extra information about the execution, akin to log.info. ToolResponseMessage are inputs to inference, which doesn't make use of the added metadata.

Copy link
Contributor

@yanxi0830 yanxi0830 Feb 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/meta-llama/llama-stack-client-python/blob/c6457261bdfaef9466017d52e4764be930bce40e/src/llama_stack_client/lib/agents/client_tool.py#L63-L85

My understanding is that the ClientTool will output a ToolResponseMessage. This ToolResponseMessage can be sent back to resume the Turn.

Having metadata in ToolResponseMessage is useful for:
(1) Support ClientTool outputting metadata
(1) Easy to allow metadata info to be tracked/logged on server when we resume_turn by passing back the ToolResponseMessage.

Copy link
Contributor Author

@ehhuang ehhuang Feb 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! Yea I was thinking that we should change ClientTool to output ToolInvocationResult instead, same as tool_call on the server side (this PR's change). Then we don't need metadata in ToolResponseMessage.

This PR doesn't support ClientTool metadata anyway (which will be made easier to support with your resume change). We can punt on this until the PR to support ClientTool ouputting metadata?

Summary:

Allows tools to output metadata. This is useful for evaluating tool outputs, e.g. RAG tool will output document IDs, which can be used to score recall.

Will need to make a similar change on the client side to support ClientTool outputting metadata.

Test Plan:

LLAMA_STACK_CONFIG=fireworks pytest -s -v tests/client-sdk/agents/test_agents.py
@ehhuang ehhuang merged commit 25fddcc into main Feb 21, 2025
5 checks passed
@ehhuang ehhuang deleted the pr1153 branch February 21, 2025 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Meta Open Source bot.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants