From 47ffaccba13d468d397446a2c2f0b4702a38835e Mon Sep 17 00:00:00 2001 From: tongyu <119610311+tongyu0924@users.noreply.github.com> Date: Mon, 24 Mar 2025 05:49:57 +0800 Subject: [PATCH] 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 --- docs/dotnet/core/toc.yml | 2 +- docs/dotnet/docfx.json | 2 +- .../src/autogen_agentchat/agents/_assistant_agent.py | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/dotnet/core/toc.yml b/docs/dotnet/core/toc.yml index cc0156551b..1f0cc20a6c 100644 --- a/docs/dotnet/core/toc.yml +++ b/docs/dotnet/core/toc.yml @@ -7,4 +7,4 @@ - name: Differences from Python href: differences-from-python.md - name: Protobuf message types - href: protobuf-message-types.md \ No newline at end of file + href: protobuf-message-types.md diff --git a/docs/dotnet/docfx.json b/docs/dotnet/docfx.json index f43779dd3e..cb44b5c6b9 100644 --- a/docs/dotnet/docfx.json +++ b/docs/dotnet/docfx.json @@ -73,4 +73,4 @@ "keepFileLink": false, "disableGitFeatures": false } -} \ No newline at end of file +} diff --git a/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_assistant_agent.py b/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_assistant_agent.py index 4d001c0abd..92d2ccaa45 100644 --- a/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_assistant_agent.py +++ b/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_assistant_agent.py @@ -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, )