Why the ChatAgent drop the original response message content of model and replace it with FunctionCallingMessage with an empty content #3010
Unanswered
farmer00317558
asked this question in
Q&A
Replies: 1 comment
-
|
This is a common issue with function calling message handling. Here's what's happening and how to work around it: The Problem# Model returns:
{
"role": "assistant",
"content": "Let me search for that...", # Original content
"tool_calls": [{"function": {...}}]
}
# After processing, you get:
FunctionCallingMessage(
content="", # Empty!
func_name="search",
args={...}
)The original content is dropped because CAMEL treats tool calls as discrete operations. Why This HappensIn the function calling paradigm:
Workarounds1. Capture Pre-Call Contentclass ContentPreservingAgent(ChatAgent):
def step(self, input_message):
response = super().step(input_message)
# Access raw response before transformation
if hasattr(response, "_raw_response"):
original_content = response._raw_response.get("content", "")
if original_content:
response.metadata["original_content"] = original_content
return response2. Use Two-Phase Execution# Phase 1: Get reasoning
reasoning = agent.step("Think about: " + query)
# Phase 2: Execute with tools
action = agent.step("Now execute: " + query, allow_tools=True)
# Combine
full_response = {
"reasoning": reasoning.content,
"action": action.func_name,
"result": action.result
}3. Request Explicit Reasoningsystem_prompt = """
Before calling any tool, always:
1. State your reasoning in <thinking> tags
2. Then make the tool call
Example:
<thinking>User wants X, I'll use tool Y because...</thinking>
[tool call]
"""Recommended ApproachStore reasoning in external state rather than relying on message content: state = {
"reasoning_trace": [],
"actions": []
}
# Agent writes reasoning to state
state["reasoning_trace"].append(agent.last_reasoning)More on state-based patterns: https://github.com/KeepALifeUS/autonomous-agents |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
This is a snippet from the _record_tool_calling method. Why is the content property not set to the actual output of the current step model?
Beta Was this translation helpful? Give feedback.
All reactions