-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Open
Description
Required prerequisites
- I have searched the Issue Tracker and Discussions that this hasn't already been reported. (+1 or comment there if it has.)
- Consider asking first in a Discussion.
Motivation
when using ChatAgent in streaming mode with both response_format (structured output) and tools enabled, the agent
fails to return proper tool calls and structured content. The same configuration works correctly in non-streaming mode.
code to reproduce:
from pydantic import BaseModel, Field
from camel.agents import ChatAgent
from camel.models import ModelFactory
from camel.toolkits import MathToolkit
from camel.types import ModelPlatformType, ModelType
class Result(BaseModel):
sum_result: str = Field(description="Result of the addition")
product_result: str = Field(description="Result of the multiplication")
division_result: str = Field(description="Result of the division")
capital_result: str = Field(description="Result of the capital search")
streaming_model = ModelFactory.create(
model_platform=ModelPlatformType.DEFAULT,
model_type=ModelType.DEFAULT,
model_config_dict={
"stream": True,
"stream_options": {"include_usage": True},
},
)
agent = ChatAgent(
system_message="You are a helpful assistant. ",
model=streaming_model,
tools=MathToolkit().get_tools(),
stream_accumulate=False, # Delta mode
)
streaming_response = agent.step(
"Calculate: 1) 123.45 + 678.90 2) 100 * 3.14159 3) 1000 / 7, "
"also search what is the capital of Germany",
response_format=Result,
)
# Collect content from streaming chunks
content_parts = []
for chunk in streaming_response:
if chunk.msgs[0].content:
content_parts.append(chunk.msgs[0].content)
# Verify we got some structured response
full_content = "".join(content_parts)
print(full_content)
Suggested Fix:
- Preserve
used_prompt_formattingandoriginal_response_formatin _stream method - Apply
_apply_prompt_based_parsingafter stream completion whenused_prompt_formattingis True - Review
_stream_responseand_process_stream_chunks_with_accumulatorto ensure proper handling of tool calls followed
by structured output generation
also need to validate other model platforms including gemini, anthropic etc..
Solution
No response
Alternatives
No response
Additional context
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P0Task with high level priorityTask with high level priority
Type
Projects
Status
No status