AssistantAgent.metadata for user/application identity information associated with the agent. #6048 (#6057)

This PR introduces a metadata field in AssistantAgentConfig, allowing
applications to assign and track identity information for agents.
The metadata field is a Dict[str, str] and is included in the
configuration for proper serialization.


---------

Co-authored-by: Eric Zhu <ekzhu@users.noreply.github.com>
This commit is contained in:
tongyu
2025-03-24 05:49:57 +08:00
committed by GitHub
parent fc2c9978fd
commit 47ffaccba1
3 changed files with 8 additions and 2 deletions

View File

@@ -73,6 +73,7 @@ class AssistantAgentConfig(BaseModel):
model_client_stream: bool = False
reflect_on_tool_use: bool
tool_call_summary_format: str
metadata: Dict[str, str] | None = None
class AssistantAgent(BaseChatAgent, Component[AssistantAgentConfig]):
@@ -169,6 +170,7 @@ class AssistantAgent(BaseChatAgent, Component[AssistantAgentConfig]):
Available variables: `{tool_name}`, `{arguments}`, `{result}`.
For example, `"{tool_name}: {result}"` will create a summary like `"tool_name: result"`.
memory (Sequence[Memory] | None, optional): The memory store to use for the agent. Defaults to `None`.
metadata (Dict[str, str] | None, optional): Optional metadata for tracking.
Raises:
ValueError: If tool names are not unique.
@@ -613,8 +615,10 @@ class AssistantAgent(BaseChatAgent, Component[AssistantAgentConfig]):
reflect_on_tool_use: bool = False,
tool_call_summary_format: str = "{result}",
memory: Sequence[Memory] | None = None,
metadata: Dict[str, str] | None = None,
):
super().__init__(name=name, description=description)
self._metadata = metadata or {}
if reflect_on_tool_use and ModelFamily.is_claude(model_client.model_info["family"]):
warnings.warn(
"Claude models may not work with reflection on tool use because Claude requires that any requests including a previous tool use or tool result must include the original tools definition."
@@ -1214,6 +1218,7 @@ class AssistantAgent(BaseChatAgent, Component[AssistantAgentConfig]):
model_client_stream=self._model_client_stream,
reflect_on_tool_use=self._reflect_on_tool_use,
tool_call_summary_format=self._tool_call_summary_format,
metadata=self._metadata,
)
@classmethod
@@ -1231,4 +1236,5 @@ class AssistantAgent(BaseChatAgent, Component[AssistantAgentConfig]):
model_client_stream=config.model_client_stream,
reflect_on_tool_use=config.reflect_on_tool_use,
tool_call_summary_format=config.tool_call_summary_format,
metadata=config.metadata,
)