Build and run agents you can see, understand and trust.
Python agentchatbotlarge-language-modelsllmllm-agentmcpmulti-agentmulti-modalreact-agentrealtime-agentvoice-agentvoice-assistant
fix(agent): set `tool_choice` to "required" when requring structured output (#928)
qbcf4c6b6f0c7f5
diff --git a/src/agentscope/agent/_react_agent.py b/src/agentscope/agent/_react_agent.pyindex 2e43c7f40..8ddc0e162 100644--- a/src/agentscope/agent/_react_agent.py+++ b/src/agentscope/agent/_react_agent.py@@ -262,6 +262,9 @@ class ReActAgent(ReActAgentBase):# Retrieve relevant documents from the knowledge base(s) if anyawait self._retrieve_from_knowledge(msg)+ # Control if LLM generates tool calls in each reasoning step+ tool_choice: Literal["auto", "none", "any", "required"] | None = None+# -------------- Structured output management --------------self._required_structured_model = structured_model# Record structured output model if provided@@ -278,13 +281,12 @@ class ReActAgent(ReActAgentBase):self.finish_function_name,structured_model,)+ tool_choice = "required"else:# Remove generate_response tool if no structured output is requiredself.toolkit.remove_tool_function(self.finish_function_name)# -------------- The reasoning-acting loop --------------- # Control if LLM generates tool calls in each reasoning step- tool_choice = None# Cache the structured output generated in the finish function callstructured_output = Nonefor _ in range(self.max_iters):