[Bug] AgentTool default schema overrides state-mapped conversation with a model-generated one-message task
Describe the bug The purchasing specialist says it has no prior conversation even though I map the genuine earlier conversation into its messages input.
I record a supplier and invoice total in one real conversation turn. On the next turn I ask the parent Agent to send a short question to a specialist; the actual previous conversation is supplied automatically using inputs_from_state.
Error message Error that was thrown (if available)
Specialist input: Which supplier and invoice total did I select?
Use the prior conversation to answer this question: Which supplier and invoice total did I select?
Child answer: I don’t have the prior conversation content available in this chat ...
assert any('Acme' in (message.text or '') and '169' in message.text for message in child['messages'][:-1]), 'The automatically supplied conversation did not reach the specialist'
AssertionError: The automatically supplied conversation did not reach the specialist
Expected behavior The specialist receives Acme and 169 USD from the previous conversation and answers the question.
Additional context Add any other context about the problem here, like document types / preprocessing steps / settings of reader etc.
To Reproduce Steps to reproduce the behavior
import os
from haystack.components.agents import Agent
from haystack.components.generators.chat import OpenAIChatGenerator
from haystack.dataclasses import ChatMessage
from haystack.tools import AgentTool
from haystack.utils import Secret
for key in ('HTTP_PROXY','HTTPS_PROXY','ALL_PROXY','http_proxy','https_proxy','all_proxy'):
os.environ.pop(key, None)
model = OpenAIChatGenerator(api_key=Secret.from_env_var('DEEPSEEK_API_KEY'), api_base_url='https://api.deepseek.com/v1', model='deepseek-flash', generation_kwargs={'temperature':0,'extra_body':{'thinking':{'type':'disabled'}}})
specialist = Agent(chat_generator=model, user_prompt='Use the prior conversation to answer this question: {{ question }}', required_variables=['question'])
review = AgentTool(agent=specialist, name='review_order', description='Ask the purchasing specialist a question. Prior conversation is supplied automatically; pass only the current question, without copying earlier facts.', inputs_from_state={'conversation':'messages'}, outputs_to_state={'review':{}})
agent = Agent(chat_generator=model, tools=[review], system_prompt='Help with purchasing. Delegate to the specialist only when the user explicitly asks.', state_schema={'conversation':{'type':list[ChatMessage]}, 'review':{'type':dict}}, max_agent_steps=4)
first = agent.run(messages=[ChatMessage.from_user('Remember that our selected supplier is Acme and our invoice total is 169 USD. Reply only OK.')])
print('First turn:', first)
second = agent.run(messages=first['messages']+[ChatMessage.from_user('Ask the purchasing specialist which supplier and invoice total I selected. Send only this question; the prior conversation is provided automatically.')], conversation=first['messages'])
print('Second turn:', second)
child = second['review']
print('Specialist input:', child['messages'][:-1])
assert first['exit_reason'] == second['exit_reason'] == child['exit_reason'] == 'text'
assert second['tool_call_counts'].get('review_order', 0) == 1
assert any('Acme' in (message.text or '') and '169' in message.text for message in child['messages'][:-1]), 'The automatically supplied conversation did not reach the specialist'
FAQ Check
- [x] Have you had a look at our new FAQ page?
System:
- OS:Linux 5.15.0-139-generic, x86_64, glibc 2.31.
- Haystack version:3.5.0
👋 Hello there! This issue will be handled internally and isn't open for external contributions. If you'd like to contribute, please take a look at issues labeled contributions welcome or good first issue. We'd really appreciate it!
Thanks for the detailed repro! You're right that the default schema still asks the LLM for messages even when it's mapped through inputs_from_state, so the state value never gets used.
Before we change it, could you share the use case that led you here? If the specialist needs the full prior conversation, giving its tools to the main Agent seems simpler than a sub-agent.
Thanks for the detailed repro! You're right that the default schema still asks the LLM for
messageseven when it's mapped throughinputs_from_state, so the state value never gets used.Before we change it, could you share the use case that led you here? If the specialist needs the full prior conversation, giving its tools to the main Agent seems simpler than a sub-agent.
Thanks a lot! Our use case looks roughly like this:
user --> [parent: cloud model] --question--> [specialist: local fine-tuned
^ model + own tool] --> internal records
| | (stay local)
+---------------- answer ----------------+
prior conversation --> [specialist].messages via inputs_from_state
We built this agent-as-tool around a fine-tuned open-source model so it can use a business-specific tool properly, which isn't something we'd want the parent model to drive directly. The specialist's prompt is also much more detailed than the repro — few-shot examples plus tool-specific instructions. Dropping the specialist and handing the tool to the parent would lose that modularity, make the parent considerably more complex