[BUG] Tool schemas are duplicated into the conversation as an assistant turn
Summary
The full tool-schema list is written into the conversation as a message attributed to the agent itself. It duplicates information already sent through the API's tools parameter, and it makes the conversation open with an assistant turn that the assistant never said.
Location
swarms/structs/agent.py:978-981
self.short_memory.add(
role=self.agent_name,
content=self.tools_list_dictionary,
)Details
tools_list_dictionary is already passed to the provider as the tools parameter, which is the supported and cheaper channel — providers apply their own formatting and, for Anthropic, cache it as part of the stable prefix. Writing it into the conversation as well means:
- Duplicated tokens. The full JSON schema of every tool is sent twice per request, once as
toolsand once as conversation content. For an agent with a dozen tools this is a large, permanent overhead on every call. - Wrong attribution. It is stored under
role=self.agent_name, so anything mapping conversation roles onto chat roles reads it as anassistantturn. A conversation that opens with the assistant reciting its own tool schemas is not a shape any model was trained on. - It is not a stringly-typed value.
contentis alist, unlike every other entry, so it renders as a Python repr ([{'type': 'function', ...}]) inreturn_history_as_string().
Observed on a fresh agent with one tool:
role='System' '\nYou are an autonomous agent designed to serve users by auto...'
role='P' "[{'type': 'function', 'function': {'name': 'get_weather', 'd..."
role='Human' 'task'Proposed fix
Drop the short_memory.add(...) call — the tools parameter already carries this. If a record is wanted for debugging or transcripts, log it, or store it under a non-conversational role that prompt construction skips (as "System" already is).
Worth checking against #1977: with a structured transcript the tool list is genuinely redundant, since tool calls and results now appear in their proper form.
Source: kyegomez/swarms