diff --git a/lib/crewai/src/crewai/agents/crew_agent_executor.py b/lib/crewai/src/crewai/agents/crew_agent_executor.py index fdc3b5671..09bbd885d 100644 --- a/lib/crewai/src/crewai/agents/crew_agent_executor.py +++ b/lib/crewai/src/crewai/agents/crew_agent_executor.py @@ -517,7 +517,7 @@ class CrewAgentExecutor(CrewAgentExecutorMixin): isinstance(first_item, dict) and "function" in first_item ): return True - # Anthropic-style + # Anthropic-style (object with attributes) if ( hasattr(first_item, "type") and getattr(first_item, "type", None) == "tool_use" @@ -525,6 +525,13 @@ class CrewAgentExecutor(CrewAgentExecutorMixin): return True if hasattr(first_item, "name") and hasattr(first_item, "input"): return True + # Bedrock-style (dict with name and input keys) + if ( + isinstance(first_item, dict) + and "name" in first_item + and "input" in first_item + ): + return True # Gemini-style if hasattr(first_item, "function_call") and first_item.function_call: return True @@ -585,7 +592,12 @@ class CrewAgentExecutor(CrewAgentExecutorMixin): func_name = tool_call.name func_args = tool_call.input # Already a dict in Anthropic elif isinstance(tool_call, dict): - call_id = tool_call.get("id", f"call_{id(tool_call)}") + # Support OpenAI "id", Bedrock "toolUseId", or generate one + call_id = ( + tool_call.get("id") + or tool_call.get("toolUseId") + or f"call_{id(tool_call)}" + ) func_info = tool_call.get("function", {}) func_name = func_info.get("name", "") or tool_call.get("name", "") func_args = func_info.get("arguments", "{}") or tool_call.get("input", {}) diff --git a/lib/crewai/src/crewai/experimental/agent_executor.py b/lib/crewai/src/crewai/experimental/agent_executor.py index 3afd770d5..cef75897e 100644 --- a/lib/crewai/src/crewai/experimental/agent_executor.py +++ b/lib/crewai/src/crewai/experimental/agent_executor.py @@ -263,6 +263,13 @@ class AgentExecutor(Flow[AgentReActState], CrewAgentExecutorMixin): return True if hasattr(first_item, "name") and hasattr(first_item, "input"): return True + # Check for Bedrock-style tool call structure (dict with name and input keys) + if ( + isinstance(first_item, dict) + and "name" in first_item + and "input" in first_item + ): + return True # Check for Gemini-style function call (Part with function_call) if hasattr(first_item, "function_call") and first_item.function_call: return True diff --git a/lib/crewai/src/crewai/llms/providers/bedrock/completion.py b/lib/crewai/src/crewai/llms/providers/bedrock/completion.py index e982b2af6..c88d23ab8 100644 --- a/lib/crewai/src/crewai/llms/providers/bedrock/completion.py +++ b/lib/crewai/src/crewai/llms/providers/bedrock/completion.py @@ -330,7 +330,8 @@ class BedrockCompletion(BaseLLM): cast(object, [{"text": system_message}]), ) - # Add tool config if present + # Add tool config if present or if messages contain tool content + # Bedrock requires toolConfig when messages have toolUse/toolResult if tools: tool_config: ToolConfigurationTypeDef = { "tools": cast( @@ -339,6 +340,16 @@ class BedrockCompletion(BaseLLM): ) } body["toolConfig"] = tool_config + elif self._messages_contain_tool_content(formatted_messages): + # Create minimal toolConfig from tool history in messages + tools_from_history = self._extract_tools_from_message_history( + formatted_messages + ) + if tools_from_history: + body["toolConfig"] = cast( + "ToolConfigurationTypeDef", + cast(object, {"tools": tools_from_history}), + ) # Add optional advanced features if configured if self.guardrail_config: @@ -444,6 +455,8 @@ class BedrockCompletion(BaseLLM): cast(object, [{"text": system_message}]), ) + # Add tool config if present or if messages contain tool content + # Bedrock requires toolConfig when messages have toolUse/toolResult if tools: tool_config: ToolConfigurationTypeDef = { "tools": cast( @@ -452,6 +465,16 @@ class BedrockCompletion(BaseLLM): ) } body["toolConfig"] = tool_config + elif self._messages_contain_tool_content(formatted_messages): + # Create minimal toolConfig from tool history in messages + tools_from_history = self._extract_tools_from_message_history( + formatted_messages + ) + if tools_from_history: + body["toolConfig"] = cast( + "ToolConfigurationTypeDef", + cast(object, {"tools": tools_from_history}), + ) if self.guardrail_config: guardrail_config: GuardrailConfigurationTypeDef = cast( @@ -1290,6 +1313,8 @@ class BedrockCompletion(BaseLLM): for message in formatted_messages: role = message.get("role") content = message.get("content", "") + tool_calls = message.get("tool_calls") + tool_call_id = message.get("tool_call_id") if role == "system": # Extract system message - Converse API handles it separately @@ -1297,9 +1322,48 @@ class BedrockCompletion(BaseLLM): system_message += f"\n\n{content}" else: system_message = cast(str, content) + elif role == "assistant" and tool_calls: + # Convert OpenAI-style tool_calls to Bedrock toolUse format + bedrock_content = [] + for tc in tool_calls: + func = tc.get("function", {}) + tool_use_block = { + "toolUse": { + "toolUseId": tc.get("id", f"call_{id(tc)}"), + "name": func.get("name", ""), + "input": func.get("arguments", {}) + if isinstance(func.get("arguments"), dict) + else json.loads(func.get("arguments", "{}") or "{}"), + } + } + bedrock_content.append(tool_use_block) + converse_messages.append( + {"role": "assistant", "content": bedrock_content} + ) + elif role == "tool" and tool_call_id: + # Convert OpenAI-style tool response to Bedrock toolResult format + converse_messages.append( + { + "role": "user", + "content": [ + { + "toolResult": { + "toolUseId": tool_call_id, + "content": [ + {"text": str(content) if content else ""} + ], + } + } + ], + } + ) else: # Convert to Converse API format with proper content structure - converse_messages.append({"role": role, "content": [{"text": content}]}) + # Ensure content is not None + text_content = content if content else "" + converse_messages.append( + {"role": role, "content": [{"text": text_content}]} + ) # CRITICAL: Handle model-specific conversation requirements # Cohere and some other models require conversation to end with user message @@ -1349,6 +1413,58 @@ class BedrockCompletion(BaseLLM): return converse_messages, system_message + @staticmethod + def _messages_contain_tool_content(messages: list[LLMMessage]) -> bool: + """Check if messages contain toolUse or toolResult content blocks. + + Bedrock requires toolConfig when messages have tool-related content. + """ + for message in messages: + content = message.get("content", []) + if isinstance(content, list): + for block in content: + if isinstance(block, dict): + if "toolUse" in block or "toolResult" in block: + return True + return False + + @staticmethod + def _extract_tools_from_message_history( + messages: list[LLMMessage], + ) -> list[dict[str, Any]]: + """Extract tool definitions from toolUse blocks in message history. + + When no tools are passed but messages contain toolUse, we need to + recreate a minimal toolConfig to satisfy Bedrock's API requirements. + """ + tools: list[dict[str, Any]] = [] + seen_tool_names: set[str] = set() + + for message in messages: + content = message.get("content", []) + if isinstance(content, list): + for block in content: + if isinstance(block, dict) and "toolUse" in block: + tool_use = block["toolUse"] + tool_name = tool_use.get("name", "") + if tool_name and tool_name not in seen_tool_names: + seen_tool_names.add(tool_name) + # Create a minimal tool spec from the toolUse block + tool_spec: dict[str, Any] = { + "toolSpec": { + "name": tool_name, + "description": f"Tool: {tool_name}", + "inputSchema": { + "json": { + "type": "object", + "properties": {}, + } + }, + } + } + tools.append(tool_spec) + return tools + @staticmethod def _format_tools_for_converse( tools: list[dict[str, Any]], diff --git a/lib/crewai/src/crewai/utilities/agent_utils.py b/lib/crewai/src/crewai/utilities/agent_utils.py index 3d88474a4..40118d6e8 100644 --- a/lib/crewai/src/crewai/utilities/agent_utils.py +++ b/lib/crewai/src/crewai/utilities/agent_utils.py @@ -875,7 +875,8 @@ def extract_tool_call_info( call_id = getattr(tool_call, "id", f"call_{id(tool_call)}") return call_id, tool_call.name, tool_call.input if isinstance(tool_call, dict): - call_id = tool_call.get("id", f"call_{id(tool_call)}") + # Support OpenAI "id", Bedrock "toolUseId", or generate one + call_id = tool_call.get("id") or tool_call.get("toolUseId") or f"call_{id(tool_call)}" func_info = tool_call.get("function", {}) func_name = func_info.get("name", "") or tool_call.get("name", "") func_args = func_info.get("arguments", "{}") or tool_call.get("input", {}) diff --git a/lib/crewai/tests/agents/test_native_tool_calling.py b/lib/crewai/tests/agents/test_native_tool_calling.py index 1724a81dc..662aa7b50 100644 --- a/lib/crewai/tests/agents/test_native_tool_calling.py +++ b/lib/crewai/tests/agents/test_native_tool_calling.py @@ -241,26 +241,26 @@ class TestGeminiNativeToolCalling: self, calculator_tool: CalculatorTool ) -> None: """Test Gemini agent can use native tool calling.""" - with patch.dict(os.environ, {"GOOGLE_GENAI_USE_VERTEXAI": "true"}): - agent = Agent( - role="Math Assistant", - goal="Help users with mathematical calculations", - backstory="You are a helpful math assistant.", - tools=[calculator_tool], - llm=LLM(model="gemini/gemini-2.0-flash-exp"), - ) - task = Task( - description="Calculate what is 15 * 8", - expected_output="The result of the calculation", - agent=agent, - ) + agent = Agent( + role="Math Assistant", + goal="Help users with mathematical calculations", + backstory="You are a helpful math assistant.", + tools=[calculator_tool], + llm=LLM(model="gemini/gemini-2.0-flash-exp"), + ) - crew = Crew(agents=[agent], tasks=[task]) - result = crew.kickoff() + task = Task( + description="Calculate what is 15 * 8", + expected_output="The result of the calculation", + agent=agent, + ) - assert result is not None - assert result.raw is not None + crew = Crew(agents=[agent], tasks=[task]) + result = crew.kickoff() + + assert result is not None + assert result.raw is not None def test_gemini_agent_kickoff_with_tools_mocked( self, calculator_tool: CalculatorTool @@ -387,40 +387,45 @@ class TestBedrockNativeToolCalling: def mock_aws_env(self): """Mock AWS environment variables for tests.""" env_vars = { - "AWS_ACCESS_KEY_ID": "test-key", - "AWS_SECRET_ACCESS_KEY": "test-secret", - "AWS_REGION": "us-east-1", + "AWS_ACCESS_KEY_ID": "test-key", + "AWS_SECRET_ACCESS_KEY": "test-secret", + "AWS_REGION": "us-east-1", } - with patch.dict(os.environ, env_vars): + if "AWS_ACCESS_KEY_ID" not in os.environ: + with patch.dict(os.environ, env_vars): + yield + else: yield + @pytest.mark.vcr() def test_bedrock_agent_kickoff_with_tools_mocked( self, calculator_tool: CalculatorTool ) -> None: """Test Bedrock agent kickoff with mocked LLM call.""" llm = LLM(model="bedrock/anthropic.claude-3-haiku-20240307-v1:0") - with patch.object(llm, "call", return_value="The answer is 120.") as mock_call: - agent = Agent( - role="Math Assistant", - goal="Calculate math", - backstory="You calculate.", - tools=[calculator_tool], - llm=llm, - verbose=False, - ) + agent = Agent( + role="Math Assistant", + goal="Calculate math", + backstory="You calculate.", + tools=[calculator_tool], + llm=llm, + verbose=False, + max_iter=5, + ) - task = Task( - description="Calculate 15 * 8", - expected_output="Result", - agent=agent, - ) + task = Task( + description="Calculate 15 * 8", + expected_output="Result", + agent=agent, + ) - crew = Crew(agents=[agent], tasks=[task]) - result = crew.kickoff() + crew = Crew(agents=[agent], tasks=[task]) + result = crew.kickoff() - assert mock_call.called - assert result is not None + assert result is not None + assert result.raw is not None + assert "120" in str(result.raw) # ============================================================================= diff --git a/lib/crewai/tests/cassettes/agents/TestBedrockNativeToolCalling.test_bedrock_agent_kickoff_with_tools_mocked.yaml b/lib/crewai/tests/cassettes/agents/TestBedrockNativeToolCalling.test_bedrock_agent_kickoff_with_tools_mocked.yaml new file mode 100644 index 000000000..1e7565eb1 --- /dev/null +++ b/lib/crewai/tests/cassettes/agents/TestBedrockNativeToolCalling.test_bedrock_agent_kickoff_with_tools_mocked.yaml @@ -0,0 +1,485 @@ +interactions: +- request: + body: '{"messages": [{"role": "user", "content": [{"text": "\nCurrent Task: Calculate + 15 * 8\n\nThis is the expected criteria for your final answer: Result\nyou MUST + return the actual complete content as the final answer, not a summary.\n\nThis + is VERY important to you, your job depends on it!"}]}], "inferenceConfig": {"stopSequences": + ["\nObservation:"]}, "system": [{"text": "You are Math Assistant. You calculate.\nYour + personal goal is: Calculate math"}], "toolConfig": {"tools": [{"toolSpec": {"name": + "calculator", "description": "Perform mathematical calculations. Use this for + any math operations.", "inputSchema": {"json": {"properties": {"expression": + {"description": "Mathematical expression to evaluate", "title": "Expression", + "type": "string"}}, "required": ["expression"], "type": "object"}}}}]}}' + headers: + Content-Length: + - '806' + Content-Type: + - !!binary | + YXBwbGljYXRpb24vanNvbg== + User-Agent: + - X-USER-AGENT-XXX + amz-sdk-invocation-id: + - AMZ-SDK-INVOCATION-ID-XXX + amz-sdk-request: + - !!binary | + YXR0ZW1wdD0x + authorization: + - AUTHORIZATION-XXX + x-amz-date: + - X-AMZ-DATE-XXX + method: POST + uri: https://bedrock-runtime.us-east-1.amazonaws.com/model/anthropic.claude-3-haiku-20240307-v1%3A0/converse + response: + body: + string: '{"metrics":{"latencyMs":1540},"output":{"message":{"content":[{"text":"Here + is the calculation for 15 * 8:"},{"toolUse":{"input":{"expression":"15 * 8"},"name":"calculator","toolUseId":"tooluse_1OIARGnOTjiITDKGd_FgMA"}}],"role":"assistant"}},"stopReason":"tool_use","usage":{"inputTokens":417,"outputTokens":68,"serverToolUsage":{},"totalTokens":485}}' + headers: + Connection: + - keep-alive + Content-Length: + - '351' + Content-Type: + - application/json + Date: + - Thu, 22 Jan 2026 21:27:56 GMT + x-amzn-RequestId: + - X-AMZN-REQUESTID-XXX + status: + code: 200 + message: OK +- request: + body: '{"messages": [{"role": "user", "content": [{"text": "\nCurrent Task: Calculate + 15 * 8\n\nThis is the expected criteria for your final answer: Result\nyou MUST + return the actual complete content as the final answer, not a summary.\n\nThis + is VERY important to you, your job depends on it!"}]}, {"role": "assistant", + "content": [{"toolUse": {"toolUseId": "tooluse_1OIARGnOTjiITDKGd_FgMA", "name": + "calculator", "input": {}}}]}, {"role": "user", "content": [{"toolResult": {"toolUseId": + "tooluse_1OIARGnOTjiITDKGd_FgMA", "content": [{"text": "Error executing tool: + CalculatorTool._run() missing 1 required positional argument: ''expression''"}]}}]}, + {"role": "user", "content": [{"text": "Analyze the tool result. If requirements + are met, provide the Final Answer. Otherwise, call the next tool. Deliver only + the answer without meta-commentary."}]}], "inferenceConfig": {"stopSequences": + ["\nObservation:"]}, "system": [{"text": "You are Math Assistant. You calculate.\nYour + personal goal is: Calculate math"}], "toolConfig": {"tools": [{"toolSpec": {"name": + "calculator", "description": "Perform mathematical calculations. Use this for + any math operations.", "inputSchema": {"json": {"properties": {"expression": + {"description": "Mathematical expression to evaluate", "title": "Expression", + "type": "string"}}, "required": ["expression"], "type": "object"}}}}]}}' + headers: + Content-Length: + - '1358' + Content-Type: + - !!binary | + YXBwbGljYXRpb24vanNvbg== + User-Agent: + - X-USER-AGENT-XXX + amz-sdk-invocation-id: + - AMZ-SDK-INVOCATION-ID-XXX + amz-sdk-request: + - !!binary | + YXR0ZW1wdD0x + authorization: + - AUTHORIZATION-XXX + x-amz-date: + - X-AMZ-DATE-XXX + method: POST + uri: https://bedrock-runtime.us-east-1.amazonaws.com/model/anthropic.claude-3-haiku-20240307-v1%3A0/converse + response: + body: + string: '{"metrics":{"latencyMs":1071},"output":{"message":{"content":[{"toolUse":{"input":{"expression":"15 + * 8"},"name":"calculator","toolUseId":"tooluse_vjcn57LeQpS-pePkTvny8w"}}],"role":"assistant"}},"stopReason":"tool_use","usage":{"inputTokens":527,"outputTokens":55,"serverToolUsage":{},"totalTokens":582}}' + headers: + Connection: + - keep-alive + Content-Length: + - '304' + Content-Type: + - application/json + Date: + - Thu, 22 Jan 2026 21:27:57 GMT + x-amzn-RequestId: + - X-AMZN-REQUESTID-XXX + status: + code: 200 + message: OK +- request: + body: '{"messages": [{"role": "user", "content": [{"text": "\nCurrent Task: Calculate + 15 * 8\n\nThis is the expected criteria for your final answer: Result\nyou MUST + return the actual complete content as the final answer, not a summary.\n\nThis + is VERY important to you, your job depends on it!"}]}, {"role": "assistant", + "content": [{"toolUse": {"toolUseId": "tooluse_1OIARGnOTjiITDKGd_FgMA", "name": + "calculator", "input": {}}}]}, {"role": "user", "content": [{"toolResult": {"toolUseId": + "tooluse_1OIARGnOTjiITDKGd_FgMA", "content": [{"text": "Error executing tool: + CalculatorTool._run() missing 1 required positional argument: ''expression''"}]}}]}, + {"role": "user", "content": [{"text": "Analyze the tool result. If requirements + are met, provide the Final Answer. Otherwise, call the next tool. Deliver only + the answer without meta-commentary."}]}, {"role": "assistant", "content": [{"toolUse": + {"toolUseId": "tooluse_vjcn57LeQpS-pePkTvny8w", "name": "calculator", "input": + {}}}]}, {"role": "user", "content": [{"toolResult": {"toolUseId": "tooluse_vjcn57LeQpS-pePkTvny8w", + "content": [{"text": "Error executing tool: CalculatorTool._run() missing 1 + required positional argument: ''expression''"}]}}]}, {"role": "user", "content": + [{"text": "Analyze the tool result. If requirements are met, provide the Final + Answer. Otherwise, call the next tool. Deliver only the answer without meta-commentary."}]}], + "inferenceConfig": {"stopSequences": ["\nObservation:"]}, "system": [{"text": + "You are Math Assistant. You calculate.\nYour personal goal is: Calculate math"}], + "toolConfig": {"tools": [{"toolSpec": {"name": "calculator", "description": + "Perform mathematical calculations. Use this for any math operations.", "inputSchema": + {"json": {"properties": {"expression": {"description": "Mathematical expression + to evaluate", "title": "Expression", "type": "string"}}, "required": ["expression"], + "type": "object"}}}}]}}' + headers: + Content-Length: + - '1910' + Content-Type: + - !!binary | + YXBwbGljYXRpb24vanNvbg== + User-Agent: + - X-USER-AGENT-XXX + amz-sdk-invocation-id: + - AMZ-SDK-INVOCATION-ID-XXX + amz-sdk-request: + - !!binary | + YXR0ZW1wdD0x + authorization: + - AUTHORIZATION-XXX + x-amz-date: + - X-AMZ-DATE-XXX + method: POST + uri: https://bedrock-runtime.us-east-1.amazonaws.com/model/anthropic.claude-3-haiku-20240307-v1%3A0/converse + response: + body: + string: '{"metrics":{"latencyMs":927},"output":{"message":{"content":[{"toolUse":{"input":{"expression":"15 + * 8"},"name":"calculator","toolUseId":"tooluse__4aP-hcTR4Ozp5gTlESXbg"}}],"role":"assistant"}},"stopReason":"tool_use","usage":{"inputTokens":637,"outputTokens":57,"serverToolUsage":{},"totalTokens":694}}' + headers: + Connection: + - keep-alive + Content-Length: + - '303' + Content-Type: + - application/json + Date: + - Thu, 22 Jan 2026 21:27:58 GMT + x-amzn-RequestId: + - X-AMZN-REQUESTID-XXX + status: + code: 200 + message: OK +- request: + body: '{"messages": [{"role": "user", "content": [{"text": "\nCurrent Task: Calculate + 15 * 8\n\nThis is the expected criteria for your final answer: Result\nyou MUST + return the actual complete content as the final answer, not a summary.\n\nThis + is VERY important to you, your job depends on it!"}]}, {"role": "assistant", + "content": [{"toolUse": {"toolUseId": "tooluse_1OIARGnOTjiITDKGd_FgMA", "name": + "calculator", "input": {}}}]}, {"role": "user", "content": [{"toolResult": {"toolUseId": + "tooluse_1OIARGnOTjiITDKGd_FgMA", "content": [{"text": "Error executing tool: + CalculatorTool._run() missing 1 required positional argument: ''expression''"}]}}]}, + {"role": "user", "content": [{"text": "Analyze the tool result. If requirements + are met, provide the Final Answer. Otherwise, call the next tool. Deliver only + the answer without meta-commentary."}]}, {"role": "assistant", "content": [{"toolUse": + {"toolUseId": "tooluse_vjcn57LeQpS-pePkTvny8w", "name": "calculator", "input": + {}}}]}, {"role": "user", "content": [{"toolResult": {"toolUseId": "tooluse_vjcn57LeQpS-pePkTvny8w", + "content": [{"text": "Error executing tool: CalculatorTool._run() missing 1 + required positional argument: ''expression''"}]}}]}, {"role": "user", "content": + [{"text": "Analyze the tool result. If requirements are met, provide the Final + Answer. Otherwise, call the next tool. Deliver only the answer without meta-commentary."}]}, + {"role": "assistant", "content": [{"toolUse": {"toolUseId": "tooluse__4aP-hcTR4Ozp5gTlESXbg", + "name": "calculator", "input": {}}}]}, {"role": "user", "content": [{"toolResult": + {"toolUseId": "tooluse__4aP-hcTR4Ozp5gTlESXbg", "content": [{"text": "Error + executing tool: CalculatorTool._run() missing 1 required positional argument: + ''expression''"}]}}]}, {"role": "user", "content": [{"text": "Analyze the tool + result. If requirements are met, provide the Final Answer. Otherwise, call the + next tool. Deliver only the answer without meta-commentary."}]}], "inferenceConfig": + {"stopSequences": ["\nObservation:"]}, "system": [{"text": "You are Math Assistant. + You calculate.\nYour personal goal is: Calculate math"}], "toolConfig": {"tools": + [{"toolSpec": {"name": "calculator", "description": "Perform mathematical calculations. + Use this for any math operations.", "inputSchema": {"json": {"properties": {"expression": + {"description": "Mathematical expression to evaluate", "title": "Expression", + "type": "string"}}, "required": ["expression"], "type": "object"}}}}]}}' + headers: + Content-Length: + - '2462' + Content-Type: + - !!binary | + YXBwbGljYXRpb24vanNvbg== + User-Agent: + - X-USER-AGENT-XXX + amz-sdk-invocation-id: + - AMZ-SDK-INVOCATION-ID-XXX + amz-sdk-request: + - !!binary | + YXR0ZW1wdD0x + authorization: + - AUTHORIZATION-XXX + x-amz-date: + - X-AMZ-DATE-XXX + method: POST + uri: https://bedrock-runtime.us-east-1.amazonaws.com/model/anthropic.claude-3-haiku-20240307-v1%3A0/converse + response: + body: + string: '{"metrics":{"latencyMs":1226},"output":{"message":{"content":[{"toolUse":{"input":{"expression":"15 + * 8"},"name":"calculator","toolUseId":"tooluse_fEJhgDNjSUic0g97dN8Xww"}}],"role":"assistant"}},"stopReason":"tool_use","usage":{"inputTokens":747,"outputTokens":55,"serverToolUsage":{},"totalTokens":802}}' + headers: + Connection: + - keep-alive + Content-Length: + - '304' + Content-Type: + - application/json + Date: + - Thu, 22 Jan 2026 21:28:00 GMT + x-amzn-RequestId: + - X-AMZN-REQUESTID-XXX + status: + code: 200 + message: OK +- request: + body: '{"messages": [{"role": "user", "content": [{"text": "\nCurrent Task: Calculate + 15 * 8\n\nThis is the expected criteria for your final answer: Result\nyou MUST + return the actual complete content as the final answer, not a summary.\n\nThis + is VERY important to you, your job depends on it!"}]}, {"role": "assistant", + "content": [{"toolUse": {"toolUseId": "tooluse_1OIARGnOTjiITDKGd_FgMA", "name": + "calculator", "input": {}}}]}, {"role": "user", "content": [{"toolResult": {"toolUseId": + "tooluse_1OIARGnOTjiITDKGd_FgMA", "content": [{"text": "Error executing tool: + CalculatorTool._run() missing 1 required positional argument: ''expression''"}]}}]}, + {"role": "user", "content": [{"text": "Analyze the tool result. If requirements + are met, provide the Final Answer. Otherwise, call the next tool. Deliver only + the answer without meta-commentary."}]}, {"role": "assistant", "content": [{"toolUse": + {"toolUseId": "tooluse_vjcn57LeQpS-pePkTvny8w", "name": "calculator", "input": + {}}}]}, {"role": "user", "content": [{"toolResult": {"toolUseId": "tooluse_vjcn57LeQpS-pePkTvny8w", + "content": [{"text": "Error executing tool: CalculatorTool._run() missing 1 + required positional argument: ''expression''"}]}}]}, {"role": "user", "content": + [{"text": "Analyze the tool result. If requirements are met, provide the Final + Answer. Otherwise, call the next tool. Deliver only the answer without meta-commentary."}]}, + {"role": "assistant", "content": [{"toolUse": {"toolUseId": "tooluse__4aP-hcTR4Ozp5gTlESXbg", + "name": "calculator", "input": {}}}]}, {"role": "user", "content": [{"toolResult": + {"toolUseId": "tooluse__4aP-hcTR4Ozp5gTlESXbg", "content": [{"text": "Error + executing tool: CalculatorTool._run() missing 1 required positional argument: + ''expression''"}]}}]}, {"role": "user", "content": [{"text": "Analyze the tool + result. If requirements are met, provide the Final Answer. Otherwise, call the + next tool. Deliver only the answer without meta-commentary."}]}, {"role": "assistant", + "content": [{"toolUse": {"toolUseId": "tooluse_fEJhgDNjSUic0g97dN8Xww", "name": + "calculator", "input": {}}}]}, {"role": "user", "content": [{"toolResult": {"toolUseId": + "tooluse_fEJhgDNjSUic0g97dN8Xww", "content": [{"text": "Error executing tool: + CalculatorTool._run() missing 1 required positional argument: ''expression''"}]}}]}, + {"role": "user", "content": [{"text": "Analyze the tool result. If requirements + are met, provide the Final Answer. Otherwise, call the next tool. Deliver only + the answer without meta-commentary."}]}], "inferenceConfig": {"stopSequences": + ["\nObservation:"]}, "system": [{"text": "You are Math Assistant. You calculate.\nYour + personal goal is: Calculate math"}], "toolConfig": {"tools": [{"toolSpec": {"name": + "calculator", "description": "Perform mathematical calculations. Use this for + any math operations.", "inputSchema": {"json": {"properties": {"expression": + {"description": "Mathematical expression to evaluate", "title": "Expression", + "type": "string"}}, "required": ["expression"], "type": "object"}}}}]}}' + headers: + Content-Length: + - '3014' + Content-Type: + - !!binary | + YXBwbGljYXRpb24vanNvbg== + User-Agent: + - X-USER-AGENT-XXX + amz-sdk-invocation-id: + - AMZ-SDK-INVOCATION-ID-XXX + amz-sdk-request: + - !!binary | + YXR0ZW1wdD0x + authorization: + - AUTHORIZATION-XXX + x-amz-date: + - X-AMZ-DATE-XXX + method: POST + uri: https://bedrock-runtime.us-east-1.amazonaws.com/model/anthropic.claude-3-haiku-20240307-v1%3A0/converse + response: + body: + string: '{"metrics":{"latencyMs":947},"output":{"message":{"content":[{"toolUse":{"input":{"expression":"15 + * 8"},"name":"calculator","toolUseId":"tooluse_F5QIGY91SBOeM4VcFRB73A"}}],"role":"assistant"}},"stopReason":"tool_use","usage":{"inputTokens":857,"outputTokens":55,"serverToolUsage":{},"totalTokens":912}}' + headers: + Connection: + - keep-alive + Content-Length: + - '303' + Content-Type: + - application/json + Date: + - Thu, 22 Jan 2026 21:28:01 GMT + x-amzn-RequestId: + - X-AMZN-REQUESTID-XXX + status: + code: 200 + message: OK +- request: + body: '{"messages": [{"role": "user", "content": [{"text": "\nCurrent Task: Calculate + 15 * 8\n\nThis is the expected criteria for your final answer: Result\nyou MUST + return the actual complete content as the final answer, not a summary.\n\nThis + is VERY important to you, your job depends on it!"}]}, {"role": "assistant", + "content": [{"toolUse": {"toolUseId": "tooluse_1OIARGnOTjiITDKGd_FgMA", "name": + "calculator", "input": {}}}]}, {"role": "user", "content": [{"toolResult": {"toolUseId": + "tooluse_1OIARGnOTjiITDKGd_FgMA", "content": [{"text": "Error executing tool: + CalculatorTool._run() missing 1 required positional argument: ''expression''"}]}}]}, + {"role": "user", "content": [{"text": "Analyze the tool result. If requirements + are met, provide the Final Answer. Otherwise, call the next tool. Deliver only + the answer without meta-commentary."}]}, {"role": "assistant", "content": [{"toolUse": + {"toolUseId": "tooluse_vjcn57LeQpS-pePkTvny8w", "name": "calculator", "input": + {}}}]}, {"role": "user", "content": [{"toolResult": {"toolUseId": "tooluse_vjcn57LeQpS-pePkTvny8w", + "content": [{"text": "Error executing tool: CalculatorTool._run() missing 1 + required positional argument: ''expression''"}]}}]}, {"role": "user", "content": + [{"text": "Analyze the tool result. If requirements are met, provide the Final + Answer. Otherwise, call the next tool. Deliver only the answer without meta-commentary."}]}, + {"role": "assistant", "content": [{"toolUse": {"toolUseId": "tooluse__4aP-hcTR4Ozp5gTlESXbg", + "name": "calculator", "input": {}}}]}, {"role": "user", "content": [{"toolResult": + {"toolUseId": "tooluse__4aP-hcTR4Ozp5gTlESXbg", "content": [{"text": "Error + executing tool: CalculatorTool._run() missing 1 required positional argument: + ''expression''"}]}}]}, {"role": "user", "content": [{"text": "Analyze the tool + result. If requirements are met, provide the Final Answer. Otherwise, call the + next tool. Deliver only the answer without meta-commentary."}]}, {"role": "assistant", + "content": [{"toolUse": {"toolUseId": "tooluse_fEJhgDNjSUic0g97dN8Xww", "name": + "calculator", "input": {}}}]}, {"role": "user", "content": [{"toolResult": {"toolUseId": + "tooluse_fEJhgDNjSUic0g97dN8Xww", "content": [{"text": "Error executing tool: + CalculatorTool._run() missing 1 required positional argument: ''expression''"}]}}]}, + {"role": "user", "content": [{"text": "Analyze the tool result. If requirements + are met, provide the Final Answer. Otherwise, call the next tool. Deliver only + the answer without meta-commentary."}]}, {"role": "assistant", "content": [{"toolUse": + {"toolUseId": "tooluse_F5QIGY91SBOeM4VcFRB73A", "name": "calculator", "input": + {}}}]}, {"role": "user", "content": [{"toolResult": {"toolUseId": "tooluse_F5QIGY91SBOeM4VcFRB73A", + "content": [{"text": "Error executing tool: CalculatorTool._run() missing 1 + required positional argument: ''expression''"}]}}]}, {"role": "user", "content": + [{"text": "Analyze the tool result. If requirements are met, provide the Final + Answer. Otherwise, call the next tool. Deliver only the answer without meta-commentary."}]}, + {"role": "assistant", "content": [{"text": "Now it''s time you MUST give your + absolute best final answer. You''ll ignore all previous instructions, stop using + any tools, and just return your absolute BEST Final answer."}]}], "inferenceConfig": + {"stopSequences": ["\nObservation:"]}, "system": [{"text": "You are Math Assistant. + You calculate.\nYour personal goal is: Calculate math"}], "toolConfig": {"tools": + [{"toolSpec": {"name": "calculator", "description": "Tool: calculator", "inputSchema": + {"json": {"type": "object", "properties": {}}}}}]}}' + headers: + Content-Length: + - '3599' + Content-Type: + - !!binary | + YXBwbGljYXRpb24vanNvbg== + User-Agent: + - X-USER-AGENT-XXX + amz-sdk-invocation-id: + - AMZ-SDK-INVOCATION-ID-XXX + amz-sdk-request: + - !!binary | + YXR0ZW1wdD0x + authorization: + - AUTHORIZATION-XXX + x-amz-date: + - X-AMZ-DATE-XXX + method: POST + uri: https://bedrock-runtime.us-east-1.amazonaws.com/model/anthropic.claude-3-haiku-20240307-v1%3A0/converse + response: + body: + string: '{"message":"The model returned the following errors: Your API request + included an `assistant` message in the final position, which would pre-fill + the `assistant` response. When using tools, pre-filling the `assistant` response + is not supported."}' + headers: + Connection: + - keep-alive + Content-Length: + - '246' + Content-Type: + - application/json + Date: + - Thu, 22 Jan 2026 21:28:02 GMT + x-amzn-ErrorType: + - ValidationException:http://internal.amazon.com/coral/com.amazon.bedrock/ + x-amzn-RequestId: + - X-AMZN-REQUESTID-XXX + status: + code: 400 + message: Bad Request +- request: + body: '{"messages": [{"role": "user", "content": [{"text": "\nCurrent Task: Calculate + 15 * 8\n\nThis is the expected criteria for your final answer: Result\nyou MUST + return the actual complete content as the final answer, not a summary.\n\nThis + is VERY important to you, your job depends on it!"}]}, {"role": "assistant", + "content": [{"toolUse": {"toolUseId": "tooluse_1OIARGnOTjiITDKGd_FgMA", "name": + "calculator", "input": {}}}]}, {"role": "user", "content": [{"toolResult": {"toolUseId": + "tooluse_1OIARGnOTjiITDKGd_FgMA", "content": [{"text": "Error executing tool: + CalculatorTool._run() missing 1 required positional argument: ''expression''"}]}}]}, + {"role": "user", "content": [{"text": "Analyze the tool result. If requirements + are met, provide the Final Answer. Otherwise, call the next tool. Deliver only + the answer without meta-commentary."}]}, {"role": "assistant", "content": [{"toolUse": + {"toolUseId": "tooluse_vjcn57LeQpS-pePkTvny8w", "name": "calculator", "input": + {}}}]}, {"role": "user", "content": [{"toolResult": {"toolUseId": "tooluse_vjcn57LeQpS-pePkTvny8w", + "content": [{"text": "Error executing tool: CalculatorTool._run() missing 1 + required positional argument: ''expression''"}]}}]}, {"role": "user", "content": + [{"text": "Analyze the tool result. If requirements are met, provide the Final + Answer. Otherwise, call the next tool. Deliver only the answer without meta-commentary."}]}, + {"role": "assistant", "content": [{"toolUse": {"toolUseId": "tooluse__4aP-hcTR4Ozp5gTlESXbg", + "name": "calculator", "input": {}}}]}, {"role": "user", "content": [{"toolResult": + {"toolUseId": "tooluse__4aP-hcTR4Ozp5gTlESXbg", "content": [{"text": "Error + executing tool: CalculatorTool._run() missing 1 required positional argument: + ''expression''"}]}}]}, {"role": "user", "content": [{"text": "Analyze the tool + result. If requirements are met, provide the Final Answer. Otherwise, call the + next tool. Deliver only the answer without meta-commentary."}]}, {"role": "assistant", + "content": [{"toolUse": {"toolUseId": "tooluse_fEJhgDNjSUic0g97dN8Xww", "name": + "calculator", "input": {}}}]}, {"role": "user", "content": [{"toolResult": {"toolUseId": + "tooluse_fEJhgDNjSUic0g97dN8Xww", "content": [{"text": "Error executing tool: + CalculatorTool._run() missing 1 required positional argument: ''expression''"}]}}]}, + {"role": "user", "content": [{"text": "Analyze the tool result. If requirements + are met, provide the Final Answer. Otherwise, call the next tool. Deliver only + the answer without meta-commentary."}]}, {"role": "assistant", "content": [{"toolUse": + {"toolUseId": "tooluse_F5QIGY91SBOeM4VcFRB73A", "name": "calculator", "input": + {}}}]}, {"role": "user", "content": [{"toolResult": {"toolUseId": "tooluse_F5QIGY91SBOeM4VcFRB73A", + "content": [{"text": "Error executing tool: CalculatorTool._run() missing 1 + required positional argument: ''expression''"}]}}]}, {"role": "user", "content": + [{"text": "Analyze the tool result. If requirements are met, provide the Final + Answer. Otherwise, call the next tool. Deliver only the answer without meta-commentary."}]}, + {"role": "assistant", "content": [{"text": "Now it''s time you MUST give your + absolute best final answer. You''ll ignore all previous instructions, stop using + any tools, and just return your absolute BEST Final answer."}]}, {"role": "user", + "content": [{"text": "\nCurrent Task: Calculate 15 * 8\n\nThis is the expected + criteria for your final answer: Result\nyou MUST return the actual complete + content as the final answer, not a summary.\n\nThis is VERY important to you, + your job depends on it!"}]}, {"role": "assistant", "content": [{"text": "Now + it''s time you MUST give your absolute best final answer. You''ll ignore all + previous instructions, stop using any tools, and just return your absolute BEST + Final answer."}]}], "inferenceConfig": {"stopSequences": ["\nObservation:"]}, + "system": [{"text": "You are Math Assistant. You calculate.\nYour personal goal + is: Calculate math\n\nYou are Math Assistant. You calculate.\nYour personal + goal is: Calculate math"}], "toolConfig": {"tools": [{"toolSpec": {"name": "calculator", + "description": "Tool: calculator", "inputSchema": {"json": {"type": "object", + "properties": {}}}}}]}}' + headers: + Content-Length: + - '4181' + Content-Type: + - !!binary | + YXBwbGljYXRpb24vanNvbg== + User-Agent: + - X-USER-AGENT-XXX + amz-sdk-invocation-id: + - AMZ-SDK-INVOCATION-ID-XXX + amz-sdk-request: + - !!binary | + YXR0ZW1wdD0x + authorization: + - AUTHORIZATION-XXX + x-amz-date: + - X-AMZ-DATE-XXX + method: POST + uri: https://bedrock-runtime.us-east-1.amazonaws.com/model/anthropic.claude-3-haiku-20240307-v1%3A0/converse + response: + body: + string: '{"metrics":{"latencyMs":715},"output":{"message":{"content":[{"text":"\n\n120"}],"role":"assistant"}},"stopReason":"end_turn","usage":{"inputTokens":1082,"outputTokens":5,"serverToolUsage":{},"totalTokens":1087}}' + headers: + Connection: + - keep-alive + Content-Length: + - '212' + Content-Type: + - application/json + Date: + - Thu, 22 Jan 2026 21:28:03 GMT + x-amzn-RequestId: + - X-AMZN-REQUESTID-XXX + status: + code: 200 + message: OK +version: 1