AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
fix(backend): support Responses API in SmartDecisionMakerBlock (#12489)
Nicholas Tindlef01f6686744e
diff --git a/autogpt_platform/backend/backend/blocks/llm.py b/autogpt_platform/backend/backend/blocks/llm.pyindex 298aeb9240..29787767df 100644--- a/autogpt_platform/backend/backend/blocks/llm.py+++ b/autogpt_platform/backend/backend/blocks/llm.py@@ -33,6 +33,13 @@ from backend.integrations.providers import ProviderNamefrom backend.util import jsonfrom backend.util.clients import OPENROUTER_BASE_URLfrom backend.util.logging import TruncatedLogger+from backend.util.openai_responses import (+ convert_tools_to_responses_format,+ extract_responses_content,+ extract_responses_reasoning,+ extract_responses_tool_calls,+ extract_responses_usage,+)from backend.util.prompt import compress_context, estimate_token_countfrom backend.util.request import validate_url_hostfrom backend.util.settings import Settings@@ -111,7 +118,6 @@ class LlmModel(str, Enum, metaclass=LlmModelMeta):GPT4O_MINI = "gpt-4o-mini"GPT4O = "gpt-4o"GPT4_TURBO = "gpt-4-turbo"- GPT3_5_TURBO = "gpt-3.5-turbo"# Anthropic modelsCLAUDE_4_1_OPUS = "claude-opus-4-1-20250805"CLAUDE_4_OPUS = "claude-opus-4-20250514"@@ -277,9 +283,6 @@ MODEL_METADATA = {LlmModel.GPT4_TURBO: ModelMetadata("openai", 128000, 4096, "GPT-4 Turbo", "OpenAI", "OpenAI", 3), # gpt-4-turbo-2024-04-09- LlmModel.GPT3_5_TURBO: ModelMetadata(- "openai", 16385, 4096, "GPT-3.5 Turbo", "OpenAI", "OpenAI", 1- ), # gpt-3.5-turbo-0125# https://docs.anthropic.com/en/docs/about-claude/modelsLlmModel.CLAUDE_4_1_OPUS: ModelMetadata("anthropic", 200000, 32000, "Claude Opus 4.1", "Anthropic", "Anthropic", 3@@ -801,36 +804,53 @@ async def llm_call(max_tokens = max(min(available_tokens, model_max_output, user_max), 1)if provider == "openai":- tools_param = tools if tools else openai.NOT_GIVENoai_client = openai.AsyncOpenAI(api_key=credentials.api_key.get_secret_value())- response_format = None- parallel_tool_calls = get_parallel_tool_calls_param(- llm_model, parallel_tool_calls- )+ tools_param = convert_tools_to_responses_format(tools) if tools else openai.omit+ text_config = openai.omitif force_json_output:- response_format = {"type": "json_object"}+ text_config = {"format": {"type": "json_object"}} # type: ignore- response = await oai_client.chat.completions.create(+ response = await oai_client.responses.create(model=llm_model.value,- messages=prompt, # type: ignore- response_format=response_format, # type: ignore- max_completion_tokens=max_tokens,- tools=tools_param, # type: ignore- parallel_tool_calls=parallel_tool_calls,+ input=prompt, # type: ignore[arg-type]+ tools=tools_param, # type: ignore[arg-type]+ max_output_tokens=max_tokens,+ parallel_tool_calls=get_parallel_tool_calls_param(+ llm_model, parallel_tool_calls+ ),+ text=text_config, # type: ignore[arg-type]+ store=False,+ )++ raw_tool_calls = extract_responses_tool_calls(response)+ tool_calls = (+ [+ ToolContentBlock(+ id=tc["id"],+ type=tc["type"],+ function=ToolCall(+ name=tc["function"]["name"],+ arguments=tc["function"]["arguments"],+ ),+ )+ for tc in raw_tool_calls+ ]+ if raw_tool_calls+ else None)-- tool_calls = extract_openai_tool_calls(response)- reasoning = extract_openai_reasoning(response)+ reasoning = extract_responses_reasoning(response)+ content = extract_responses_content(response)+ prompt_tokens, completion_tokens = extract_responses_usage(response)return LLMResponse(- raw_response=response.choices[0].message,+ raw_response=response,prompt=prompt,- response=response.choices[0].message.content or "",+ response=content,tool_calls=tool_calls,- prompt_tokens=response.usage.prompt_tokens if response.usage else 0,- completion_tokens=response.usage.completion_tokens if response.usage else 0,+ prompt_tokens=prompt_tokens,+ completion_tokens=completion_tokens,reasoning=reasoning,)elif provider == "anthropic":diff --git a/autogpt_platform/backend/backend/blocks/smart_decision_maker.py b/autogpt_platform/backend/backend/blocks/smart_decision_maker.pyindex 49680548af..7622d734cd 100644--- a/autogpt_platform/backend/backend/blocks/smart_decision_maker.py+++ b/autogpt_platform/backend/backend/blocks/smart_decision_maker.py@@ -61,20 +61,27 @@ class ExecutionParams(BaseModel):def _get_tool_requests(entry: dict[str, Any]) -> list[str]:"""Return a list of tool_call_ids if the entry is a tool request.- Supports both OpenAI and Anthropics formats.+ Supports OpenAI Chat Completions, Responses API, and Anthropic formats."""tool_call_ids = []++ # OpenAI Responses API: function_call items have type="function_call"+ if entry.get("type") == "function_call":+ if call_id := entry.get("call_id"):+ tool_call_ids.append(call_id)+ return tool_call_ids+if entry.get("role") != "assistant":return tool_call_ids- # OpenAI: check for tool_calls in the entry.+ # OpenAI Chat Completions: check for tool_calls in the entry.calls = entry.get("tool_calls")if isinstance(calls, list):for call in calls:if tool_id := call.get("id"):tool_call_ids.append(tool_id)- # Anthropics: check content items for tool_use type.+ # Anthropic: check content items for tool_use type.content = entry.get("content")if isinstance(content, list):for item in content:@@ -89,16 +96,22 @@ def _get_tool_requests(entry: dict[str, Any]) -> list[str]:def _get_tool_responses(entry: dict[str, Any]) -> list[str]:"""Return a list of tool_call_ids if the entry is a tool response.- Supports both OpenAI and Anthropics formats.+ Supports OpenAI Chat Completions, Responses API, and Anthropic formats."""tool_call_ids: list[str] = []- # OpenAI: a tool response message with role "tool" and key "tool_call_id".+ # OpenAI Responses API: function_call_output items+ if entry.get("type") == "function_call_output":+ if call_id := entry.get("call_id"):+ tool_call_ids.append(str(call_id))+ return tool_call_ids++ # OpenAI Chat Completions: a tool response message with role "tool".if entry.get("role") == "tool":if tool_call_id := entry.get("tool_call_id"):tool_call_ids.append(str(tool_call_id))- # Anthropics: check content items for tool_result type.+ # Anthropic: check content items for tool_result type.if entry.get("role") == "user":content = entry.get("content")if isinstance(content, list):@@ -111,14 +124,16 @@ def _get_tool_responses(entry: dict[str, Any]) -> list[str]:return tool_call_ids-def _create_tool_response(call_id: str, output: Any) -> dict[str, Any]:+def _create_tool_response(+ call_id: str, output: Any, *, responses_api: bool = False+) -> dict[str, Any]:"""- Create a tool response message for either OpenAI or Anthropics,- based on the tool_id format.+ Create a tool response message for OpenAI, Anthropic, or OpenAI Responses API,+ based on the tool_id format and the responses_api flag."""content = output if isinstance(output, str) else json.dumps(output)- # Anthropics format: tool IDs typically start with "toolu_"+ # Anthropic format: tool IDs typically start with "toolu_"if call_id.startswith("toolu_"):return {"role": "user",@@ -128,8 +143,11 @@ def _create_tool_response(call_id: str, output: Any) -> dict[str, Any]:],}- # OpenAI format: tool IDs typically start with "call_".- # Or default fallback (if the tool_id doesn't match any known prefix)+ # OpenAI Responses API format+ if responses_api:+ return {"type": "function_call_output", "call_id": call_id, "output": content}++ # OpenAI Chat Completions format (default fallback)return {"role": "tool", "tool_call_id": call_id, "content": content}@@ -177,10 +195,19 @@ def _combine_tool_responses(tool_outputs: list[dict[str, Any]]) -> list[dict[strreturn tool_outputs-def _convert_raw_response_to_dict(raw_response: Any) -> dict[str, Any]:+def _convert_raw_response_to_dict(+ raw_response: Any,+) -> dict[str, Any] | list[dict[str, Any]]:"""Safely convert raw_response to dictionary format for conversation history.Handles different response types from different LLM providers.++ For the OpenAI Responses API, the raw_response is the entire Response+ object. Its ``output`` items (messages, function_calls) are extracted+ individually so they can be used as valid input items on the next call.+ Returns a **list** of dicts in that case.++ For Chat Completions / Anthropic / Ollama, returns a single dict."""if isinstance(raw_response, str):# Ollama returns a string, convert to dict format@@ -188,11 +215,28 @@ def _convert_raw_response_to_dict(raw_response: Any) -> dict[str, Any]:elif isinstance(raw_response, dict):# Already a dict (from tests or some providers)return raw_response+ elif _is_responses_api_object(raw_response):+ # OpenAI Responses API: extract individual output items+ items = [json.to_dict(item) for item in raw_response.output]+ return items if items else [{"role": "assistant", "content": ""}]else:- # OpenAI/Anthropic return objects, convert with json.to_dict+ # Chat Completions / Anthropic return message objectsreturn json.to_dict(raw_response)+def _is_responses_api_object(obj: Any) -> bool:+ """Detect an OpenAI Responses API Response object.++ These have ``object == "response"`` and an ``output`` list, but no+ ``role`` attribute (unlike ChatCompletionMessage).+ """+ return (+ getattr(obj, "object", None) == "response"+ and hasattr(obj, "output")+ and not hasattr(obj, "role")+ )++def get_pending_tool_calls(conversation_history: list[Any] | None) -> dict[str, int]:"""All the tool calls entry in the conversation history requires a response.@@ -754,19 +798,34 @@ class SmartDecisionMakerBlock(Block):self, prompt: list[dict], response, tool_outputs: list | None = None):"""Update conversation history with response and tool outputs."""- # Don't add separate reasoning message with tool calls (breaks Anthropic's tool_use->tool_result pairing)- assistant_message = _convert_raw_response_to_dict(response.raw_response)- has_tool_calls = isinstance(assistant_message.get("content"), list) and any(- item.get("type") == "tool_use"- for item in assistant_message.get("content", [])- )+ converted = _convert_raw_response_to_dict(response.raw_response)- if response.reasoning and not has_tool_calls:- prompt.append(- {"role": "assistant", "content": f"[Reasoning]: {response.reasoning}"}+ if isinstance(converted, list):+ # Responses API: output items are already individual dicts+ has_tool_calls = any(+ item.get("type") == "function_call" for item in converted)-- prompt.append(assistant_message)+ if response.reasoning and not has_tool_calls:+ prompt.append(+ {+ "role": "assistant",+ "content": f"[Reasoning]: {response.reasoning}",+ }+ )+ prompt.extend(converted)+ else:+ # Chat Completions / Anthropic: single assistant message dict+ has_tool_calls = isinstance(converted.get("content"), list) and any(+ item.get("type") == "tool_use" for item in converted.get("content", [])+ )+ if response.reasoning and not has_tool_calls:+ prompt.append(+ {+ "role": "assistant",+ "content": f"[Reasoning]: {response.reasoning}",+ }+ )+ prompt.append(converted)if tool_outputs:prompt.extend(tool_outputs)@@ -776,6 +835,8 @@ class SmartDecisionMakerBlock(Block):tool_info: ToolInfo,execution_params: ExecutionParams,execution_processor: "ExecutionProcessor",+ *,+ responses_api: bool = False,) -> dict:"""Execute a single tool using the execution manager for proper integration."""# Lazy imports to avoid circular dependencies@@ -868,13 +929,17 @@ class SmartDecisionMakerBlock(Block):if node_outputselse "Tool executed successfully")- return _create_tool_response(tool_call.id, tool_response_content)+ return _create_tool_response(+ tool_call.id, tool_response_content, responses_api=responses_api+ )except Exception as e:logger.error(f"Tool execution with manager failed: {e}")# Return error responsereturn _create_tool_response(- tool_call.id, f"Tool execution failed: {str(e)}"+ tool_call.id,+ f"Tool execution failed: {str(e)}",+ responses_api=responses_api,)async def _execute_tools_agent_mode(@@ -895,6 +960,7 @@ class SmartDecisionMakerBlock(Block):"""Execute tools in agent mode with a loop until finished."""max_iterations = input_data.agent_mode_max_iterationsiteration = 0+ use_responses_api = input_data.model.metadata.provider == "openai"# Execution parameters for tool executionexecution_params = ExecutionParams(@@ -951,14 +1017,19 @@ class SmartDecisionMakerBlock(Block):for tool_info in processed_tools:try:tool_response = await self._execute_single_tool_with_manager(- tool_info, execution_params, execution_processor+ tool_info,+ execution_params,+ execution_processor,+ responses_api=use_responses_api,)tool_outputs.append(tool_response)except Exception as e:logger.error(f"Tool execution failed: {e}")# Create error response for the toolerror_response = _create_tool_response(- tool_info.tool_call.id, f"Error: {str(e)}"+ tool_info.tool_call.id,+ f"Error: {str(e)}",+ responses_api=use_responses_api,)tool_outputs.append(error_response)@@ -1020,11 +1091,17 @@ class SmartDecisionMakerBlock(Block):if pending_tool_calls and input_data.last_tool_output is None:raise ValueError(f"Tool call requires an output for {pending_tool_calls}")+ use_responses_api = input_data.model.metadata.provider == "openai"+tool_output = []if pending_tool_calls and input_data.last_tool_output is not None:first_call_id = next(iter(pending_tool_calls.keys()))tool_output.append(- _create_tool_response(first_call_id, input_data.last_tool_output)+ _create_tool_response(+ first_call_id,+ input_data.last_tool_output,+ responses_api=use_responses_api,+ ))prompt.extend(tool_output)@@ -1056,7 +1133,9 @@ class SmartDecisionMakerBlock(Block):)if input_data.sys_prompt and not any(- p["role"] == "system" and p["content"].startswith(MAIN_OBJECTIVE_PREFIX)+ p.get("role") == "system"+ and isinstance(p.get("content"), str)+ and p["content"].startswith(MAIN_OBJECTIVE_PREFIX)for p in prompt):prompt.append(@@ -1067,7 +1146,9 @@ class SmartDecisionMakerBlock(Block):)if input_data.prompt and not any(- p["role"] == "user" and p["content"].startswith(MAIN_OBJECTIVE_PREFIX)+ p.get("role") == "user"+ and isinstance(p.get("content"), str)+ and p["content"].startswith(MAIN_OBJECTIVE_PREFIX)for p in prompt):prompt.append(@@ -1175,11 +1256,26 @@ class SmartDecisionMakerBlock(Block):)yield emit_key, arg_value- if response.reasoning:+ converted = _convert_raw_response_to_dict(response.raw_response)++ # Check for tool calls to avoid inserting reasoning between tool pairs+ if isinstance(converted, list):+ has_tool_calls = any(+ item.get("type") == "function_call" for item in converted+ )+ else:+ has_tool_calls = isinstance(converted.get("content"), list) and any(+ item.get("type") == "tool_use" for item in converted.get("content", [])+ )++ if response.reasoning and not has_tool_calls:prompt.append({"role": "assistant", "content": f"[Reasoning]: {response.reasoning}"})- prompt.append(_convert_raw_response_to_dict(response.raw_response))+ if isinstance(converted, list):+ prompt.extend(converted)+ else:+ prompt.append(converted)yield "conversations", promptdiff --git a/autogpt_platform/backend/backend/blocks/test/test_llm.py b/autogpt_platform/backend/backend/blocks/test/test_llm.pyindex ea8760d313..ddd21e6a6e 100644--- a/autogpt_platform/backend/backend/blocks/test/test_llm.py+++ b/autogpt_platform/backend/backend/blocks/test/test_llm.py@@ -13,18 +13,17 @@ class TestLLMStatsTracking:"""Test that llm_call returns proper token counts in LLMResponse."""import backend.blocks.llm as llm- # Mock the OpenAI client+ # Mock the OpenAI Responses API responsemock_response = MagicMock()- mock_response.choices = [- MagicMock(message=MagicMock(content="Test response", tool_calls=None))- ]- mock_response.usage = MagicMock(prompt_tokens=10, completion_tokens=20)+ mock_response.output_text = "Test response"+ mock_response.output = []+ mock_response.usage = MagicMock(input_tokens=10, output_tokens=20)# Test with mocked OpenAI responsewith patch("openai.AsyncOpenAI") as mock_openai:mock_client = AsyncMock()mock_openai.return_value = mock_client- mock_client.chat.completions.create = AsyncMock(return_value=mock_response)+ mock_client.responses.create = AsyncMock(return_value=mock_response)response = await llm.llm_call(credentials=llm.TEST_CREDENTIALS,@@ -271,30 +270,17 @@ class TestLLMStatsTracking:mock_response = MagicMock()# Return different responses for chunk summary vs final summaryif call_count == 1:- mock_response.choices = [- MagicMock(- message=MagicMock(- content='<json_output id="test123456">{"summary": "Test chunk summary"}</json_output>',- tool_calls=None,- )- )- ]+ mock_response.output_text = '<json_output id="test123456">{"summary": "Test chunk summary"}</json_output>'else:- mock_response.choices = [- MagicMock(- message=MagicMock(- content='<json_output id="test123456">{"final_summary": "Test final summary"}</json_output>',- tool_calls=None,- )- )- ]- mock_response.usage = MagicMock(prompt_tokens=50, completion_tokens=30)+ mock_response.output_text = '<json_output id="test123456">{"final_summary": "Test final summary"}</json_output>'+ mock_response.output = []+ mock_response.usage = MagicMock(input_tokens=50, output_tokens=30)return mock_responsewith patch("openai.AsyncOpenAI") as mock_openai:mock_client = AsyncMock()mock_openai.return_value = mock_client- mock_client.chat.completions.create = mock_create+ mock_client.responses.create = mock_create# Test with very short text (should only need 1 chunk + 1 final summary)input_data = llm.AITextSummarizerBlock.Input(diff --git a/autogpt_platform/backend/backend/blocks/test/test_smart_decision_maker_responses_api.py b/autogpt_platform/backend/backend/blocks/test/test_smart_decision_maker_responses_api.pynew file mode 100644index 0000000000..ffd3f45496--- /dev/null+++ b/autogpt_platform/backend/backend/blocks/test/test_smart_decision_maker_responses_api.py@@ -0,0 +1,1063 @@+"""Tests for SmartDecisionMakerBlock compatibility with the OpenAI Responses API.++The SmartDecisionMakerBlock manages conversation history in the Chat Completions+format, but OpenAI models now use the Responses API which has a fundamentally+different conversation structure. These tests document:++ - Every branch of the affected helper functions+ - Which branches PASS (existing Chat Completions / Anthropic paths)+ - Which branches FAIL (Responses API paths) — marked ``xfail``++Bug report: When using gpt-5.2 (or any model via ``client.responses.create``),+the agent-mode loop fails on the second LLM call with::++ Error code: 400 - Invalid value: ''.+ Supported values are: 'assistant', 'system', 'developer', and 'user'.++Root cause: ``raw_response`` is the entire ``Response`` object. Serialising it+produces a dict with no ``role`` field. Tool results are also formatted as+``{"role": "tool", …}`` (Chat Completions) instead of+``{"type": "function_call_output", …}`` (Responses API).+"""++import threading+from collections import defaultdict+from typing import Any+from unittest.mock import AsyncMock, MagicMock, patch++import pytest++from backend.blocks.smart_decision_maker import (+ SmartDecisionMakerBlock,+ _combine_tool_responses,+ _convert_raw_response_to_dict,+ _create_tool_response,+ _get_tool_requests,+ _get_tool_responses,+ get_pending_tool_calls,+)+from backend.data.execution import ExecutionContext++# ───────────────────────────────────────────────────────────────────────────+# Mock objects that mirror the OpenAI Responses API SDK types+# ───────────────────────────────────────────────────────────────────────────+++class _MockOutputText:+ """openai.types.responses.ResponseOutputText"""++ def __init__(self, text: str):+ self.type = "output_text"+ self.text = text+ self.annotations: list = []+ self.logprobs = None+++class _MockOutputMessage:+ """openai.types.responses.ResponseOutputMessage"""++ def __init__(self, text: str, msg_id: str = "msg_abc123"):+ self.type = "message"+ self.id = msg_id+ self.role = "assistant"+ self.status = "completed"+ self.content = [_MockOutputText(text)]+++class _MockFunctionCall:+ """openai.types.responses.ResponseFunctionToolCall"""++ def __init__(+ self,+ name: str,+ arguments: str,+ call_id: str = "call_abc123",+ fc_id: str = "fc_abc123",+ ):+ self.type = "function_call"+ self.id = fc_id+ self.call_id = call_id+ self.name = name+ self.arguments = arguments+ self.status = "completed"+++class _MockUsage:+ def __init__(self, inp: int = 100, out: int = 50):+ self.input_tokens = inp+ self.output_tokens = out+++class _MockResponse:+ """openai.types.responses.Response — top-level object returned by+ ``client.responses.create()``. Stored as ``raw_response`` on the+ LLMResponse (llm.py line 848).+ """++ def __init__(self, output: list, resp_id: str = "resp_abc123"):+ self.id = resp_id+ self.object = "response"+ self.model = "gpt-5.2-2025-12-11"+ self.output = output+ self.usage = _MockUsage()+ self.user = None+ self.error = None+ self.status = "completed"+ self.store = False+ self.metadata: dict[str, Any] = {}+ self.output_text = self._text()++ def _text(self) -> str:+ for item in self.output:+ if getattr(item, "type", None) == "message":+ for c in item.content:+ if getattr(c, "type", None) == "output_text":+ return c.text+ return ""+++# ───────────────────────────────────────────────────────────────────────────+# _convert_raw_response_to_dict (lines 180-193)+# Branches: str → dict wrapper | dict → pass-through | else → to_dict+# ───────────────────────────────────────────────────────────────────────────+++class TestConvertRawResponseToDict:+ # -- passing branches --------------------------------------------------++ def test_string_input_wraps_as_assistant(self):+ """Branch 1 (str): Ollama returns a plain string."""+ result = _convert_raw_response_to_dict("hello")+ assert result == {"role": "assistant", "content": "hello"}++ def test_dict_input_passes_through(self):+ """Branch 2 (dict): Already a dict — returned as-is."""+ d = {"role": "assistant", "content": "hi", "extra": 42}+ result = _convert_raw_response_to_dict(d)+ assert result is d++ def test_chat_completion_message_object(self):+ """Branch 3 (else): A ChatCompletionMessage-like object with .role.++ Uses a Pydantic BaseModel to match how the OpenAI SDK structures+ ChatCompletionMessage objects (jsonable_encoder handles Pydantic).+ """+ from pydantic import BaseModel++ class _Msg(BaseModel):+ role: str = "assistant"+ content: str | None = "text"+ tool_calls: list | None = None++ result = _convert_raw_response_to_dict(_Msg())+ assert isinstance(result, dict)+ assert result.get("role") == "assistant"++ # -- failing branches (Responses API) -----------------------------------++ def test_responses_api_text_response_has_role(self):+ """Branch 3 (else): A Responses API Response with a text message.++ The serialised dict must have ``role`` so it can be used as a+ conversation input item. Currently it does NOT.+ """+ resp = _MockResponse(output=[_MockOutputMessage("Hello!")])+ result = _convert_raw_response_to_dict(resp)++ # After the fix, the result should either:+ # - be a list of output items each with valid role/type, OR+ # - be a single dict with role="assistant"+ if isinstance(result, list):+ for item in result:+ assert item.get("role") or item.get("type")+ else:+ assert result.get("role") == "assistant"++ def test_responses_api_function_call_has_valid_type(self):+ """Branch 3 (else): A Responses API Response with a function_call.++ The serialised output must produce items with ``type: function_call``+ that the Responses API accepts as input.+ """+ resp = _MockResponse(+ output=[_MockFunctionCall("my_tool", '{"x": 1}', call_id="call_xyz")]+ )+ result = _convert_raw_response_to_dict(resp)++ if isinstance(result, list):+ fc_items = [i for i in result if i.get("type") == "function_call"]+ assert len(fc_items) == 1+ assert fc_items[0]["call_id"] == "call_xyz"+ else:+ # If it remains a single dict it must at least be a valid input item+ assert (+ result.get("type") == "function_call"+ or result.get("role") == "assistant"+ )++ def test_responses_api_mixed_output_items(self):+ """Branch 3 (else): Response with both a message and a function_call."""+ resp = _MockResponse(+ output=[+ _MockOutputMessage("Thinking…"),+ _MockFunctionCall("tool_a", "{}", call_id="call_111"),+ ]+ )+ result = _convert_raw_response_to_dict(resp)++ if isinstance(result, list):+ assert len(result) == 2+ else:+ # A single dict is wrong — there are two distinct items+ pytest.fail("Expected a list of output items, got a single dict")+++# ───────────────────────────────────────────────────────────────────────────+# _get_tool_requests (lines 61-86)+# Branches:+# role != assistant → early return+# tool_calls is list → iterate → id present / absent+# content is list → iterate → type==tool_use / not → id present / absent+# ───────────────────────────────────────────────────────────────────────────+++class TestGetToolRequests:+ # -- passing branches (Chat Completions) --------------------------------++ def test_openai_chat_completions_with_tool_calls(self):+ """role=assistant + tool_calls list → extracts IDs."""+ entry = {+ "role": "assistant",+ "content": None,+ "tool_calls": [+ {"id": "call_1", "type": "function"},+ {"id": "call_2", "type": "function"},+ ],+ }+ assert _get_tool_requests(entry) == ["call_1", "call_2"]++ def test_openai_chat_completions_tool_call_missing_id(self):+ """tool_call entry without 'id' → skipped."""+ entry = {+ "role": "assistant",+ "tool_calls": [{"type": "function"}], # no id+ }+ assert _get_tool_requests(entry) == []++ def test_assistant_no_tool_calls_no_content(self):+ """role=assistant with neither tool_calls nor content list → empty."""+ entry = {"role": "assistant", "content": "Just text"}+ assert _get_tool_requests(entry) == []++ def test_tool_calls_not_a_list(self):+ """tool_calls is not a list (edge case) → skipped."""+ entry = {"role": "assistant", "tool_calls": "not a list"}+ assert _get_tool_requests(entry) == []++ # -- passing branches (Anthropic) ---------------------------------------++ def test_anthropic_tool_use_items(self):+ """role=assistant + content with tool_use items → extracts IDs."""+ entry = {+ "role": "assistant",+ "content": [+ {"type": "tool_use", "id": "toolu_a"},+ {"type": "tool_use", "id": "toolu_b"},+ ],+ }+ assert _get_tool_requests(entry) == ["toolu_a", "toolu_b"]++ def test_anthropic_tool_use_missing_id(self):+ """tool_use item without 'id' → skipped."""+ entry = {+ "role": "assistant",+ "content": [{"type": "tool_use"}],+ }+ assert _get_tool_requests(entry) == []++ def test_content_list_with_non_tool_use_items(self):+ """Content list items that are not tool_use → skipped."""+ entry = {+ "role": "assistant",+ "content": [{"type": "text", "text": "hi"}],+ }+ assert _get_tool_requests(entry) == []++ def test_content_not_a_list(self):+ """Content is a string (not a list) → skipped."""+ entry = {"role": "assistant", "content": "plain string"}+ assert _get_tool_requests(entry) == []++ def test_non_assistant_role_returns_empty(self):+ """role != assistant → immediate empty return."""+ entry = {"role": "user", "content": "hello"}+ assert _get_tool_requests(entry) == []++ def test_no_role_returns_empty(self):+ """No role key at all → immediate empty return."""+ entry = {"content": "orphan"}+ assert _get_tool_requests(entry) == []++ # -- failing branches (Responses API) -----------------------------------++ def test_responses_api_function_call_detected(self):+ """type=function_call with call_id → should return [call_id]."""+ entry = {+ "type": "function_call",+ "id": "fc_abc",+ "call_id": "call_abc",+ "name": "my_tool",+ "arguments": '{"x": 1}',+ "status": "completed",+ }+ assert _get_tool_requests(entry) == ["call_abc"]++ def test_responses_api_function_call_missing_call_id(self):+ """type=function_call WITHOUT call_id → should return [].++ This currently returns [] because the item is ignored entirely+ (no role=assistant). After the fix it should STILL return []+ because there is no call_id to extract.+ """+ entry = {+ "type": "function_call",+ "id": "fc_abc",+ "name": "my_tool",+ # no call_id+ }+ assert _get_tool_requests(entry) == []+++# ───────────────────────────────────────────────────────────────────────────+# _get_tool_responses (lines 89-111)+# Branches:+# role=tool → tool_call_id present / absent+# role=user → content is list → type==tool_result / not → tool_use_id present / absent+# neither → empty+# ───────────────────────────────────────────────────────────────────────────+++class TestGetToolResponses:+ # -- passing branches (Chat Completions) --------------------------------++ def test_openai_tool_response(self):+ """role=tool + tool_call_id → returns [id]."""+ entry = {"role": "tool", "tool_call_id": "call_abc", "content": "result"}+ assert _get_tool_responses(entry) == ["call_abc"]++ def test_openai_tool_response_missing_id(self):+ """role=tool but no tool_call_id → empty."""+ entry = {"role": "tool", "content": "result"}+ assert _get_tool_responses(entry) == []++ # -- passing branches (Anthropic) ---------------------------------------++ def test_anthropic_tool_result(self):+ """role=user + content with tool_result → returns [tool_use_id]."""+ entry = {+ "role": "user",+ "type": "message",+ "content": [+ {"type": "tool_result", "tool_use_id": "toolu_abc", "content": "ok"}+ ],+ }+ assert _get_tool_responses(entry) == ["toolu_abc"]++ def test_anthropic_tool_result_missing_use_id(self):+ """tool_result item without tool_use_id → skipped."""+ entry = {+ "role": "user",+ "content": [{"type": "tool_result", "content": "ok"}],+ }+ assert _get_tool_responses(entry) == []++ def test_anthropic_content_non_tool_result(self):+ """Content items that are not tool_result → skipped."""+ entry = {+ "role": "user",+ "content": [{"type": "text", "text": "hi"}],+ }+ assert _get_tool_responses(entry) == []++ def test_user_role_content_not_list(self):+ """role=user but content is a string (not list) → empty."""+ entry = {"role": "user", "content": "just text"}+ assert _get_tool_responses(entry) == []++ def test_other_role_returns_empty(self):+ """role=assistant (neither tool nor user) → empty."""+ entry = {"role": "assistant", "content": "response"}+ assert _get_tool_responses(entry) == []++ def test_no_role_returns_empty(self):+ """No role at all → empty."""+ entry = {"content": "orphan"}+ assert _get_tool_responses(entry) == []++ # -- failing branches (Responses API) -----------------------------------++ def test_responses_api_function_call_output_detected(self):+ """type=function_call_output + call_id → should return [call_id]."""+ entry = {+ "type": "function_call_output",+ "call_id": "call_abc",+ "output": '{"result": "done"}',+ }+ assert _get_tool_responses(entry) == ["call_abc"]++ def test_responses_api_function_call_output_missing_call_id(self):+ """type=function_call_output WITHOUT call_id → should return [].++ Currently returns [] because the item is ignored entirely+ (no role=tool or role=user). After the fix it should STILL+ return [] because there is no call_id to extract.+ """+ entry = {+ "type": "function_call_output",+ "output": "result",+ }+ assert _get_tool_responses(entry) == []+++# ───────────────────────────────────────────────────────────────────────────+# _create_tool_response (lines 114-133)+# Branches: toolu_ prefix → Anthropic | else → Chat Completions+# ───────────────────────────────────────────────────────────────────────────+++class TestCreateToolResponse:+ # -- passing branches ---------------------------------------------------++ def test_anthropic_format(self):+ """call_id starting with 'toolu_' → Anthropic format."""+ result = _create_tool_response("toolu_abc", "ok")+ assert result["role"] == "user"+ assert result["type"] == "message"+ assert result["content"][0]["type"] == "tool_result"+ assert result["content"][0]["tool_use_id"] == "toolu_abc"+ assert result["content"][0]["content"] == "ok"++ def test_openai_chat_completions_format(self):+ """call_id starting with 'call_' → Chat Completions format.++ This works correctly for Chat Completions models but is WRONG for+ the Responses API. The test documents the current behaviour.+ """+ result = _create_tool_response("call_abc", "result text")+ assert result == {+ "role": "tool",+ "tool_call_id": "call_abc",+ "content": "result text",+ }++ def test_non_string_output_is_json_dumped(self):+ """Non-string output is serialised to JSON (compact, via orjson)."""+ result = _create_tool_response("call_abc", {"key": "val"})+ assert result["content"] == '{"key":"val"}'++ def test_dict_output_anthropic(self):+ """Non-string output with Anthropic prefix is also JSON-dumped."""+ result = _create_tool_response("toolu_abc", [1, 2, 3])+ assert result["content"][0]["content"] == "[1,2,3]"++ # -- failing branches (Responses API) -----------------------------------++ def test_responses_api_format_with_flag(self):+ """With responses_api=True, produces Responses API format."""+ result = _create_tool_response("call_abc", "result", responses_api=True)+ assert result == {+ "type": "function_call_output",+ "call_id": "call_abc",+ "output": "result",+ }++ def test_responses_api_flag_ignored_for_anthropic(self):+ """Anthropic prefix takes priority over responses_api flag."""+ result = _create_tool_response("toolu_abc", "result", responses_api=True)+ assert result["role"] == "user"+ assert result["content"][0]["type"] == "tool_result"+++# ───────────────────────────────────────────────────────────────────────────+# _combine_tool_responses (lines 136-177)+# Branches:+# len <= 1 → return as-is+# > 1 Anthropic responses → combine+# <= 1 Anthropic response → return original list+# mixed Anthropic + non-Anthropic → combine Anthropic, keep others+# ───────────────────────────────────────────────────────────────────────────+++class TestCombineToolResponses:+ def test_empty_list(self):+ assert _combine_tool_responses([]) == []++ def test_single_item(self):+ item = {"role": "tool", "tool_call_id": "call_1", "content": "r"}+ assert _combine_tool_responses([item]) == [item]++ def test_multiple_non_anthropic(self):+ """Multiple non-Anthropic items → returned unchanged."""+ items = [+ {"role": "tool", "tool_call_id": "call_1", "content": "a"},+ {"role": "tool", "tool_call_id": "call_2", "content": "b"},+ ]+ assert _combine_tool_responses(items) == items++ def test_single_anthropic_among_multiple(self):+ """Only 1 Anthropic response among >1 total → returned unchanged."""+ items = [+ {+ "role": "user",+ "type": "message",+ "content": [+ {"type": "tool_result", "tool_use_id": "toolu_1", "content": "a"}+ ],+ },+ {"role": "tool", "tool_call_id": "call_2", "content": "b"},+ ]+ result = _combine_tool_responses(items)+ assert result == items # No combining when only 1 Anthropic++ def test_multiple_anthropic_responses_combined(self):+ """Multiple Anthropic responses → combined into one user message."""+ items = [+ {+ "role": "user",+ "type": "message",+ "content": [+ {"type": "tool_result", "tool_use_id": "toolu_1", "content": "a"}+ ],+ },+ {+ "role": "user",+ "type": "message",+ "content": [+ {"type": "tool_result", "tool_use_id": "toolu_2", "content": "b"}+ ],+ },+ ]+ result = _combine_tool_responses(items)+ assert len(result) == 1+ assert result[0]["role"] == "user"+ assert len(result[0]["content"]) == 2++ def test_mixed_anthropic_and_non_anthropic(self):+ """Multiple Anthropic + non-Anthropic → Anthropic combined, others kept."""+ items = [+ {+ "role": "user",+ "type": "message",+ "content": [+ {"type": "tool_result", "tool_use_id": "toolu_1", "content": "a"}+ ],+ },+ {+ "role": "user",+ "type": "message",+ "content": [+ {"type": "tool_result", "tool_use_id": "toolu_2", "content": "b"}+ ],+ },+ {"role": "tool", "tool_call_id": "call_3", "content": "c"},+ ]+ result = _combine_tool_responses(items)+ assert len(result) == 2 # 1 combined Anthropic + 1 non-Anthropic+ assert result[0]["role"] == "user"+ assert len(result[0]["content"]) == 2+ assert result[1]["role"] == "tool"++ def test_anthropic_content_not_list_not_combined(self):+ """Anthropic-like item with non-list content → not detected as Anthropic."""+ items = [+ {"role": "user", "type": "message", "content": "not a list"},+ {"role": "user", "type": "message", "content": "also not a list"},+ ]+ assert _combine_tool_responses(items) == items++ def test_anthropic_content_no_tool_result_not_combined(self):+ """Anthropic-like item with list content but no tool_result → not combined."""+ items = [+ {+ "role": "user",+ "type": "message",+ "content": [{"type": "text", "text": "hi"}],+ },+ {+ "role": "user",+ "type": "message",+ "content": [{"type": "text", "text": "bye"}],+ },+ ]+ assert _combine_tool_responses(items) == items+++# ───────────────────────────────────────────────────────────────────────────+# get_pending_tool_calls (lines 196-214)+# Branches: empty/None → {} | has history → count requests - responses+# ───────────────────────────────────────────────────────────────────────────+++class TestGetPendingToolCalls:+ def test_none_history(self):+ assert get_pending_tool_calls(None) == {}++ def test_empty_history(self):+ assert get_pending_tool_calls([]) == {}++ def test_chat_completions_pending(self):+ """Chat Completions: request without response → pending."""+ history = [+ {+ "role": "assistant",+ "tool_calls": [{"id": "call_1", "type": "function"}],+ },+ ]+ assert get_pending_tool_calls(history) == {"call_1": 1}++ def test_chat_completions_resolved(self):+ """Chat Completions: request + response → resolved (not pending)."""+ history = [+ {+ "role": "assistant",+ "tool_calls": [{"id": "call_1", "type": "function"}],+ },+ {"role": "tool", "tool_call_id": "call_1", "content": "done"},+ ]+ assert get_pending_tool_calls(history) == {}++ def test_anthropic_pending(self):+ """Anthropic: request without response → pending."""+ history = [+ {+ "role": "assistant",+ "content": [{"type": "tool_use", "id": "toolu_1"}],+ },+ ]+ assert get_pending_tool_calls(history) == {"toolu_1": 1}++ def test_anthropic_resolved(self):+ """Anthropic: request + response → resolved."""+ history = [+ {+ "role": "assistant",+ "content": [{"type": "tool_use", "id": "toolu_1"}],+ },+ {+ "role": "user",+ "content": [+ {"type": "tool_result", "tool_use_id": "toolu_1", "content": "ok"}+ ],+ },+ ]+ assert get_pending_tool_calls(history) == {}++ def test_responses_api_function_call_tracked_as_pending(self):+ """Responses API function_call → should be tracked as pending."""+ history = [+ {"role": "user", "content": "Do something."},+ {+ "type": "function_call",+ "id": "fc_abc",+ "call_id": "call_abc",+ "name": "tool",+ "arguments": "{}",+ },+ ]+ assert get_pending_tool_calls(history) == {"call_abc": 1}++ def test_responses_api_both_invisible_gives_false_resolved(self):+ """Both function_call and function_call_output are invisible to+ the current code, so get_pending_tool_calls returns {} — but for+ the WRONG reason (neither is tracked, not because they cancel out).++ This test documents that limitation: the result is {} but only+ because the function ignores both items entirely.+ """+ history = [+ {+ "type": "function_call",+ "id": "fc_abc",+ "call_id": "call_abc",+ "name": "tool",+ "arguments": "{}",+ },+ {+ "type": "function_call_output",+ "call_id": "call_abc",+ "output": "done",+ },+ ]+ # Returns {} — correct result but for the wrong reason+ assert get_pending_tool_calls(history) == {}++ def test_responses_api_unresolved_call_detected(self):+ """A function_call WITHOUT a matching function_call_output should+ show up as pending. Currently it does NOT because function_call+ items are invisible.+ """+ history = [+ {"role": "user", "content": "Do something."},+ {+ "type": "function_call",+ "id": "fc_abc",+ "call_id": "call_abc",+ "name": "tool",+ "arguments": "{}",+ },+ # No function_call_output → should be pending+ ]+ pending = get_pending_tool_calls(history)+ assert "call_abc" in pending+++# ───────────────────────────────────────────────────────────────────────────+# _update_conversation (lines 753-772)+# Branches:+# reasoning + no tool calls → append reasoning+# reasoning + tool calls → skip reasoning+# no reasoning → skip+# tool_outputs → extend prompt+# no tool_outputs → skip extend+# ───────────────────────────────────────────────────────────────────────────+++class TestUpdateConversation:+ def _make_response(self, raw, reasoning=None):+ r = MagicMock()+ r.raw_response = raw+ r.reasoning = reasoning+ return r++ # -- passing branches ---------------------------------------------------++ def test_dict_raw_response_no_reasoning_no_tools(self):+ """Dict raw_response, no reasoning → appends assistant dict."""+ block = SmartDecisionMakerBlock()+ prompt: list[dict] = []+ resp = self._make_response({"role": "assistant", "content": "hi"})+ block._update_conversation(prompt, resp)+ assert prompt == [{"role": "assistant", "content": "hi"}]++ def test_dict_raw_response_with_reasoning_no_tool_calls(self):+ """Reasoning present, no tool calls → reasoning prepended."""+ block = SmartDecisionMakerBlock()+ prompt: list[dict] = []+ resp = self._make_response(+ {"role": "assistant", "content": "answer"},+ reasoning="Let me think…",+ )+ block._update_conversation(prompt, resp)+ assert len(prompt) == 2+ assert prompt[0] == {+ "role": "assistant",+ "content": "[Reasoning]: Let me think…",+ }+ assert prompt[1] == {"role": "assistant", "content": "answer"}++ def test_dict_raw_response_with_reasoning_and_anthropic_tool_calls(self):+ """Reasoning + Anthropic tool_use in content → reasoning skipped."""+ block = SmartDecisionMakerBlock()+ prompt: list[dict] = []+ raw = {+ "role": "assistant",+ "content": [+ {"type": "tool_use", "id": "toolu_1", "name": "t", "input": {}}+ ],+ }+ resp = self._make_response(raw, reasoning="Thinking…")+ block._update_conversation(prompt, resp)+ assert len(prompt) == 1+ assert prompt[0] is raw++ def test_with_tool_outputs(self):+ """Tool outputs → extended onto prompt."""+ block = SmartDecisionMakerBlock()+ prompt: list[dict] = []+ resp = self._make_response({"role": "assistant", "content": None})+ outputs = [{"role": "tool", "tool_call_id": "call_1", "content": "r"}]+ block._update_conversation(prompt, resp, outputs)+ assert len(prompt) == 2+ assert prompt[1] == outputs[0]++ def test_without_tool_outputs(self):+ """No tool outputs → only assistant message appended."""+ block = SmartDecisionMakerBlock()+ prompt: list[dict] = []+ resp = self._make_response({"role": "assistant", "content": "done"})+ block._update_conversation(prompt, resp, None)+ assert len(prompt) == 1++ def test_string_raw_response(self):+ """Ollama string → wrapped as assistant dict."""+ block = SmartDecisionMakerBlock()+ prompt: list[dict] = []+ resp = self._make_response("hello from ollama")+ block._update_conversation(prompt, resp)+ assert prompt == [{"role": "assistant", "content": "hello from ollama"}]++ # -- failing branches (Responses API) -----------------------------------++ def test_responses_api_text_response_produces_valid_items(self):+ """Responses API text response → conversation items must have valid role."""+ block = SmartDecisionMakerBlock()+ prompt: list[dict] = [+ {"role": "system", "content": "sys"},+ {"role": "user", "content": "user"},+ ]+ resp = self._make_response(_MockResponse(output=[_MockOutputMessage("Answer")]))+ block._update_conversation(prompt, resp)++ # Every item in the prompt must be a valid API input+ for item in prompt:+ has_role = item.get("role") in ("assistant", "system", "user", "developer")+ has_type = item.get("type") in (+ "function_call",+ "function_call_output",+ "message",+ )+ assert has_role or has_type, f"Invalid conversation item: {item}"++ def test_responses_api_function_call_produces_valid_items(self):+ """Responses API function_call → conversation items must have valid type."""+ block = SmartDecisionMakerBlock()+ prompt: list[dict] = []+ resp = self._make_response(+ _MockResponse(output=[_MockFunctionCall("tool", "{}", call_id="call_1")])+ )+ tool_outputs = [+ {"type": "function_call_output", "call_id": "call_1", "output": "done"}+ ]+ block._update_conversation(prompt, resp, tool_outputs)++ for item in prompt:+ has_role = item.get("role") in ("assistant", "system", "user", "developer")+ has_type = item.get("type") in (+ "function_call",+ "function_call_output",+ "message",+ )+ assert has_role or has_type, f"Invalid conversation item: {item}"+++# ───────────────────────────────────────────────────────────────────────────+# End-to-end: agent mode loop+# ───────────────────────────────────────────────────────────────────────────+++async def test_agent_mode_conversation_valid_for_responses_api():+ """Agent mode with a Responses API raw_response: the conversation passed+ to the second LLM call must contain only valid input items.++ Currently fails because:+ 1. The full Response object is serialised as a dict without ``role``+ 2. Tool results use ``role: "tool"`` instead of ``type: function_call_output``+ """+ import backend.blocks.llm as llm_module++ block = SmartDecisionMakerBlock()++ # First response: tool call+ mock_tc = MagicMock()+ mock_tc.id = "call_abc"+ mock_tc.function.name = "story_improver"+ mock_tc.function.arguments = (+ '{"prompt_values___story": "draft", "prompt_values___improvement": "polish"}'+ )++ resp1 = MagicMock()+ resp1.response = None+ resp1.tool_calls = [mock_tc]+ resp1.prompt_tokens = 100+ resp1.completion_tokens = 50+ resp1.reasoning = None+ resp1.raw_response = _MockResponse(+ output=[+ _MockFunctionCall(+ "story_improver",+ '{"prompt_values___story": "draft", "prompt_values___improvement": "polish"}',+ call_id="call_abc",+ )+ ]+ )++ # Second response: finished+ resp2 = MagicMock()+ resp2.response = "Done!"+ resp2.tool_calls = []+ resp2.prompt_tokens = 200+ resp2.completion_tokens = 10+ resp2.reasoning = None+ resp2.raw_response = _MockResponse(output=[_MockOutputMessage("Done!")])++ llm_mock = AsyncMock(side_effect=[resp1, resp2])++ tool_sigs = [+ {+ "type": "function",+ "function": {+ "name": "story_improver",+ "_sink_node_id": "sink-1",+ "_field_mapping": {},+ "parameters": {+ "type": "object",+ "properties": {+ "prompt_values___story": {"type": "string"},+ "prompt_values___improvement": {"type": "string"},+ },+ "required": [+ "prompt_values___story",+ "prompt_values___improvement",+ ],+ },+ },+ }+ ]++ mock_db = AsyncMock()+ mock_db.get_node.return_value = MagicMock(block_id="bid")+ ner = MagicMock(node_exec_id="neid")+ mock_db.upsert_execution_input.return_value = (+ ner,+ {"prompt_values___story": "draft", "prompt_values___improvement": "polish"},+ )+ mock_db.get_execution_outputs_by_node_exec_id.return_value = {+ "response": "polished"+ }++ ep = AsyncMock()+ ep.running_node_execution = defaultdict(MagicMock)+ ep.execution_stats = MagicMock()+ ep.execution_stats_lock = threading.Lock()+ ns = MagicMock(error=None)+ ep.on_node_execution = AsyncMock(return_value=ns)++ with patch("backend.blocks.llm.llm_call", llm_mock), patch.object(+ block, "_create_tool_node_signatures", return_value=tool_sigs+ ), patch(+ "backend.blocks.smart_decision_maker.get_database_manager_async_client",+ return_value=mock_db,+ ), patch(+ "backend.executor.manager.async_update_node_execution_status",+ new_callable=AsyncMock,+ ), patch(+ "backend.integrations.creds_manager.IntegrationCredentialsManager"+ ):++ inp = SmartDecisionMakerBlock.Input(+ prompt="Improve this",+ model=llm_module.DEFAULT_LLM_MODEL,+ credentials=llm_module.TEST_CREDENTIALS_INPUT, # type: ignore+ agent_mode_max_iterations=5,+ )++ outputs = {}+ async for name, data in block.run(+ inp,+ credentials=llm_module.TEST_CREDENTIALS,+ graph_id="gid",+ node_id="nid",+ graph_exec_id="geid",+ node_exec_id="neid",+ user_id="uid",+ graph_version=1,+ execution_context=ExecutionContext(human_in_the_loop_safe_mode=False),+ execution_processor=ep,+ ):+ outputs[name] = data++ # The second LLM call's prompt must only contain valid items+ assert llm_mock.call_count >= 2+ second_call = llm_mock.call_args_list[1]+ second_prompt = second_call.kwargs.get("prompt")+ if second_prompt is None:+ second_prompt = second_call[0][1] if len(second_call[0]) > 1 else None+ assert second_prompt is not None++ for i, item in enumerate(second_prompt):+ has_role = item.get("role") in ("assistant", "system", "user", "developer")+ has_type = item.get("type") in (+ "function_call",+ "function_call_output",+ "message",+ )+ assert (+ has_role or has_type+ ), f"input[{i}] has neither valid role nor type: {item!r}"+++async def test_traditional_mode_conversation_valid_for_responses_api():+ """Traditional mode: the yielded conversation must contain only valid items."""+ import backend.blocks.llm as llm_module++ block = SmartDecisionMakerBlock()++ mock_tc = MagicMock()+ mock_tc.function.name = "my_tool"+ mock_tc.function.arguments = '{"param": "val"}'++ resp = MagicMock()+ resp.response = None+ resp.tool_calls = [mock_tc]+ resp.prompt_tokens = 50+ resp.completion_tokens = 25+ resp.reasoning = None+ resp.raw_response = _MockResponse(+ output=[_MockFunctionCall("my_tool", '{"param": "val"}', call_id="call_t")]+ )++ tool_sigs = [+ {+ "type": "function",+ "function": {+ "name": "my_tool",+ "_sink_node_id": "sink-1",+ "_field_mapping": {},+ "parameters": {+ "type": "object",+ "properties": {"param": {"type": "string"}},+ "required": ["param"],+ },+ },+ }+ ]++ with patch(+ "backend.blocks.llm.llm_call", new_callable=AsyncMock, return_value=resp+ ), patch.object(block, "_create_tool_node_signatures", return_value=tool_sigs):++ inp = SmartDecisionMakerBlock.Input(+ prompt="Do it",+ model=llm_module.DEFAULT_LLM_MODEL,+ credentials=llm_module.TEST_CREDENTIALS_INPUT, # type: ignore+ agent_mode_max_iterations=0,+ )++ outputs = {}+ async for name, data in block.run(+ inp,+ credentials=llm_module.TEST_CREDENTIALS,+ graph_id="gid",+ node_id="nid",+ graph_exec_id="geid",+ node_exec_id="neid",+ user_id="uid",+ graph_version=1,+ execution_context=ExecutionContext(human_in_the_loop_safe_mode=False),+ execution_processor=MagicMock(),+ ):+ outputs[name] = data++ conversations = outputs["conversations"]+ for i, item in enumerate(conversations):+ has_role = item.get("role") in ("assistant", "system", "user", "developer")+ has_type = item.get("type") in (+ "function_call",+ "function_call_output",+ "message",+ )+ assert (+ has_role or has_type+ ), f"conversations[{i}] has neither valid role nor type: {item!r}"diff --git a/autogpt_platform/backend/backend/data/block_cost_config.py b/autogpt_platform/backend/backend/data/block_cost_config.pyindex a3a264b57b..ec369537c0 100644--- a/autogpt_platform/backend/backend/data/block_cost_config.py+++ b/autogpt_platform/backend/backend/data/block_cost_config.py@@ -76,7 +76,6 @@ MODEL_COST: dict[LlmModel, int] = {LlmModel.GPT4O_MINI: 1,LlmModel.GPT4O: 3,LlmModel.GPT4_TURBO: 10,- LlmModel.GPT3_5_TURBO: 1,LlmModel.CLAUDE_4_1_OPUS: 21,LlmModel.CLAUDE_4_OPUS: 21,LlmModel.CLAUDE_4_SONNET: 5,diff --git a/autogpt_platform/backend/backend/data/execution.py b/autogpt_platform/backend/backend/data/execution.pyindex 45669124d6..3b1b8cbf08 100644--- a/autogpt_platform/backend/backend/data/execution.py+++ b/autogpt_platform/backend/backend/data/execution.py@@ -877,12 +877,12 @@ async def get_execution_outputs_by_node_exec_id(where={"referencedByOutputExecId": node_exec_id})- result = {}+ result: CompletedBlockOutput = defaultdict(list)for output in outputs:if output.data is not None:- result[output.name] = type_utils.convert(output.data, JsonValue)+ result[output.name].append(type_utils.convert(output.data, JsonValue))- return result+ return dict(result)async def update_graph_execution_start_time(diff --git a/autogpt_platform/backend/backend/data/execution_outputs_test.py b/autogpt_platform/backend/backend/data/execution_outputs_test.pynew file mode 100644index 0000000000..cb8a1e87ef--- /dev/null+++ b/autogpt_platform/backend/backend/data/execution_outputs_test.py@@ -0,0 +1,102 @@+"""Test that get_execution_outputs_by_node_exec_id returns CompletedBlockOutput.++CompletedBlockOutput is dict[str, list[Any]] — values must be lists.+The RPC service layer validates return types via TypeAdapter, so if+the function returns plain values instead of lists, it causes:++ 1 validation error for dict[str,list[any]] response+ Input should be a valid list [type=list_type, input_value='', input_type=str]++This breaks SmartDecisionMakerBlock agent mode tool execution.+"""++from unittest.mock import AsyncMock, MagicMock, patch++import pytest+from pydantic import TypeAdapter++from backend.data.block import CompletedBlockOutput+++async def test_outputs_are_lists():+ """Each value in the returned dict must be a list, matching CompletedBlockOutput."""+ from backend.data.execution import get_execution_outputs_by_node_exec_id++ mock_output = MagicMock()+ mock_output.name = "response"+ mock_output.data = "some text output"++ with patch(+ "backend.data.execution.AgentNodeExecutionInputOutput.prisma"+ ) as mock_prisma:+ mock_prisma.return_value.find_many = AsyncMock(return_value=[mock_output])+ result = await get_execution_outputs_by_node_exec_id("test-exec-id")++ # The result must conform to CompletedBlockOutput = dict[str, list[Any]]+ assert "response" in result+ assert isinstance(+ result["response"], list+ ), f"Expected list, got {type(result['response']).__name__}: {result['response']!r}"++ # Must also pass TypeAdapter validation (this is what the RPC layer does)+ adapter = TypeAdapter(CompletedBlockOutput)+ validated = adapter.validate_python(result) # This is the line that fails in prod+ assert validated == {"response": ["some text output"]}+++async def test_multiple_outputs_same_name_are_collected():+ """Multiple outputs with the same name should all appear in the list."""+ from backend.data.execution import get_execution_outputs_by_node_exec_id++ mock_out1 = MagicMock()+ mock_out1.name = "result"+ mock_out1.data = "first"++ mock_out2 = MagicMock()+ mock_out2.name = "result"+ mock_out2.data = "second"++ with patch(+ "backend.data.execution.AgentNodeExecutionInputOutput.prisma"+ ) as mock_prisma:+ mock_prisma.return_value.find_many = AsyncMock(+ return_value=[mock_out1, mock_out2]+ )+ result = await get_execution_outputs_by_node_exec_id("test-exec-id")++ assert isinstance(result["result"], list)+ assert len(result["result"]) == 2+++async def test_empty_outputs_returns_empty_dict():+ """No outputs → empty dict."""+ from backend.data.execution import get_execution_outputs_by_node_exec_id++ with patch(+ "backend.data.execution.AgentNodeExecutionInputOutput.prisma"+ ) as mock_prisma:+ mock_prisma.return_value.find_many = AsyncMock(return_value=[])+ result = await get_execution_outputs_by_node_exec_id("test-exec-id")++ assert result == {}+++async def test_none_data_skipped():+ """Outputs with data=None should be skipped."""+ from backend.data.execution import get_execution_outputs_by_node_exec_id++ mock_output = MagicMock()+ mock_output.name = "response"+ mock_output.data = None++ with patch(+ "backend.data.execution.AgentNodeExecutionInputOutput.prisma"+ ) as mock_prisma:+ mock_prisma.return_value.find_many = AsyncMock(return_value=[mock_output])+ result = await get_execution_outputs_by_node_exec_id("test-exec-id")++ assert result == {}diff --git a/autogpt_platform/backend/backend/util/conftest.py b/autogpt_platform/backend/backend/util/conftest.pynew file mode 100644index 0000000000..b2048f7022--- /dev/null+++ b/autogpt_platform/backend/backend/util/conftest.py@@ -0,0 +1,14 @@+"""Override session-scoped fixtures from parent conftest.py so unit tests+in this directory can run without the full server stack."""++import pytest++[email protected](scope="session")+def server():+ yield None++[email protected](scope="session", autouse=True)+def graph_cleanup():+ yielddiff --git a/autogpt_platform/backend/backend/util/openai_responses.py b/autogpt_platform/backend/backend/util/openai_responses.pynew file mode 100644index 0000000000..2c4a618911--- /dev/null+++ b/autogpt_platform/backend/backend/util/openai_responses.py@@ -0,0 +1,150 @@+"""Helpers for OpenAI Responses API.++This module provides utilities for using OpenAI's Responses API, which is the+default for all OpenAI models supported by the platform.+"""++from typing import Any+++def convert_tools_to_responses_format(tools: list[dict] | None) -> list[dict]:+ """Convert Chat Completions tool format to Responses API format.++ The Responses API uses internally-tagged polymorphism (flatter structure)+ and functions are strict by default.++ Chat Completions format:+ {"type": "function", "function": {"name": "...", "parameters": {...}}}++ Responses API format:+ {"type": "function", "name": "...", "parameters": {...}}++ Args:+ tools: List of tools in Chat Completions format++ Returns:+ List of tools in Responses API format+ """+ if not tools:+ return []++ converted = []+ for tool in tools:+ if tool.get("type") == "function":+ func = tool.get("function", {})+ name = func.get("name")+ if not name:+ raise ValueError(+ f"Function tool is missing required 'name' field: {tool}"+ )+ entry: dict[str, Any] = {+ "type": "function",+ "name": name,+ # Note: strict=True is default in Responses API+ }+ if func.get("description") is not None:+ entry["description"] = func["description"]+ if func.get("parameters") is not None:+ entry["parameters"] = func["parameters"]+ converted.append(entry)+ else:+ # Pass through non-function tools as-is+ converted.append(tool)+ return converted+++def extract_responses_tool_calls(response: Any) -> list[dict] | None:+ """Extract tool calls from Responses API response.++ The Responses API returns tool calls as separate items in the output array+ with type="function_call".++ Args:+ response: The Responses API response object++ Returns:+ List of tool calls in a normalized format, or None if no tool calls+ """+ tool_calls = []+ for item in response.output:+ if getattr(item, "type", None) == "function_call":+ tool_calls.append(+ {+ "id": item.call_id,+ "type": "function",+ "function": {+ "name": item.name,+ "arguments": item.arguments,+ },+ }+ )+ return tool_calls if tool_calls else None+++def extract_responses_usage(response: Any) -> tuple[int, int]:+ """Extract token usage from Responses API response.++ The Responses API uses input_tokens/output_tokens (not prompt_tokens/completion_tokens).++ Args:+ response: The Responses API response object++ Returns:+ Tuple of (input_tokens, output_tokens)+ """+ if not getattr(response, "usage", None):+ return 0, 0++ return (+ getattr(response.usage, "input_tokens", 0),+ getattr(response.usage, "output_tokens", 0),+ )+++def extract_responses_content(response: Any) -> str:+ """Extract text content from Responses API response.++ Args:+ response: The Responses API response object++ Returns:+ The text content from the response, or empty string if none+ """+ # The SDK provides a helper property+ if hasattr(response, "output_text"):+ return response.output_text or ""++ # Fallback: manually extract from output items+ for item in response.output:+ if getattr(item, "type", None) == "message":+ for content in getattr(item, "content", []):+ if getattr(content, "type", None) == "output_text":+ return getattr(content, "text", "")+ return ""+++def extract_responses_reasoning(response: Any) -> str | None:+ """Extract reasoning content from Responses API response.++ Reasoning models return their reasoning process in the response,+ which can be useful for debugging or display.++ Args:+ response: The Responses API response object++ Returns:+ The reasoning text, or None if not present+ """+ for item in response.output:+ if getattr(item, "type", None) == "reasoning":+ # Reasoning items may have summary or content+ summary = getattr(item, "summary", [])+ if summary:+ # Join summary items if present+ texts = []+ for s in summary:+ if hasattr(s, "text"):+ texts.append(s.text)+ if texts:+ return "\n".join(texts)+ return Nonediff --git a/autogpt_platform/backend/backend/util/openai_responses_test.py b/autogpt_platform/backend/backend/util/openai_responses_test.pynew file mode 100644index 0000000000..b843159495--- /dev/null+++ b/autogpt_platform/backend/backend/util/openai_responses_test.py@@ -0,0 +1,312 @@+"""Tests for OpenAI Responses API helpers."""++from unittest.mock import MagicMock++from backend.util.openai_responses import (+ convert_tools_to_responses_format,+ extract_responses_content,+ extract_responses_reasoning,+ extract_responses_tool_calls,+ extract_responses_usage,+)+++class TestConvertToolsToResponsesFormat:+ """Tests for the convert_tools_to_responses_format function."""++ def test_empty_tools_returns_empty_list(self):+ """Empty or None tools should return empty list."""+ assert convert_tools_to_responses_format(None) == []+ assert convert_tools_to_responses_format([]) == []++ def test_converts_function_tool_format(self):+ """Should convert Chat Completions function format to Responses format."""+ chat_completions_tools = [+ {+ "type": "function",+ "function": {+ "name": "get_weather",+ "description": "Get the weather in a location",+ "parameters": {+ "type": "object",+ "properties": {+ "location": {"type": "string"},+ },+ "required": ["location"],+ },+ },+ }+ ]++ result = convert_tools_to_responses_format(chat_completions_tools)++ assert len(result) == 1+ assert result[0]["type"] == "function"+ assert result[0]["name"] == "get_weather"+ assert result[0]["description"] == "Get the weather in a location"+ assert result[0]["parameters"] == {+ "type": "object",+ "properties": {+ "location": {"type": "string"},+ },+ "required": ["location"],+ }+ # Should not have nested "function" key+ assert "function" not in result[0]++ def test_handles_multiple_tools(self):+ """Should handle multiple tools."""+ chat_completions_tools = [+ {+ "type": "function",+ "function": {+ "name": "tool_1",+ "description": "First tool",+ "parameters": {"type": "object", "properties": {}},+ },+ },+ {+ "type": "function",+ "function": {+ "name": "tool_2",+ "description": "Second tool",+ "parameters": {"type": "object", "properties": {}},+ },+ },+ ]++ result = convert_tools_to_responses_format(chat_completions_tools)++ assert len(result) == 2+ assert result[0]["name"] == "tool_1"+ assert result[1]["name"] == "tool_2"++ def test_passes_through_non_function_tools(self):+ """Non-function tools should be passed through as-is."""+ tools = [{"type": "web_search", "config": {"enabled": True}}]++ result = convert_tools_to_responses_format(tools)++ assert result == tools++ def test_omits_none_description_and_parameters(self):+ """Should omit description and parameters when they are None."""+ tools = [+ {+ "type": "function",+ "function": {+ "name": "simple_tool",+ },+ }+ ]++ result = convert_tools_to_responses_format(tools)++ assert len(result) == 1+ assert result[0]["type"] == "function"+ assert result[0]["name"] == "simple_tool"+ assert "description" not in result[0]+ assert "parameters" not in result[0]++ def test_raises_on_missing_name(self):+ """Should raise ValueError when function tool has no name."""+ import pytest++ tools = [{"type": "function", "function": {}}]+ with pytest.raises(ValueError, match="missing required 'name' field"):+ convert_tools_to_responses_format(tools)+++class TestExtractResponsesToolCalls:+ """Tests for the extract_responses_tool_calls function."""++ def test_extracts_function_call_items(self):+ """Should extract function_call items from response output."""+ item = MagicMock()+ item.type = "function_call"+ item.call_id = "call_123"+ item.name = "get_weather"+ item.arguments = '{"location": "NYC"}'++ response = MagicMock()+ response.output = [item]++ result = extract_responses_tool_calls(response)++ assert result == [+ {+ "id": "call_123",+ "type": "function",+ "function": {+ "name": "get_weather",+ "arguments": '{"location": "NYC"}',+ },+ }+ ]++ def test_returns_none_when_no_tool_calls(self):+ """Should return None when no function_call items exist."""+ message_item = MagicMock()+ message_item.type = "message"++ response = MagicMock()+ response.output = [message_item]++ assert extract_responses_tool_calls(response) is None++ def test_returns_none_for_empty_output(self):+ """Should return None when output is empty."""+ response = MagicMock()+ response.output = []++ assert extract_responses_tool_calls(response) is None++ def test_extracts_multiple_tool_calls(self):+ """Should extract multiple function_call items."""+ item1 = MagicMock()+ item1.type = "function_call"+ item1.call_id = "call_1"+ item1.name = "tool_a"+ item1.arguments = "{}"++ item2 = MagicMock()+ item2.type = "function_call"+ item2.call_id = "call_2"+ item2.name = "tool_b"+ item2.arguments = '{"x": 1}'++ response = MagicMock()+ response.output = [item1, item2]++ result = extract_responses_tool_calls(response)++ assert result is not None+ assert len(result) == 2+ assert result[0]["function"]["name"] == "tool_a"+ assert result[1]["function"]["name"] == "tool_b"+++class TestExtractResponsesUsage:+ """Tests for the extract_responses_usage function."""++ def test_extracts_token_counts(self):+ """Should extract input_tokens and output_tokens."""+ response = MagicMock()+ response.usage.input_tokens = 42+ response.usage.output_tokens = 17++ result = extract_responses_usage(response)++ assert result == (42, 17)++ def test_returns_zeros_when_usage_is_none(self):+ """Should return (0, 0) when usage is None."""+ response = MagicMock()+ response.usage = None++ result = extract_responses_usage(response)++ assert result == (0, 0)+++class TestExtractResponsesContent:+ """Tests for the extract_responses_content function."""++ def test_extracts_from_output_text(self):+ """Should use output_text property when available."""+ response = MagicMock()+ response.output_text = "Hello world"++ assert extract_responses_content(response) == "Hello world"++ def test_returns_empty_string_when_output_text_is_none(self):+ """Should return empty string when output_text is None."""+ response = MagicMock()+ response.output_text = None+ response.output = []++ assert extract_responses_content(response) == ""++ def test_fallback_to_output_items(self):+ """Should fall back to extracting from output items."""+ text_content = MagicMock()+ text_content.type = "output_text"+ text_content.text = "Fallback content"++ message_item = MagicMock()+ message_item.type = "message"+ message_item.content = [text_content]++ response = MagicMock(spec=[]) # no output_text attribute+ response.output = [message_item]++ assert extract_responses_content(response) == "Fallback content"++ def test_returns_empty_string_for_empty_output(self):+ """Should return empty string when no content found."""+ response = MagicMock(spec=[]) # no output_text attribute+ response.output = []++ assert extract_responses_content(response) == ""+++class TestExtractResponsesReasoning:+ """Tests for the extract_responses_reasoning function."""++ def test_extracts_reasoning_summary(self):+ """Should extract reasoning text from summary items."""+ summary_item = MagicMock()+ summary_item.text = "Step 1: Think about it"++ reasoning_item = MagicMock()+ reasoning_item.type = "reasoning"+ reasoning_item.summary = [summary_item]++ response = MagicMock()+ response.output = [reasoning_item]++ assert extract_responses_reasoning(response) == "Step 1: Think about it"++ def test_joins_multiple_summary_items(self):+ """Should join multiple summary text items with newlines."""+ s1 = MagicMock()+ s1.text = "First thought"+ s2 = MagicMock()+ s2.text = "Second thought"++ reasoning_item = MagicMock()+ reasoning_item.type = "reasoning"+ reasoning_item.summary = [s1, s2]++ response = MagicMock()+ response.output = [reasoning_item]++ assert extract_responses_reasoning(response) == "First thought\nSecond thought"++ def test_returns_none_when_no_reasoning(self):+ """Should return None when no reasoning items exist."""+ message_item = MagicMock()+ message_item.type = "message"++ response = MagicMock()+ response.output = [message_item]++ assert extract_responses_reasoning(response) is None++ def test_returns_none_for_empty_output(self):+ """Should return None when output is empty."""+ response = MagicMock()+ response.output = []++ assert extract_responses_reasoning(response) is None++ def test_returns_none_when_summary_is_empty(self):+ """Should return None when reasoning item has empty summary."""+ reasoning_item = MagicMock()+ reasoning_item.type = "reasoning"+ reasoning_item.summary = []++ response = MagicMock()+ response.output = [reasoning_item]++ assert extract_responses_reasoning(response) is Nonediff --git a/autogpt_platform/backend/backend/util/prompt.py b/autogpt_platform/backend/backend/util/prompt.pyindex cf8f737a0a..071e109dcc 100644--- a/autogpt_platform/backend/backend/util/prompt.py+++ b/autogpt_platform/backend/backend/util/prompt.py@@ -36,16 +36,34 @@ def _msg_tokens(msg: dict, enc) -> int:OpenAI counts ≈3 wrapper tokens per chat message, plus 1 if "name"is present, plus the tokenised content length.For tool calls, we need to count tokens in tool_calls and content fields.+ Supports Chat Completions, Anthropic, and Responses API formats."""WRAPPER = 3 + (1 if "name" in msg else 0)+ # Responses API: function_call items have arguments + name+ if msg.get("type") == "function_call":+ return (+ WRAPPER+ + _tok_len(msg.get("name", ""), enc)+ + _tok_len(msg.get("arguments", ""), enc)+ + _tok_len(msg.get("call_id", ""), enc)+ )++ # Responses API: function_call_output items have output+ if msg.get("type") == "function_call_output":+ return (+ WRAPPER+ + _tok_len(msg.get("output", ""), enc)+ + _tok_len(msg.get("call_id", ""), enc)+ )+# Count content tokenscontent_tokens = _tok_len(msg.get("content") or "", enc)# Count tool call tokens for both OpenAI and Anthropic formatstool_call_tokens = 0- # OpenAI format: tool_calls array at message level+ # OpenAI Chat Completions format: tool_calls array at message levelif "tool_calls" in msg and isinstance(msg["tool_calls"], list):for tool_call in msg["tool_calls"]:# Count the tool call structure tokens@@ -85,6 +103,10 @@ def _msg_tokens(msg: dict, enc) -> int:def _is_tool_message(msg: dict) -> bool:"""Check if a message contains tool calls or results that should be protected."""+ # Responses API: standalone function_call / function_call_output items+ if msg.get("type") in ("function_call", "function_call_output"):+ return True+content = msg.get("content")# Check for Anthropic-style tool messages@@ -94,7 +116,7 @@ def _is_tool_message(msg: dict) -> bool:):return True- # Check for OpenAI-style tool calls in the message+ # Check for OpenAI Chat Completions-style tool calls in the messageif "tool_calls" in msg or msg.get("role") == "tool":return True@@ -113,11 +135,18 @@ def _is_objective_message(msg: dict) -> bool:def _truncate_tool_message_content(msg: dict, enc, max_tokens: int) -> None:"""Carefully truncate tool message content while preserving tool structure.- Handles both Anthropic-style (list content) and OpenAI-style (string content) tool messages.+ Handles Anthropic, Chat Completions, and Responses API tool messages."""+ # Responses API: function_call_output has "output" field+ if msg.get("type") == "function_call_output":+ output = msg.get("output", "")+ if isinstance(output, str) and _tok_len(output, enc) > max_tokens:+ msg["output"] = _truncate_middle_tokens(output, enc, max_tokens)+ return+content = msg.get("content")- # OpenAI-style tool message: role="tool" with string content+ # OpenAI Chat Completions tool message: role="tool" with string contentif msg.get("role") == "tool" and isinstance(content, str):if _tok_len(content, enc) > max_tokens:msg["content"] = _truncate_middle_tokens(content, enc, max_tokens)@@ -251,18 +280,26 @@ def _extract_tool_call_ids_from_message(msg: dict) -> set[str]:"""Extract tool_call IDs from an assistant message.- Supports both formats:- - OpenAI: {"role": "assistant", "tool_calls": [{"id": "..."}]}+ Supports all formats:+ - OpenAI Chat Completions: {"role": "assistant", "tool_calls": [{"id": "..."}]}- Anthropic: {"role": "assistant", "content": [{"type": "tool_use", "id": "..."}]}+ - OpenAI Responses API: {"type": "function_call", "call_id": "..."}Returns:Set of tool_call IDs found in the message."""ids: set[str] = set()++ # Responses API: standalone function_call item+ if msg.get("type") == "function_call":+ if call_id := msg.get("call_id"):+ ids.add(call_id)+ return ids+if msg.get("role") != "assistant":return ids- # OpenAI format: tool_calls array+ # OpenAI Chat Completions format: tool_calls arrayif msg.get("tool_calls"):for tc in msg["tool_calls"]:tc_id = tc.get("id")@@ -285,16 +322,23 @@ def _extract_tool_response_ids_from_message(msg: dict) -> set[str]:"""Extract tool_call IDs that this message is responding to.- Supports both formats:- - OpenAI: {"role": "tool", "tool_call_id": "..."}+ Supports all formats:+ - OpenAI Chat Completions: {"role": "tool", "tool_call_id": "..."}- Anthropic: {"role": "user", "content": [{"type": "tool_result", "tool_use_id": "..."}]}+ - OpenAI Responses API: {"type": "function_call_output", "call_id": "..."}Returns:Set of tool_call IDs this message responds to."""ids: set[str] = set()- # OpenAI format: role=tool with tool_call_id+ # Responses API: standalone function_call_output item+ if msg.get("type") == "function_call_output":+ if call_id := msg.get("call_id"):+ ids.add(call_id)+ return ids++ # OpenAI Chat Completions format: role=tool with tool_call_idif msg.get("role") == "tool":tc_id = msg.get("tool_call_id")if tc_id:@@ -313,8 +357,11 @@ def _extract_tool_response_ids_from_message(msg: dict) -> set[str]:def _is_tool_response_message(msg: dict) -> bool:- """Check if message is a tool response (OpenAI or Anthropic format)."""- # OpenAI format+ """Check if message is a tool response (Chat Completions, Anthropic, or Responses API)."""+ # Responses API format+ if msg.get("type") == "function_call_output":+ return True+ # OpenAI Chat Completions formatif msg.get("role") == "tool":return True# Anthropic format@@ -332,13 +379,20 @@ def _remove_orphan_tool_responses("""Remove tool response messages/blocks that reference orphan tool_call IDs.- Supports both OpenAI and Anthropic formats.+ Supports OpenAI Chat Completions, Anthropic, and Responses API formats.For Anthropic messages with mixed valid/orphan tool_result blocks,filters out only the orphan blocks instead of dropping the entire message."""result = []for msg in messages:- # OpenAI format: role=tool - drop entire message if orphan+ # Responses API: function_call_output - drop if orphan+ if msg.get("type") == "function_call_output":+ if msg.get("call_id") in orphan_ids:+ continue+ result.append(msg)+ continue++ # OpenAI Chat Completions: role=tool - drop entire message if orphanif msg.get("role") == "tool":tc_id = msg.get("tool_call_id")if tc_id and tc_id in orphan_ids:@@ -524,6 +578,18 @@ async def _summarize_messages_llm("""Summarize messages using an LLM."""conversation = []for msg in messages:+ # Responses API: function_call items+ if msg.get("type") == "function_call":+ name = msg.get("name", "unknown_tool")+ args = msg.get("arguments", "")+ conversation.append(f"TOOL CALL ({name}): {args}")+ continue+ # Responses API: function_call_output items+ if msg.get("type") == "function_call_output":+ output = msg.get("output", "")+ conversation.append(f"TOOL OUTPUT: {output}")+ continue+role = msg.get("role", "")content = msg.get("content", "")if content and role in ("user", "assistant", "tool"):diff --git a/autogpt_platform/backend/backend/util/prompt_responses_api_test.py b/autogpt_platform/backend/backend/util/prompt_responses_api_test.pynew file mode 100644index 0000000000..49f43115fe--- /dev/null+++ b/autogpt_platform/backend/backend/util/prompt_responses_api_test.py@@ -0,0 +1,603 @@+"""Tests for prompt.py compatibility with the OpenAI Responses API.++The Responses API uses a different conversation format:+- Tool calls are standalone items with ``type: "function_call"`` and ``call_id``+- Tool results are items with ``type: "function_call_output"`` and ``call_id``+- These items do NOT have ``role`` at the top level++These tests validate that prompt utilities correctly handle Responses API items+alongside Chat Completions and Anthropic formats.+"""++import pytest+from tiktoken import encoding_for_model++from backend.util.prompt import (+ _ensure_tool_pairs_intact,+ _extract_tool_call_ids_from_message,+ _extract_tool_response_ids_from_message,+ _is_tool_message,+ _is_tool_response_message,+ _msg_tokens,+ _remove_orphan_tool_responses,+ _truncate_tool_message_content,+ compress_context,+ validate_and_remove_orphan_tool_responses,+)++# ── Fixtures ──────────────────────────────────────────────────────────────+++def enc():+ return encoding_for_model("gpt-4o")+++# ── Sample items ──────────────────────────────────────────────────────────++FUNCTION_CALL_ITEM = {+ "type": "function_call",+ "id": "fc_abc",+ "call_id": "call_abc",+ "name": "search_tool",+ "arguments": '{"query": "python asyncio tutorial"}',+ "status": "completed",+}++FUNCTION_CALL_OUTPUT_ITEM = {+ "type": "function_call_output",+ "call_id": "call_abc",+ "output": '{"results": ["result1", "result2", "result3"]}',+}+++# ═══════════════════════════════════════════════════════════════════════════+# _msg_tokens+# ═══════════════════════════════════════════════════════════════════════════+++class TestMsgTokensResponsesApi:+ """_msg_tokens should count tokens in function_call / function_call_output+ items, not just role-based messages."""++ def test_chat_completions_tool_call_counted(self, enc):+ """Baseline: Chat Completions tool_calls are counted correctly."""+ msg = {+ "role": "assistant",+ "content": None,+ "tool_calls": [+ {+ "id": "call_abc",+ "type": "function",+ "function": {+ "name": "search_tool",+ "arguments": '{"query": "python asyncio tutorial"}',+ },+ }+ ],+ }+ tokens = _msg_tokens(msg, enc)+ assert tokens > 10 # Should count the tool call content++ def test_chat_completions_tool_response_counted(self, enc):+ """Baseline: Chat Completions tool responses are counted correctly."""+ msg = {+ "role": "tool",+ "tool_call_id": "call_abc",+ "content": '{"results": ["result1", "result2"]}',+ }+ tokens = _msg_tokens(msg, enc)+ assert tokens > 5++ def test_function_call_minimal_fields(self, enc):+ """function_call with missing optional fields still counts."""+ msg = {"type": "function_call"}+ tokens = _msg_tokens(msg, enc)+ assert tokens >= 3 # At least the wrapper++ def test_function_call_output_minimal_fields(self, enc):+ """function_call_output with missing output field still counts."""+ msg = {"type": "function_call_output"}+ tokens = _msg_tokens(msg, enc)+ assert tokens >= 3++ def test_function_call_arguments_counted(self, enc):+ """function_call items have 'arguments' not 'content' — tokens must+ include the arguments string and the function name."""+ tokens = _msg_tokens(FUNCTION_CALL_ITEM, enc)+ # Must count at least the arguments and name tokens+ name_tokens = len(enc.encode(FUNCTION_CALL_ITEM["name"]))+ args_tokens = len(enc.encode(FUNCTION_CALL_ITEM["arguments"]))+ assert tokens >= name_tokens + args_tokens++ def test_function_call_output_content_counted(self, enc):+ """function_call_output items have 'output' not 'content' — tokens must+ include the output string."""+ tokens = _msg_tokens(FUNCTION_CALL_OUTPUT_ITEM, enc)+ output_tokens = len(enc.encode(FUNCTION_CALL_OUTPUT_ITEM["output"]))+ assert tokens >= output_tokens+++# ═══════════════════════════════════════════════════════════════════════════+# _is_tool_message+# ═══════════════════════════════════════════════════════════════════════════+++class TestIsToolMessageResponsesApi:+ """_is_tool_message should recognise Responses API items as tool messages+ so they are protected from deletion during compaction."""++ def test_chat_completions_tool_call_detected(self):+ """Baseline: Chat Completions tool_calls are detected."""+ msg = {+ "role": "assistant",+ "tool_calls": [{"id": "call_1", "type": "function"}],+ }+ assert _is_tool_message(msg) is True++ def test_chat_completions_tool_response_detected(self):+ """Baseline: Chat Completions role=tool is detected."""+ msg = {"role": "tool", "tool_call_id": "call_1", "content": "result"}+ assert _is_tool_message(msg) is True++ def test_anthropic_tool_use_detected(self):+ """Baseline: Anthropic tool_use is detected."""+ msg = {+ "role": "assistant",+ "content": [+ {"type": "tool_use", "id": "toolu_1", "name": "t", "input": {}}+ ],+ }+ assert _is_tool_message(msg) is True++ def test_anthropic_tool_result_detected(self):+ """Baseline: Anthropic tool_result is detected."""+ msg = {+ "role": "user",+ "content": [+ {"type": "tool_result", "tool_use_id": "toolu_1", "content": "ok"}+ ],+ }+ assert _is_tool_message(msg) is True++ def test_function_call_detected(self):+ """type=function_call should be recognised as a tool message."""+ assert _is_tool_message(FUNCTION_CALL_ITEM) is True++ def test_function_call_output_detected(self):+ """type=function_call_output should be recognised as a tool message."""+ assert _is_tool_message(FUNCTION_CALL_OUTPUT_ITEM) is True++ def test_regular_user_message_not_tool(self):+ """Plain user message → not a tool message."""+ assert _is_tool_message({"role": "user", "content": "hello"}) is False++ def test_regular_assistant_message_not_tool(self):+ """Plain assistant message without tool_calls → not a tool message."""+ assert _is_tool_message({"role": "assistant", "content": "hi"}) is False+++# ═══════════════════════════════════════════════════════════════════════════+# _extract_tool_call_ids_from_message+# ═══════════════════════════════════════════════════════════════════════════+++class TestExtractToolCallIdsResponsesApi:+ """_extract_tool_call_ids_from_message should extract call_ids from+ Responses API function_call items."""++ def test_chat_completions_extracted(self):+ """Baseline: Chat Completions tool_calls IDs are extracted."""+ msg = {+ "role": "assistant",+ "tool_calls": [+ {"id": "call_1", "type": "function"},+ {"id": "call_2", "type": "function"},+ ],+ }+ assert _extract_tool_call_ids_from_message(msg) == {"call_1", "call_2"}++ def test_anthropic_extracted(self):+ """Baseline: Anthropic tool_use IDs are extracted."""+ msg = {+ "role": "assistant",+ "content": [{"type": "tool_use", "id": "toolu_1"}],+ }+ assert _extract_tool_call_ids_from_message(msg) == {"toolu_1"}++ def test_function_call_extracted(self):+ """type=function_call with call_id should be extracted."""+ assert _extract_tool_call_ids_from_message(FUNCTION_CALL_ITEM) == {"call_abc"}++ def test_function_call_missing_call_id(self):+ """function_call without call_id → empty set."""+ msg = {"type": "function_call", "name": "tool"}+ assert _extract_tool_call_ids_from_message(msg) == set()++ def test_non_assistant_non_function_call(self):+ """Messages with neither role=assistant nor type=function_call → empty."""+ msg = {"role": "user", "content": "hello"}+ assert _extract_tool_call_ids_from_message(msg) == set()+++# ═══════════════════════════════════════════════════════════════════════════+# _extract_tool_response_ids_from_message+# ═══════════════════════════════════════════════════════════════════════════+++class TestExtractToolResponseIdsResponsesApi:+ """_extract_tool_response_ids_from_message should extract call_ids from+ Responses API function_call_output items."""++ def test_chat_completions_extracted(self):+ """Baseline: Chat Completions tool_call_id is extracted."""+ msg = {"role": "tool", "tool_call_id": "call_1", "content": "result"}+ assert _extract_tool_response_ids_from_message(msg) == {"call_1"}++ def test_anthropic_extracted(self):+ """Baseline: Anthropic tool_use_id is extracted."""+ msg = {+ "role": "user",+ "content": [+ {"type": "tool_result", "tool_use_id": "toolu_1", "content": "ok"}+ ],+ }+ assert _extract_tool_response_ids_from_message(msg) == {"toolu_1"}++ def test_function_call_output_extracted(self):+ """type=function_call_output with call_id should be extracted."""+ assert _extract_tool_response_ids_from_message(FUNCTION_CALL_OUTPUT_ITEM) == {+ "call_abc"+ }++ def test_function_call_output_missing_call_id(self):+ """function_call_output without call_id → empty set."""+ msg = {"type": "function_call_output", "output": "result"}+ assert _extract_tool_response_ids_from_message(msg) == set()++ def test_non_tool_non_function_call_output(self):+ """Regular user message → empty set."""+ msg = {"role": "user", "content": "hello"}+ assert _extract_tool_response_ids_from_message(msg) == set()+++# ═══════════════════════════════════════════════════════════════════════════+# _is_tool_response_message+# ═══════════════════════════════════════════════════════════════════════════+++class TestIsToolResponseMessageResponsesApi:+ def test_chat_completions_detected(self):+ msg = {"role": "tool", "tool_call_id": "call_1", "content": "r"}+ assert _is_tool_response_message(msg) is True++ def test_anthropic_detected(self):+ msg = {+ "role": "user",+ "content": [+ {"type": "tool_result", "tool_use_id": "toolu_1", "content": "ok"}+ ],+ }+ assert _is_tool_response_message(msg) is True++ def test_function_call_output_detected(self):+ """type=function_call_output should be recognised as a tool response."""+ assert _is_tool_response_message(FUNCTION_CALL_OUTPUT_ITEM) is True++ def test_function_call_is_not_response(self):+ """function_call is a tool REQUEST, not a response."""+ assert _is_tool_response_message(FUNCTION_CALL_ITEM) is False++ def test_regular_message_not_response(self):+ """Plain message → not a tool response."""+ assert _is_tool_response_message({"role": "user", "content": "hi"}) is False+++# ═══════════════════════════════════════════════════════════════════════════+# _truncate_tool_message_content+# ═══════════════════════════════════════════════════════════════════════════+++class TestTruncateToolMessageContentResponsesApi:+ def test_chat_completions_truncated(self, enc):+ """Baseline: role=tool content is truncated."""+ msg = {"role": "tool", "tool_call_id": "call_1", "content": "x" * 10000}+ _truncate_tool_message_content(msg, enc, max_tokens=50)+ assert len(enc.encode(msg["content"])) <= 55 # ~50 with rounding++ def test_function_call_output_truncated(self, enc):+ """function_call_output 'output' field should be truncated."""+ msg = {+ "type": "function_call_output",+ "call_id": "call_1",+ "output": "x" * 10000,+ }+ _truncate_tool_message_content(msg, enc, max_tokens=50)+ assert len(enc.encode(msg["output"])) <= 55++ def test_function_call_output_short_not_truncated(self, enc):+ """Short function_call_output output is left unchanged."""+ msg = {+ "type": "function_call_output",+ "call_id": "call_1",+ "output": "short",+ }+ _truncate_tool_message_content(msg, enc, max_tokens=1000)+ assert msg["output"] == "short"++ def test_function_call_not_truncated(self, enc):+ """function_call items (requests) should not be truncated."""+ msg = dict(FUNCTION_CALL_ITEM) # copy+ original_args = msg["arguments"]+ _truncate_tool_message_content(msg, enc, max_tokens=5)+ assert msg["arguments"] == original_args # unchanged+++# ═══════════════════════════════════════════════════════════════════════════+# _remove_orphan_tool_responses+# ═══════════════════════════════════════════════════════════════════════════+++class TestRemoveOrphanToolResponsesResponsesApi:+ def test_chat_completions_orphan_removed(self):+ """Baseline: orphan role=tool messages are removed."""+ messages = [+ {"role": "tool", "tool_call_id": "call_orphan", "content": "result"},+ {"role": "user", "content": "Hello"},+ ]+ result = _remove_orphan_tool_responses(messages, {"call_orphan"})+ assert len(result) == 1+ assert result[0]["role"] == "user"++ def test_function_call_output_orphan_removed(self):+ """Orphan function_call_output items should be removed."""+ messages = [+ {+ "type": "function_call_output",+ "call_id": "call_orphan",+ "output": "result",+ },+ {"role": "user", "content": "Hello"},+ ]+ result = _remove_orphan_tool_responses(messages, {"call_orphan"})+ assert len(result) == 1+ assert result[0]["role"] == "user"++ def test_function_call_output_non_orphan_kept(self):+ """Non-orphan function_call_output items should be kept."""+ messages = [+ {+ "type": "function_call_output",+ "call_id": "call_valid",+ "output": "result",+ },+ {"role": "user", "content": "Hello"},+ ]+ result = _remove_orphan_tool_responses(messages, {"call_other"})+ assert len(result) == 2+++# ═══════════════════════════════════════════════════════════════════════════+# validate_and_remove_orphan_tool_responses+# ═══════════════════════════════════════════════════════════════════════════+++class TestValidateOrphansResponsesApi:+ def test_chat_completions_paired_kept(self):+ """Baseline: matched Chat Completions pairs are kept."""+ messages = [+ {+ "role": "assistant",+ "tool_calls": [{"id": "call_1", "type": "function"}],+ },+ {"role": "tool", "tool_call_id": "call_1", "content": "done"},+ ]+ result = validate_and_remove_orphan_tool_responses(messages, log_warning=False)+ assert len(result) == 2++ def test_responses_api_paired_kept(self):+ """Matched Responses API pairs are kept because the validator+ properly recognizes function_call and function_call_output items."""+ messages = [+ {"role": "user", "content": "Do something."},+ FUNCTION_CALL_ITEM,+ FUNCTION_CALL_OUTPUT_ITEM,+ ]+ result = validate_and_remove_orphan_tool_responses(messages, log_warning=False)+ assert len(result) == 3++ def test_responses_api_orphan_output_removed(self):+ """Orphan function_call_output (no matching function_call) should be removed."""+ messages = [+ {"role": "user", "content": "Do something."},+ # No function_call — output is orphaned+ FUNCTION_CALL_OUTPUT_ITEM,+ ]+ result = validate_and_remove_orphan_tool_responses(messages, log_warning=False)+ assert len(result) == 1+ assert result[0]["role"] == "user"+++# ═══════════════════════════════════════════════════════════════════════════+# _ensure_tool_pairs_intact+# ═══════════════════════════════════════════════════════════════════════════+++class TestEnsureToolPairsIntactResponsesApi:+ def test_chat_completions_pair_preserved(self):+ """Baseline: sliced Chat Completions tool responses get their assistant prepended."""+ all_msgs = [+ {"role": "system", "content": "sys"},+ {+ "role": "assistant",+ "tool_calls": [{"id": "call_1", "type": "function"}],+ },+ {"role": "tool", "tool_call_id": "call_1", "content": "result"},+ {"role": "user", "content": "thanks"},+ ]+ # Slice starts at index 2 (tool response) — orphan+ recent = [all_msgs[2], all_msgs[3]]+ result = _ensure_tool_pairs_intact(recent, all_msgs, start_index=2)+ # Should prepend the assistant message+ assert len(result) == 3+ assert "tool_calls" in result[0]++ def test_responses_api_pair_preserved(self):+ """Sliced function_call_output should get its function_call prepended."""+ all_msgs = [+ {"role": "system", "content": "sys"},+ {"role": "user", "content": "search for X"},+ FUNCTION_CALL_ITEM,+ FUNCTION_CALL_OUTPUT_ITEM,+ {"role": "user", "content": "thanks"},+ ]+ # Slice starts at index 3 (function_call_output) — orphan+ recent = [all_msgs[3], all_msgs[4]]+ result = _ensure_tool_pairs_intact(recent, all_msgs, start_index=3)+ # Should prepend the function_call item+ assert len(result) == 3+ assert result[0].get("type") == "function_call"+++# ═══════════════════════════════════════════════════════════════════════════+# _summarize_messages_llm (minor)+# ═══════════════════════════════════════════════════════════════════════════+++class TestSummarizeMessagesResponsesApi:+ """_summarize_messages_llm extracts content using msg.get("role") and+ msg.get("content"). Responses API function_call items have neither+ role in ("user", "assistant", "tool") nor "content" — they'd be silently+ skipped in the summary. This is a minor data-loss issue."""++ @pytest.mark.asyncio+ async def test_function_call_included_in_summary_text(self):+ """function_call items should contribute to the summary text."""+ from backend.util.prompt import _summarize_messages_llm++ messages = [+ {"role": "user", "content": "Search for X"},+ FUNCTION_CALL_ITEM,+ FUNCTION_CALL_OUTPUT_ITEM,+ {"role": "user", "content": "Thanks"},+ ]++ # We only need to check the conversation text building, not the LLM call.+ # The function builds conversation_text before calling the client.+ # We mock the client to capture what it receives.+ from unittest.mock import AsyncMock, MagicMock++ mock_client = MagicMock()+ mock_resp = MagicMock()+ mock_resp.choices = [MagicMock()]+ mock_resp.choices[0].message.content = "Summary"+ mock_client.with_options.return_value.chat.completions.create = AsyncMock(+ return_value=mock_resp+ )++ await _summarize_messages_llm(messages, mock_client, "gpt-4o")++ # Check the prompt sent to the LLM contains tool info+ call_args = (+ mock_client.with_options.return_value.chat.completions.create.call_args+ )+ user_msg = call_args.kwargs["messages"][1]["content"]+ # The tool name or arguments should appear in the summary text+ assert "search_tool" in user_msg or "python asyncio" in user_msg+++# ═══════════════════════════════════════════════════════════════════════════+# compress_context end-to-end+# ═══════════════════════════════════════════════════════════════════════════+++class TestCompressContextResponsesApi:+ @pytest.mark.asyncio+ async def test_chat_completions_tool_pairs_preserved(self):+ """Baseline: Chat Completions tool pairs survive compaction."""+ messages: list[dict] = [+ {"role": "system", "content": "You are helpful."},+ ]+ # Add enough messages to trigger compaction+ for i in range(20):+ messages.append({"role": "user", "content": f"Question {i} " * 200})+ messages.append({"role": "assistant", "content": f"Answer {i} " * 200})+ # Add a tool pair at the end+ messages.append(+ {+ "role": "assistant",+ "tool_calls": [+ {"id": "call_final", "type": "function", "function": {"name": "f"}}+ ],+ }+ )+ messages.append(+ {"role": "tool", "tool_call_id": "call_final", "content": "result"}+ )+ messages.append({"role": "assistant", "content": "Done!"})++ result = await compress_context(messages, target_tokens=2000, client=None)++ # If tool response exists, its call must exist too+ call_ids = set()+ resp_ids = set()+ for msg in result.messages:+ if "tool_calls" in msg:+ for tc in msg["tool_calls"]:+ call_ids.add(tc["id"])+ if msg.get("role") == "tool":+ resp_ids.add(msg.get("tool_call_id"))+ assert resp_ids <= call_ids++ @pytest.mark.asyncio+ async def test_responses_api_tool_pairs_preserved(self):+ """Responses API function_call / function_call_output pairs must+ survive compaction intact. Currently they can be silently deleted+ because _is_tool_message doesn't recognise them."""+ messages = [+ {"role": "system", "content": "You are helpful."},+ ]+ # Add enough messages to trigger compaction+ for i in range(20):+ messages.append({"role": "user", "content": f"Question {i} " * 200})+ messages.append({"role": "assistant", "content": f"Answer {i} " * 200})+ # Add a Responses API tool pair at the end+ messages.append(+ {+ "type": "function_call",+ "id": "fc_final",+ "call_id": "call_final",+ "name": "search_tool",+ "arguments": '{"q": "test"}',+ "status": "completed",+ }+ )+ messages.append(+ {+ "type": "function_call_output",+ "call_id": "call_final",+ "output": '{"results": ["a", "b"]}',+ }+ )+ messages.append({"role": "user", "content": "Thanks!"})++ result = await compress_context(messages, target_tokens=2000, client=None)++ # The function_call and function_call_output must both survive+ fc_items = [m for m in result.messages if m.get("type") == "function_call"]+ fco_items = [+ m for m in result.messages if m.get("type") == "function_call_output"+ ]++ # If either exists, the other must exist too (pair integrity)+ if fc_items or fco_items:+ fc_call_ids = {m["call_id"] for m in fc_items}+ fco_call_ids = {m["call_id"] for m in fco_items}+ assert (+ fco_call_ids <= fc_call_ids+ ), "function_call_output exists without matching function_call"++ # At minimum, neither should have been silently deleted if the+ # conversation was short enough to keep them+ assert len(fc_items) >= 1, "function_call was deleted during compaction"+ assert len(fco_items) >= 1, "function_call_output was deleted during compaction"diff --git a/docs/integrations/block-integrations/llm.md b/docs/integrations/block-integrations/llm.mdindex b506cfe0bc..8f62223d65 100644--- a/docs/integrations/block-integrations/llm.md+++ b/docs/integrations/block-integrations/llm.md@@ -65,7 +65,7 @@ The result routes data to yes_output or no_output, enabling intelligent branchin| condition | A plaintext English description of the condition to evaluate | str | Yes || yes_value | (Optional) Value to output if the condition is true. If not provided, input_value will be used. | Yes Value | No || no_value | (Optional) Value to output if the condition is false. If not provided, input_value will be used. | No Value | No |-| model | The language model to use for evaluating the condition. | "o3-mini" \| "o3-2025-04-16" \| "o1" \| "o1-mini" \| "gpt-5.2-2025-12-11" \| "gpt-5.1-2025-11-13" \| "gpt-5-2025-08-07" \| "gpt-5-mini-2025-08-07" \| "gpt-5-nano-2025-08-07" \| "gpt-5-chat-latest" \| "gpt-4.1-2025-04-14" \| "gpt-4.1-mini-2025-04-14" \| "gpt-4o-mini" \| "gpt-4o" \| "gpt-4-turbo" \| "gpt-3.5-turbo" \| "claude-opus-4-1-20250805" \| "claude-opus-4-20250514" \| "claude-sonnet-4-20250514" \| "claude-opus-4-5-20251101" \| "claude-sonnet-4-5-20250929" \| "claude-haiku-4-5-20251001" \| "claude-opus-4-6" \| "claude-sonnet-4-6" \| "claude-3-haiku-20240307" \| "Qwen/Qwen2.5-72B-Instruct-Turbo" \| "nvidia/llama-3.1-nemotron-70b-instruct" \| "meta-llama/Llama-3.3-70B-Instruct-Turbo" \| "meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo" \| "meta-llama/Llama-3.2-3B-Instruct-Turbo" \| "llama-3.3-70b-versatile" \| "llama-3.1-8b-instant" \| "llama3.3" \| "llama3.2" \| "llama3" \| "llama3.1:405b" \| "dolphin-mistral:latest" \| "openai/gpt-oss-120b" \| "openai/gpt-oss-20b" \| "google/gemini-2.5-pro-preview-03-25" \| "google/gemini-2.5-pro" \| "google/gemini-3.1-pro-preview" \| "google/gemini-3-flash-preview" \| "google/gemini-2.5-flash" \| "google/gemini-2.0-flash-001" \| "google/gemini-3.1-flash-lite-preview" \| "google/gemini-2.5-flash-lite-preview-06-17" \| "google/gemini-2.0-flash-lite-001" \| "mistralai/mistral-nemo" \| "mistralai/mistral-large-2512" \| "mistralai/mistral-medium-3.1" \| "mistralai/mistral-small-3.2-24b-instruct" \| "mistralai/codestral-2508" \| "cohere/command-r-08-2024" \| "cohere/command-r-plus-08-2024" \| "cohere/command-a-03-2025" \| "cohere/command-a-translate-08-2025" \| "cohere/command-a-reasoning-08-2025" \| "cohere/command-a-vision-07-2025" \| "deepseek/deepseek-chat" \| "deepseek/deepseek-r1-0528" \| "perplexity/sonar" \| "perplexity/sonar-pro" \| "perplexity/sonar-reasoning-pro" \| "perplexity/sonar-deep-research" \| "nousresearch/hermes-3-llama-3.1-405b" \| "nousresearch/hermes-3-llama-3.1-70b" \| "amazon/nova-lite-v1" \| "amazon/nova-micro-v1" \| "amazon/nova-pro-v1" \| "microsoft/wizardlm-2-8x22b" \| "microsoft/phi-4" \| "gryphe/mythomax-l2-13b" \| "meta-llama/llama-4-scout" \| "meta-llama/llama-4-maverick" \| "x-ai/grok-3" \| "x-ai/grok-4" \| "x-ai/grok-4-fast" \| "x-ai/grok-4.1-fast" \| "x-ai/grok-code-fast-1" \| "moonshotai/kimi-k2" \| "qwen/qwen3-235b-a22b-thinking-2507" \| "qwen/qwen3-coder" \| "Llama-4-Scout-17B-16E-Instruct-FP8" \| "Llama-4-Maverick-17B-128E-Instruct-FP8" \| "Llama-3.3-8B-Instruct" \| "Llama-3.3-70B-Instruct" \| "v0-1.5-md" \| "v0-1.5-lg" \| "v0-1.0-md" | No |+| model | The language model to use for evaluating the condition. | "o3-mini" \| "o3-2025-04-16" \| "o1" \| "o1-mini" \| "gpt-5.2-2025-12-11" \| "gpt-5.1-2025-11-13" \| "gpt-5-2025-08-07" \| "gpt-5-mini-2025-08-07" \| "gpt-5-nano-2025-08-07" \| "gpt-5-chat-latest" \| "gpt-4.1-2025-04-14" \| "gpt-4.1-mini-2025-04-14" \| "gpt-4o-mini" \| "gpt-4o" \| "gpt-4-turbo" \| "claude-opus-4-1-20250805" \| "claude-opus-4-20250514" \| "claude-sonnet-4-20250514" \| "claude-opus-4-5-20251101" \| "claude-sonnet-4-5-20250929" \| "claude-haiku-4-5-20251001" \| "claude-opus-4-6" \| "claude-sonnet-4-6" \| "claude-3-haiku-20240307" \| "Qwen/Qwen2.5-72B-Instruct-Turbo" \| "nvidia/llama-3.1-nemotron-70b-instruct" \| "meta-llama/Llama-3.3-70B-Instruct-Turbo" \| "meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo" \| "meta-llama/Llama-3.2-3B-Instruct-Turbo" \| "llama-3.3-70b-versatile" \| "llama-3.1-8b-instant" \| "llama3.3" \| "llama3.2" \| "llama3" \| "llama3.1:405b" \| "dolphin-mistral:latest" \| "openai/gpt-oss-120b" \| "openai/gpt-oss-20b" \| "google/gemini-2.5-pro-preview-03-25" \| "google/gemini-2.5-pro" \| "google/gemini-3.1-pro-preview" \| "google/gemini-3-flash-preview" \| "google/gemini-2.5-flash" \| "google/gemini-2.0-flash-001" \| "google/gemini-3.1-flash-lite-preview" \| "google/gemini-2.5-flash-lite-preview-06-17" \| "google/gemini-2.0-flash-lite-001" \| "mistralai/mistral-nemo" \| "mistralai/mistral-large-2512" \| "mistralai/mistral-medium-3.1" \| "mistralai/mistral-small-3.2-24b-instruct" \| "mistralai/codestral-2508" \| "cohere/command-r-08-2024" \| "cohere/command-r-plus-08-2024" \| "cohere/command-a-03-2025" \| "cohere/command-a-translate-08-2025" \| "cohere/command-a-reasoning-08-2025" \| "cohere/command-a-vision-07-2025" \| "deepseek/deepseek-chat" \| "deepseek/deepseek-r1-0528" \| "perplexity/sonar" \| "perplexity/sonar-pro" \| "perplexity/sonar-reasoning-pro" \| "perplexity/sonar-deep-research" \| "nousresearch/hermes-3-llama-3.1-405b" \| "nousresearch/hermes-3-llama-3.1-70b" \| "amazon/nova-lite-v1" \| "amazon/nova-micro-v1" \| "amazon/nova-pro-v1" \| "microsoft/wizardlm-2-8x22b" \| "microsoft/phi-4" \| "gryphe/mythomax-l2-13b" \| "meta-llama/llama-4-scout" \| "meta-llama/llama-4-maverick" \| "x-ai/grok-3" \| "x-ai/grok-4" \| "x-ai/grok-4-fast" \| "x-ai/grok-4.1-fast" \| "x-ai/grok-code-fast-1" \| "moonshotai/kimi-k2" \| "qwen/qwen3-235b-a22b-thinking-2507" \| "qwen/qwen3-coder" \| "Llama-4-Scout-17B-16E-Instruct-FP8" \| "Llama-4-Maverick-17B-128E-Instruct-FP8" \| "Llama-3.3-8B-Instruct" \| "Llama-3.3-70B-Instruct" \| "v0-1.5-md" \| "v0-1.5-lg" \| "v0-1.0-md" | No |### Outputs@@ -103,7 +103,7 @@ The block sends the entire conversation history to the chosen LLM, including sys|-------|-------------|------|----------|| prompt | The prompt to send to the language model. | str | No || messages | List of messages in the conversation. | List[Any] | Yes |-| model | The language model to use for the conversation. | "o3-mini" \| "o3-2025-04-16" \| "o1" \| "o1-mini" \| "gpt-5.2-2025-12-11" \| "gpt-5.1-2025-11-13" \| "gpt-5-2025-08-07" \| "gpt-5-mini-2025-08-07" \| "gpt-5-nano-2025-08-07" \| "gpt-5-chat-latest" \| "gpt-4.1-2025-04-14" \| "gpt-4.1-mini-2025-04-14" \| "gpt-4o-mini" \| "gpt-4o" \| "gpt-4-turbo" \| "gpt-3.5-turbo" \| "claude-opus-4-1-20250805" \| "claude-opus-4-20250514" \| "claude-sonnet-4-20250514" \| "claude-opus-4-5-20251101" \| "claude-sonnet-4-5-20250929" \| "claude-haiku-4-5-20251001" \| "claude-opus-4-6" \| "claude-sonnet-4-6" \| "claude-3-haiku-20240307" \| "Qwen/Qwen2.5-72B-Instruct-Turbo" \| "nvidia/llama-3.1-nemotron-70b-instruct" \| "meta-llama/Llama-3.3-70B-Instruct-Turbo" \| "meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo" \| "meta-llama/Llama-3.2-3B-Instruct-Turbo" \| "llama-3.3-70b-versatile" \| "llama-3.1-8b-instant" \| "llama3.3" \| "llama3.2" \| "llama3" \| "llama3.1:405b" \| "dolphin-mistral:latest" \| "openai/gpt-oss-120b" \| "openai/gpt-oss-20b" \| "google/gemini-2.5-pro-preview-03-25" \| "google/gemini-2.5-pro" \| "google/gemini-3.1-pro-preview" \| "google/gemini-3-flash-preview" \| "google/gemini-2.5-flash" \| "google/gemini-2.0-flash-001" \| "google/gemini-3.1-flash-lite-preview" \| "google/gemini-2.5-flash-lite-preview-06-17" \| "google/gemini-2.0-flash-lite-001" \| "mistralai/mistral-nemo" \| "mistralai/mistral-large-2512" \| "mistralai/mistral-medium-3.1" \| "mistralai/mistral-small-3.2-24b-instruct" \| "mistralai/codestral-2508" \| "cohere/command-r-08-2024" \| "cohere/command-r-plus-08-2024" \| "cohere/command-a-03-2025" \| "cohere/command-a-translate-08-2025" \| "cohere/command-a-reasoning-08-2025" \| "cohere/command-a-vision-07-2025" \| "deepseek/deepseek-chat" \| "deepseek/deepseek-r1-0528" \| "perplexity/sonar" \| "perplexity/sonar-pro" \| "perplexity/sonar-reasoning-pro" \| "perplexity/sonar-deep-research" \| "nousresearch/hermes-3-llama-3.1-405b" \| "nousresearch/hermes-3-llama-3.1-70b" \| "amazon/nova-lite-v1" \| "amazon/nova-micro-v1" \| "amazon/nova-pro-v1" \| "microsoft/wizardlm-2-8x22b" \| "microsoft/phi-4" \| "gryphe/mythomax-l2-13b" \| "meta-llama/llama-4-scout" \| "meta-llama/llama-4-maverick" \| "x-ai/grok-3" \| "x-ai/grok-4" \| "x-ai/grok-4-fast" \| "x-ai/grok-4.1-fast" \| "x-ai/grok-code-fast-1" \| "moonshotai/kimi-k2" \| "qwen/qwen3-235b-a22b-thinking-2507" \| "qwen/qwen3-coder" \| "Llama-4-Scout-17B-16E-Instruct-FP8" \| "Llama-4-Maverick-17B-128E-Instruct-FP8" \| "Llama-3.3-8B-Instruct" \| "Llama-3.3-70B-Instruct" \| "v0-1.5-md" \| "v0-1.5-lg" \| "v0-1.0-md" | No |+| model | The language model to use for the conversation. | "o3-mini" \| "o3-2025-04-16" \| "o1" \| "o1-mini" \| "gpt-5.2-2025-12-11" \| "gpt-5.1-2025-11-13" \| "gpt-5-2025-08-07" \| "gpt-5-mini-2025-08-07" \| "gpt-5-nano-2025-08-07" \| "gpt-5-chat-latest" \| "gpt-4.1-2025-04-14" \| "gpt-4.1-mini-2025-04-14" \| "gpt-4o-mini" \| "gpt-4o" \| "gpt-4-turbo" \| "claude-opus-4-1-20250805" \| "claude-opus-4-20250514" \| "claude-sonnet-4-20250514" \| "claude-opus-4-5-20251101" \| "claude-sonnet-4-5-20250929" \| "claude-haiku-4-5-20251001" \| "claude-opus-4-6" \| "claude-sonnet-4-6" \| "claude-3-haiku-20240307" \| "Qwen/Qwen2.5-72B-Instruct-Turbo" \| "nvidia/llama-3.1-nemotron-70b-instruct" \| "meta-llama/Llama-3.3-70B-Instruct-Turbo" \| "meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo" \| "meta-llama/Llama-3.2-3B-Instruct-Turbo" \| "llama-3.3-70b-versatile" \| "llama-3.1-8b-instant" \| "llama3.3" \| "llama3.2" \| "llama3" \| "llama3.1:405b" \| "dolphin-mistral:latest" \| "openai/gpt-oss-120b" \| "openai/gpt-oss-20b" \| "google/gemini-2.5-pro-preview-03-25" \| "google/gemini-2.5-pro" \| "google/gemini-3.1-pro-preview" \| "google/gemini-3-flash-preview" \| "google/gemini-2.5-flash" \| "google/gemini-2.0-flash-001" \| "google/gemini-3.1-flash-lite-preview" \| "google/gemini-2.5-flash-lite-preview-06-17" \| "google/gemini-2.0-flash-lite-001" \| "mistralai/mistral-nemo" \| "mistralai/mistral-large-2512" \| "mistralai/mistral-medium-3.1" \| "mistralai/mistral-small-3.2-24b-instruct" \| "mistralai/codestral-2508" \| "cohere/command-r-08-2024" \| "cohere/command-r-plus-08-2024" \| "cohere/command-a-03-2025" \| "cohere/command-a-translate-08-2025" \| "cohere/command-a-reasoning-08-2025" \| "cohere/command-a-vision-07-2025" \| "deepseek/deepseek-chat" \| "deepseek/deepseek-r1-0528" \| "perplexity/sonar" \| "perplexity/sonar-pro" \| "perplexity/sonar-reasoning-pro" \| "perplexity/sonar-deep-research" \| "nousresearch/hermes-3-llama-3.1-405b" \| "nousresearch/hermes-3-llama-3.1-70b" \| "amazon/nova-lite-v1" \| "amazon/nova-micro-v1" \| "amazon/nova-pro-v1" \| "microsoft/wizardlm-2-8x22b" \| "microsoft/phi-4" \| "gryphe/mythomax-l2-13b" \| "meta-llama/llama-4-scout" \| "meta-llama/llama-4-maverick" \| "x-ai/grok-3" \| "x-ai/grok-4" \| "x-ai/grok-4-fast" \| "x-ai/grok-4.1-fast" \| "x-ai/grok-code-fast-1" \| "moonshotai/kimi-k2" \| "qwen/qwen3-235b-a22b-thinking-2507" \| "qwen/qwen3-coder" \| "Llama-4-Scout-17B-16E-Instruct-FP8" \| "Llama-4-Maverick-17B-128E-Instruct-FP8" \| "Llama-3.3-8B-Instruct" \| "Llama-3.3-70B-Instruct" \| "v0-1.5-md" \| "v0-1.5-lg" \| "v0-1.0-md" | No || max_tokens | The maximum number of tokens to generate in the chat completion. | int | No || ollama_host | Ollama host for local models | str | No |@@ -257,7 +257,7 @@ The block formulates a prompt based on the given focus or source data, sends it|-------|-------------|------|----------|| focus | The focus of the list to generate. | str | No || source_data | The data to generate the list from. | str | No |-| model | The language model to use for generating the list. | "o3-mini" \| "o3-2025-04-16" \| "o1" \| "o1-mini" \| "gpt-5.2-2025-12-11" \| "gpt-5.1-2025-11-13" \| "gpt-5-2025-08-07" \| "gpt-5-mini-2025-08-07" \| "gpt-5-nano-2025-08-07" \| "gpt-5-chat-latest" \| "gpt-4.1-2025-04-14" \| "gpt-4.1-mini-2025-04-14" \| "gpt-4o-mini" \| "gpt-4o" \| "gpt-4-turbo" \| "gpt-3.5-turbo" \| "claude-opus-4-1-20250805" \| "claude-opus-4-20250514" \| "claude-sonnet-4-20250514" \| "claude-opus-4-5-20251101" \| "claude-sonnet-4-5-20250929" \| "claude-haiku-4-5-20251001" \| "claude-opus-4-6" \| "claude-sonnet-4-6" \| "claude-3-haiku-20240307" \| "Qwen/Qwen2.5-72B-Instruct-Turbo" \| "nvidia/llama-3.1-nemotron-70b-instruct" \| "meta-llama/Llama-3.3-70B-Instruct-Turbo" \| "meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo" \| "meta-llama/Llama-3.2-3B-Instruct-Turbo" \| "llama-3.3-70b-versatile" \| "llama-3.1-8b-instant" \| "llama3.3" \| "llama3.2" \| "llama3" \| "llama3.1:405b" \| "dolphin-mistral:latest" \| "openai/gpt-oss-120b" \| "openai/gpt-oss-20b" \| "google/gemini-2.5-pro-preview-03-25" \| "google/gemini-2.5-pro" \| "google/gemini-3.1-pro-preview" \| "google/gemini-3-flash-preview" \| "google/gemini-2.5-flash" \| "google/gemini-2.0-flash-001" \| "google/gemini-3.1-flash-lite-preview" \| "google/gemini-2.5-flash-lite-preview-06-17" \| "google/gemini-2.0-flash-lite-001" \| "mistralai/mistral-nemo" \| "mistralai/mistral-large-2512" \| "mistralai/mistral-medium-3.1" \| "mistralai/mistral-small-3.2-24b-instruct" \| "mistralai/codestral-2508" \| "cohere/command-r-08-2024" \| "cohere/command-r-plus-08-2024" \| "cohere/command-a-03-2025" \| "cohere/command-a-translate-08-2025" \| "cohere/command-a-reasoning-08-2025" \| "cohere/command-a-vision-07-2025" \| "deepseek/deepseek-chat" \| "deepseek/deepseek-r1-0528" \| "perplexity/sonar" \| "perplexity/sonar-pro" \| "perplexity/sonar-reasoning-pro" \| "perplexity/sonar-deep-research" \| "nousresearch/hermes-3-llama-3.1-405b" \| "nousresearch/hermes-3-llama-3.1-70b" \| "amazon/nova-lite-v1" \| "amazon/nova-micro-v1" \| "amazon/nova-pro-v1" \| "microsoft/wizardlm-2-8x22b" \| "microsoft/phi-4" \| "gryphe/mythomax-l2-13b" \| "meta-llama/llama-4-scout" \| "meta-llama/llama-4-maverick" \| "x-ai/grok-3" \| "x-ai/grok-4" \| "x-ai/grok-4-fast" \| "x-ai/grok-4.1-fast" \| "x-ai/grok-code-fast-1" \| "moonshotai/kimi-k2" \| "qwen/qwen3-235b-a22b-thinking-2507" \| "qwen/qwen3-coder" \| "Llama-4-Scout-17B-16E-Instruct-FP8" \| "Llama-4-Maverick-17B-128E-Instruct-FP8" \| "Llama-3.3-8B-Instruct" \| "Llama-3.3-70B-Instruct" \| "v0-1.5-md" \| "v0-1.5-lg" \| "v0-1.0-md" | No |+| model | The language model to use for generating the list. | "o3-mini" \| "o3-2025-04-16" \| "o1" \| "o1-mini" \| "gpt-5.2-2025-12-11" \| "gpt-5.1-2025-11-13" \| "gpt-5-2025-08-07" \| "gpt-5-mini-2025-08-07" \| "gpt-5-nano-2025-08-07" \| "gpt-5-chat-latest" \| "gpt-4.1-2025-04-14" \| "gpt-4.1-mini-2025-04-14" \| "gpt-4o-mini" \| "gpt-4o" \| "gpt-4-turbo" \| "claude-opus-4-1-20250805" \| "claude-opus-4-20250514" \| "claude-sonnet-4-20250514" \| "claude-opus-4-5-20251101" \| "claude-sonnet-4-5-20250929" \| "claude-haiku-4-5-20251001" \| "claude-opus-4-6" \| "claude-sonnet-4-6" \| "claude-3-haiku-20240307" \| "Qwen/Qwen2.5-72B-Instruct-Turbo" \| "nvidia/llama-3.1-nemotron-70b-instruct" \| "meta-llama/Llama-3.3-70B-Instruct-Turbo" \| "meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo" \| "meta-llama/Llama-3.2-3B-Instruct-Turbo" \| "llama-3.3-70b-versatile" \| "llama-3.1-8b-instant" \| "llama3.3" \| "llama3.2" \| "llama3" \| "llama3.1:405b" \| "dolphin-mistral:latest" \| "openai/gpt-oss-120b" \| "openai/gpt-oss-20b" \| "google/gemini-2.5-pro-preview-03-25" \| "google/gemini-2.5-pro" \| "google/gemini-3.1-pro-preview" \| "google/gemini-3-flash-preview" \| "google/gemini-2.5-flash" \| "google/gemini-2.0-flash-001" \| "google/gemini-3.1-flash-lite-preview" \| "google/gemini-2.5-flash-lite-preview-06-17" \| "google/gemini-2.0-flash-lite-001" \| "mistralai/mistral-nemo" \| "mistralai/mistral-large-2512" \| "mistralai/mistral-medium-3.1" \| "mistralai/mistral-small-3.2-24b-instruct" \| "mistralai/codestral-2508" \| "cohere/command-r-08-2024" \| "cohere/command-r-plus-08-2024" \| "cohere/command-a-03-2025" \| "cohere/command-a-translate-08-2025" \| "cohere/command-a-reasoning-08-2025" \| "cohere/command-a-vision-07-2025" \| "deepseek/deepseek-chat" \| "deepseek/deepseek-r1-0528" \| "perplexity/sonar" \| "perplexity/sonar-pro" \| "perplexity/sonar-reasoning-pro" \| "perplexity/sonar-deep-research" \| "nousresearch/hermes-3-llama-3.1-405b" \| "nousresearch/hermes-3-llama-3.1-70b" \| "amazon/nova-lite-v1" \| "amazon/nova-micro-v1" \| "amazon/nova-pro-v1" \| "microsoft/wizardlm-2-8x22b" \| "microsoft/phi-4" \| "gryphe/mythomax-l2-13b" \| "meta-llama/llama-4-scout" \| "meta-llama/llama-4-maverick" \| "x-ai/grok-3" \| "x-ai/grok-4" \| "x-ai/grok-4-fast" \| "x-ai/grok-4.1-fast" \| "x-ai/grok-code-fast-1" \| "moonshotai/kimi-k2" \| "qwen/qwen3-235b-a22b-thinking-2507" \| "qwen/qwen3-coder" \| "Llama-4-Scout-17B-16E-Instruct-FP8" \| "Llama-4-Maverick-17B-128E-Instruct-FP8" \| "Llama-3.3-8B-Instruct" \| "Llama-3.3-70B-Instruct" \| "v0-1.5-md" \| "v0-1.5-lg" \| "v0-1.0-md" | No || max_retries | Maximum number of retries for generating a valid list. | int | No || force_json_output | Whether to force the LLM to produce a JSON-only response. This can increase the block's reliability, but may also reduce the quality of the response because it prohibits the LLM from reasoning before providing its JSON response. | bool | No || max_tokens | The maximum number of tokens to generate in the chat completion. | int | No |@@ -424,7 +424,7 @@ The block sends the input prompt to a chosen LLM, along with any system prompts| prompt | The prompt to send to the language model. | str | Yes || expected_format | Expected format of the response. If provided, the response will be validated against this format. The keys should be the expected fields in the response, and the values should be the description of the field. | Dict[str, str] | Yes || list_result | Whether the response should be a list of objects in the expected format. | bool | No |-| model | The language model to use for answering the prompt. | "o3-mini" \| "o3-2025-04-16" \| "o1" \| "o1-mini" \| "gpt-5.2-2025-12-11" \| "gpt-5.1-2025-11-13" \| "gpt-5-2025-08-07" \| "gpt-5-mini-2025-08-07" \| "gpt-5-nano-2025-08-07" \| "gpt-5-chat-latest" \| "gpt-4.1-2025-04-14" \| "gpt-4.1-mini-2025-04-14" \| "gpt-4o-mini" \| "gpt-4o" \| "gpt-4-turbo" \| "gpt-3.5-turbo" \| "claude-opus-4-1-20250805" \| "claude-opus-4-20250514" \| "claude-sonnet-4-20250514" \| "claude-opus-4-5-20251101" \| "claude-sonnet-4-5-20250929" \| "claude-haiku-4-5-20251001" \| "claude-opus-4-6" \| "claude-sonnet-4-6" \| "claude-3-haiku-20240307" \| "Qwen/Qwen2.5-72B-Instruct-Turbo" \| "nvidia/llama-3.1-nemotron-70b-instruct" \| "meta-llama/Llama-3.3-70B-Instruct-Turbo" \| "meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo" \| "meta-llama/Llama-3.2-3B-Instruct-Turbo" \| "llama-3.3-70b-versatile" \| "llama-3.1-8b-instant" \| "llama3.3" \| "llama3.2" \| "llama3" \| "llama3.1:405b" \| "dolphin-mistral:latest" \| "openai/gpt-oss-120b" \| "openai/gpt-oss-20b" \| "google/gemini-2.5-pro-preview-03-25" \| "google/gemini-2.5-pro" \| "google/gemini-3.1-pro-preview" \| "google/gemini-3-flash-preview" \| "google/gemini-2.5-flash" \| "google/gemini-2.0-flash-001" \| "google/gemini-3.1-flash-lite-preview" \| "google/gemini-2.5-flash-lite-preview-06-17" \| "google/gemini-2.0-flash-lite-001" \| "mistralai/mistral-nemo" \| "mistralai/mistral-large-2512" \| "mistralai/mistral-medium-3.1" \| "mistralai/mistral-small-3.2-24b-instruct" \| "mistralai/codestral-2508" \| "cohere/command-r-08-2024" \| "cohere/command-r-plus-08-2024" \| "cohere/command-a-03-2025" \| "cohere/command-a-translate-08-2025" \| "cohere/command-a-reasoning-08-2025" \| "cohere/command-a-vision-07-2025" \| "deepseek/deepseek-chat" \| "deepseek/deepseek-r1-0528" \| "perplexity/sonar" \| "perplexity/sonar-pro" \| "perplexity/sonar-reasoning-pro" \| "perplexity/sonar-deep-research" \| "nousresearch/hermes-3-llama-3.1-405b" \| "nousresearch/hermes-3-llama-3.1-70b" \| "amazon/nova-lite-v1" \| "amazon/nova-micro-v1" \| "amazon/nova-pro-v1" \| "microsoft/wizardlm-2-8x22b" \| "microsoft/phi-4" \| "gryphe/mythomax-l2-13b" \| "meta-llama/llama-4-scout" \| "meta-llama/llama-4-maverick" \| "x-ai/grok-3" \| "x-ai/grok-4" \| "x-ai/grok-4-fast" \| "x-ai/grok-4.1-fast" \| "x-ai/grok-code-fast-1" \| "moonshotai/kimi-k2" \| "qwen/qwen3-235b-a22b-thinking-2507" \| "qwen/qwen3-coder" \| "Llama-4-Scout-17B-16E-Instruct-FP8" \| "Llama-4-Maverick-17B-128E-Instruct-FP8" \| "Llama-3.3-8B-Instruct" \| "Llama-3.3-70B-Instruct" \| "v0-1.5-md" \| "v0-1.5-lg" \| "v0-1.0-md" | No |+| model | The language model to use for answering the prompt. | "o3-mini" \| "o3-2025-04-16" \| "o1" \| "o1-mini" \| "gpt-5.2-2025-12-11" \| "gpt-5.1-2025-11-13" \| "gpt-5-2025-08-07" \| "gpt-5-mini-2025-08-07" \| "gpt-5-nano-2025-08-07" \| "gpt-5-chat-latest" \| "gpt-4.1-2025-04-14" \| "gpt-4.1-mini-2025-04-14" \| "gpt-4o-mini" \| "gpt-4o" \| "gpt-4-turbo" \| "claude-opus-4-1-20250805" \| "claude-opus-4-20250514" \| "claude-sonnet-4-20250514" \| "claude-opus-4-5-20251101" \| "claude-sonnet-4-5-20250929" \| "claude-haiku-4-5-20251001" \| "claude-opus-4-6" \| "claude-sonnet-4-6" \| "claude-3-haiku-20240307" \| "Qwen/Qwen2.5-72B-Instruct-Turbo" \| "nvidia/llama-3.1-nemotron-70b-instruct" \| "meta-llama/Llama-3.3-70B-Instruct-Turbo" \| "meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo" \| "meta-llama/Llama-3.2-3B-Instruct-Turbo" \| "llama-3.3-70b-versatile" \| "llama-3.1-8b-instant" \| "llama3.3" \| "llama3.2" \| "llama3" \| "llama3.1:405b" \| "dolphin-mistral:latest" \| "openai/gpt-oss-120b" \| "openai/gpt-oss-20b" \| "google/gemini-2.5-pro-preview-03-25" \| "google/gemini-2.5-pro" \| "google/gemini-3.1-pro-preview" \| "google/gemini-3-flash-preview" \| "google/gemini-2.5-flash" \| "google/gemini-2.0-flash-001" \| "google/gemini-3.1-flash-lite-preview" \| "google/gemini-2.5-flash-lite-preview-06-17" \| "google/gemini-2.0-flash-lite-001" \| "mistralai/mistral-nemo" \| "mistralai/mistral-large-2512" \| "mistralai/mistral-medium-3.1" \| "mistralai/mistral-small-3.2-24b-instruct" \| "mistralai/codestral-2508" \| "cohere/command-r-08-2024" \| "cohere/command-r-plus-08-2024" \| "cohere/command-a-03-2025" \| "cohere/command-a-translate-08-2025" \| "cohere/command-a-reasoning-08-2025" \| "cohere/command-a-vision-07-2025" \| "deepseek/deepseek-chat" \| "deepseek/deepseek-r1-0528" \| "perplexity/sonar" \| "perplexity/sonar-pro" \| "perplexity/sonar-reasoning-pro" \| "perplexity/sonar-deep-research" \| "nousresearch/hermes-3-llama-3.1-405b" \| "nousresearch/hermes-3-llama-3.1-70b" \| "amazon/nova-lite-v1" \| "amazon/nova-micro-v1" \| "amazon/nova-pro-v1" \| "microsoft/wizardlm-2-8x22b" \| "microsoft/phi-4" \| "gryphe/mythomax-l2-13b" \| "meta-llama/llama-4-scout" \| "meta-llama/llama-4-maverick" \| "x-ai/grok-3" \| "x-ai/grok-4" \| "x-ai/grok-4-fast" \| "x-ai/grok-4.1-fast" \| "x-ai/grok-code-fast-1" \| "moonshotai/kimi-k2" \| "qwen/qwen3-235b-a22b-thinking-2507" \| "qwen/qwen3-coder" \| "Llama-4-Scout-17B-16E-Instruct-FP8" \| "Llama-4-Maverick-17B-128E-Instruct-FP8" \| "Llama-3.3-8B-Instruct" \| "Llama-3.3-70B-Instruct" \| "v0-1.5-md" \| "v0-1.5-lg" \| "v0-1.0-md" | No || force_json_output | Whether to force the LLM to produce a JSON-only response. This can increase the block's reliability, but may also reduce the quality of the response because it prohibits the LLM from reasoning before providing its JSON response. | bool | No || sys_prompt | The system prompt to provide additional context to the model. | str | No || conversation_history | The conversation history to provide context for the prompt. | List[Dict[str, Any]] | No |@@ -464,7 +464,7 @@ The block sends the input prompt to a chosen LLM, processes the response, and re| Input | Description | Type | Required ||-------|-------------|------|----------|| prompt | The prompt to send to the language model. You can use any of the {keys} from Prompt Values to fill in the prompt with values from the prompt values dictionary by putting them in curly braces. | str | Yes |-| model | The language model to use for answering the prompt. | "o3-mini" \| "o3-2025-04-16" \| "o1" \| "o1-mini" \| "gpt-5.2-2025-12-11" \| "gpt-5.1-2025-11-13" \| "gpt-5-2025-08-07" \| "gpt-5-mini-2025-08-07" \| "gpt-5-nano-2025-08-07" \| "gpt-5-chat-latest" \| "gpt-4.1-2025-04-14" \| "gpt-4.1-mini-2025-04-14" \| "gpt-4o-mini" \| "gpt-4o" \| "gpt-4-turbo" \| "gpt-3.5-turbo" \| "claude-opus-4-1-20250805" \| "claude-opus-4-20250514" \| "claude-sonnet-4-20250514" \| "claude-opus-4-5-20251101" \| "claude-sonnet-4-5-20250929" \| "claude-haiku-4-5-20251001" \| "claude-opus-4-6" \| "claude-sonnet-4-6" \| "claude-3-haiku-20240307" \| "Qwen/Qwen2.5-72B-Instruct-Turbo" \| "nvidia/llama-3.1-nemotron-70b-instruct" \| "meta-llama/Llama-3.3-70B-Instruct-Turbo" \| "meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo" \| "meta-llama/Llama-3.2-3B-Instruct-Turbo" \| "llama-3.3-70b-versatile" \| "llama-3.1-8b-instant" \| "llama3.3" \| "llama3.2" \| "llama3" \| "llama3.1:405b" \| "dolphin-mistral:latest" \| "openai/gpt-oss-120b" \| "openai/gpt-oss-20b" \| "google/gemini-2.5-pro-preview-03-25" \| "google/gemini-2.5-pro" \| "google/gemini-3.1-pro-preview" \| "google/gemini-3-flash-preview" \| "google/gemini-2.5-flash" \| "google/gemini-2.0-flash-001" \| "google/gemini-3.1-flash-lite-preview" \| "google/gemini-2.5-flash-lite-preview-06-17" \| "google/gemini-2.0-flash-lite-001" \| "mistralai/mistral-nemo" \| "mistralai/mistral-large-2512" \| "mistralai/mistral-medium-3.1" \| "mistralai/mistral-small-3.2-24b-instruct" \| "mistralai/codestral-2508" \| "cohere/command-r-08-2024" \| "cohere/command-r-plus-08-2024" \| "cohere/command-a-03-2025" \| "cohere/command-a-translate-08-2025" \| "cohere/command-a-reasoning-08-2025" \| "cohere/command-a-vision-07-2025" \| "deepseek/deepseek-chat" \| "deepseek/deepseek-r1-0528" \| "perplexity/sonar" \| "perplexity/sonar-pro" \| "perplexity/sonar-reasoning-pro" \| "perplexity/sonar-deep-research" \| "nousresearch/hermes-3-llama-3.1-405b" \| "nousresearch/hermes-3-llama-3.1-70b" \| "amazon/nova-lite-v1" \| "amazon/nova-micro-v1" \| "amazon/nova-pro-v1" \| "microsoft/wizardlm-2-8x22b" \| "microsoft/phi-4" \| "gryphe/mythomax-l2-13b" \| "meta-llama/llama-4-scout" \| "meta-llama/llama-4-maverick" \| "x-ai/grok-3" \| "x-ai/grok-4" \| "x-ai/grok-4-fast" \| "x-ai/grok-4.1-fast" \| "x-ai/grok-code-fast-1" \| "moonshotai/kimi-k2" \| "qwen/qwen3-235b-a22b-thinking-2507" \| "qwen/qwen3-coder" \| "Llama-4-Scout-17B-16E-Instruct-FP8" \| "Llama-4-Maverick-17B-128E-Instruct-FP8" \| "Llama-3.3-8B-Instruct" \| "Llama-3.3-70B-Instruct" \| "v0-1.5-md" \| "v0-1.5-lg" \| "v0-1.0-md" | No |+| model | The language model to use for answering the prompt. | "o3-mini" \| "o3-2025-04-16" \| "o1" \| "o1-mini" \| "gpt-5.2-2025-12-11" \| "gpt-5.1-2025-11-13" \| "gpt-5-2025-08-07" \| "gpt-5-mini-2025-08-07" \| "gpt-5-nano-2025-08-07" \| "gpt-5-chat-latest" \| "gpt-4.1-2025-04-14" \| "gpt-4.1-mini-2025-04-14" \| "gpt-4o-mini" \| "gpt-4o" \| "gpt-4-turbo" \| "claude-opus-4-1-20250805" \| "claude-opus-4-20250514" \| "claude-sonnet-4-20250514" \| "claude-opus-4-5-20251101" \| "claude-sonnet-4-5-20250929" \| "claude-haiku-4-5-20251001" \| "claude-opus-4-6" \| "claude-sonnet-4-6" \| "claude-3-haiku-20240307" \| "Qwen/Qwen2.5-72B-Instruct-Turbo" \| "nvidia/llama-3.1-nemotron-70b-instruct" \| "meta-llama/Llama-3.3-70B-Instruct-Turbo" \| "meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo" \| "meta-llama/Llama-3.2-3B-Instruct-Turbo" \| "llama-3.3-70b-versatile" \| "llama-3.1-8b-instant" \| "llama3.3" \| "llama3.2" \| "llama3" \| "llama3.1:405b" \| "dolphin-mistral:latest" \| "openai/gpt-oss-120b" \| "openai/gpt-oss-20b" \| "google/gemini-2.5-pro-preview-03-25" \| "google/gemini-2.5-pro" \| "google/gemini-3.1-pro-preview" \| "google/gemini-3-flash-preview" \| "google/gemini-2.5-flash" \| "google/gemini-2.0-flash-001" \| "google/gemini-3.1-flash-lite-preview" \| "google/gemini-2.5-flash-lite-preview-06-17" \| "google/gemini-2.0-flash-lite-001" \| "mistralai/mistral-nemo" \| "mistralai/mistral-large-2512" \| "mistralai/mistral-medium-3.1" \| "mistralai/mistral-small-3.2-24b-instruct" \| "mistralai/codestral-2508" \| "cohere/command-r-08-2024" \| "cohere/command-r-plus-08-2024" \| "cohere/command-a-03-2025" \| "cohere/command-a-translate-08-2025" \| "cohere/command-a-reasoning-08-2025" \| "cohere/command-a-vision-07-2025" \| "deepseek/deepseek-chat" \| "deepseek/deepseek-r1-0528" \| "perplexity/sonar" \| "perplexity/sonar-pro" \| "perplexity/sonar-reasoning-pro" \| "perplexity/sonar-deep-research" \| "nousresearch/hermes-3-llama-3.1-405b" \| "nousresearch/hermes-3-llama-3.1-70b" \| "amazon/nova-lite-v1" \| "amazon/nova-micro-v1" \| "amazon/nova-pro-v1" \| "microsoft/wizardlm-2-8x22b" \| "microsoft/phi-4" \| "gryphe/mythomax-l2-13b" \| "meta-llama/llama-4-scout" \| "meta-llama/llama-4-maverick" \| "x-ai/grok-3" \| "x-ai/grok-4" \| "x-ai/grok-4-fast" \| "x-ai/grok-4.1-fast" \| "x-ai/grok-code-fast-1" \| "moonshotai/kimi-k2" \| "qwen/qwen3-235b-a22b-thinking-2507" \| "qwen/qwen3-coder" \| "Llama-4-Scout-17B-16E-Instruct-FP8" \| "Llama-4-Maverick-17B-128E-Instruct-FP8" \| "Llama-3.3-8B-Instruct" \| "Llama-3.3-70B-Instruct" \| "v0-1.5-md" \| "v0-1.5-lg" \| "v0-1.0-md" | No || sys_prompt | The system prompt to provide additional context to the model. | str | No || retry | Number of times to retry the LLM call if the response does not match the expected format. | int | No || prompt_values | Values used to fill in the prompt. The values can be used in the prompt by putting them in a double curly braces, e.g. {{variable_name}}. | Dict[str, str] | No |@@ -501,7 +501,7 @@ The block splits the input text into smaller chunks, sends each chunk to an LLM| Input | Description | Type | Required ||-------|-------------|------|----------|| text | The text to summarize. | str | Yes |-| model | The language model to use for summarizing the text. | "o3-mini" \| "o3-2025-04-16" \| "o1" \| "o1-mini" \| "gpt-5.2-2025-12-11" \| "gpt-5.1-2025-11-13" \| "gpt-5-2025-08-07" \| "gpt-5-mini-2025-08-07" \| "gpt-5-nano-2025-08-07" \| "gpt-5-chat-latest" \| "gpt-4.1-2025-04-14" \| "gpt-4.1-mini-2025-04-14" \| "gpt-4o-mini" \| "gpt-4o" \| "gpt-4-turbo" \| "gpt-3.5-turbo" \| "claude-opus-4-1-20250805" \| "claude-opus-4-20250514" \| "claude-sonnet-4-20250514" \| "claude-opus-4-5-20251101" \| "claude-sonnet-4-5-20250929" \| "claude-haiku-4-5-20251001" \| "claude-opus-4-6" \| "claude-sonnet-4-6" \| "claude-3-haiku-20240307" \| "Qwen/Qwen2.5-72B-Instruct-Turbo" \| "nvidia/llama-3.1-nemotron-70b-instruct" \| "meta-llama/Llama-3.3-70B-Instruct-Turbo" \| "meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo" \| "meta-llama/Llama-3.2-3B-Instruct-Turbo" \| "llama-3.3-70b-versatile" \| "llama-3.1-8b-instant" \| "llama3.3" \| "llama3.2" \| "llama3" \| "llama3.1:405b" \| "dolphin-mistral:latest" \| "openai/gpt-oss-120b" \| "openai/gpt-oss-20b" \| "google/gemini-2.5-pro-preview-03-25" \| "google/gemini-2.5-pro" \| "google/gemini-3.1-pro-preview" \| "google/gemini-3-flash-preview" \| "google/gemini-2.5-flash" \| "google/gemini-2.0-flash-001" \| "google/gemini-3.1-flash-lite-preview" \| "google/gemini-2.5-flash-lite-preview-06-17" \| "google/gemini-2.0-flash-lite-001" \| "mistralai/mistral-nemo" \| "mistralai/mistral-large-2512" \| "mistralai/mistral-medium-3.1" \| "mistralai/mistral-small-3.2-24b-instruct" \| "mistralai/codestral-2508" \| "cohere/command-r-08-2024" \| "cohere/command-r-plus-08-2024" \| "cohere/command-a-03-2025" \| "cohere/command-a-translate-08-2025" \| "cohere/command-a-reasoning-08-2025" \| "cohere/command-a-vision-07-2025" \| "deepseek/deepseek-chat" \| "deepseek/deepseek-r1-0528" \| "perplexity/sonar" \| "perplexity/sonar-pro" \| "perplexity/sonar-reasoning-pro" \| "perplexity/sonar-deep-research" \| "nousresearch/hermes-3-llama-3.1-405b" \| "nousresearch/hermes-3-llama-3.1-70b" \| "amazon/nova-lite-v1" \| "amazon/nova-micro-v1" \| "amazon/nova-pro-v1" \| "microsoft/wizardlm-2-8x22b" \| "microsoft/phi-4" \| "gryphe/mythomax-l2-13b" \| "meta-llama/llama-4-scout" \| "meta-llama/llama-4-maverick" \| "x-ai/grok-3" \| "x-ai/grok-4" \| "x-ai/grok-4-fast" \| "x-ai/grok-4.1-fast" \| "x-ai/grok-code-fast-1" \| "moonshotai/kimi-k2" \| "qwen/qwen3-235b-a22b-thinking-2507" \| "qwen/qwen3-coder" \| "Llama-4-Scout-17B-16E-Instruct-FP8" \| "Llama-4-Maverick-17B-128E-Instruct-FP8" \| "Llama-3.3-8B-Instruct" \| "Llama-3.3-70B-Instruct" \| "v0-1.5-md" \| "v0-1.5-lg" \| "v0-1.0-md" | No |+| model | The language model to use for summarizing the text. | "o3-mini" \| "o3-2025-04-16" \| "o1" \| "o1-mini" \| "gpt-5.2-2025-12-11" \| "gpt-5.1-2025-11-13" \| "gpt-5-2025-08-07" \| "gpt-5-mini-2025-08-07" \| "gpt-5-nano-2025-08-07" \| "gpt-5-chat-latest" \| "gpt-4.1-2025-04-14" \| "gpt-4.1-mini-2025-04-14" \| "gpt-4o-mini" \| "gpt-4o" \| "gpt-4-turbo" \| "claude-opus-4-1-20250805" \| "claude-opus-4-20250514" \| "claude-sonnet-4-20250514" \| "claude-opus-4-5-20251101" \| "claude-sonnet-4-5-20250929" \| "claude-haiku-4-5-20251001" \| "claude-opus-4-6" \| "claude-sonnet-4-6" \| "claude-3-haiku-20240307" \| "Qwen/Qwen2.5-72B-Instruct-Turbo" \| "nvidia/llama-3.1-nemotron-70b-instruct" \| "meta-llama/Llama-3.3-70B-Instruct-Turbo" \| "meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo" \| "meta-llama/Llama-3.2-3B-Instruct-Turbo" \| "llama-3.3-70b-versatile" \| "llama-3.1-8b-instant" \| "llama3.3" \| "llama3.2" \| "llama3" \| "llama3.1:405b" \| "dolphin-mistral:latest" \| "openai/gpt-oss-120b" \| "openai/gpt-oss-20b" \| "google/gemini-2.5-pro-preview-03-25" \| "google/gemini-2.5-pro" \| "google/gemini-3.1-pro-preview" \| "google/gemini-3-flash-preview" \| "google/gemini-2.5-flash" \| "google/gemini-2.0-flash-001" \| "google/gemini-3.1-flash-lite-preview" \| "google/gemini-2.5-flash-lite-preview-06-17" \| "google/gemini-2.0-flash-lite-001" \| "mistralai/mistral-nemo" \| "mistralai/mistral-large-2512" \| "mistralai/mistral-medium-3.1" \| "mistralai/mistral-small-3.2-24b-instruct" \| "mistralai/codestral-2508" \| "cohere/command-r-08-2024" \| "cohere/command-r-plus-08-2024" \| "cohere/command-a-03-2025" \| "cohere/command-a-translate-08-2025" \| "cohere/command-a-reasoning-08-2025" \| "cohere/command-a-vision-07-2025" \| "deepseek/deepseek-chat" \| "deepseek/deepseek-r1-0528" \| "perplexity/sonar" \| "perplexity/sonar-pro" \| "perplexity/sonar-reasoning-pro" \| "perplexity/sonar-deep-research" \| "nousresearch/hermes-3-llama-3.1-405b" \| "nousresearch/hermes-3-llama-3.1-70b" \| "amazon/nova-lite-v1" \| "amazon/nova-micro-v1" \| "amazon/nova-pro-v1" \| "microsoft/wizardlm-2-8x22b" \| "microsoft/phi-4" \| "gryphe/mythomax-l2-13b" \| "meta-llama/llama-4-scout" \| "meta-llama/llama-4-maverick" \| "x-ai/grok-3" \| "x-ai/grok-4" \| "x-ai/grok-4-fast" \| "x-ai/grok-4.1-fast" \| "x-ai/grok-code-fast-1" \| "moonshotai/kimi-k2" \| "qwen/qwen3-235b-a22b-thinking-2507" \| "qwen/qwen3-coder" \| "Llama-4-Scout-17B-16E-Instruct-FP8" \| "Llama-4-Maverick-17B-128E-Instruct-FP8" \| "Llama-3.3-8B-Instruct" \| "Llama-3.3-70B-Instruct" \| "v0-1.5-md" \| "v0-1.5-lg" \| "v0-1.0-md" | No || focus | The topic to focus on in the summary | str | No || style | The style of the summary to generate. | "concise" \| "detailed" \| "bullet points" \| "numbered list" | No || max_tokens | The maximum number of tokens to generate in the chat completion. | int | No |@@ -763,7 +763,7 @@ Configure agent_mode_max_iterations to control loop behavior: 0 for single decis| Input | Description | Type | Required ||-------|-------------|------|----------|| prompt | The prompt to send to the language model. | str | Yes |-| model | The language model to use for answering the prompt. | "o3-mini" \| "o3-2025-04-16" \| "o1" \| "o1-mini" \| "gpt-5.2-2025-12-11" \| "gpt-5.1-2025-11-13" \| "gpt-5-2025-08-07" \| "gpt-5-mini-2025-08-07" \| "gpt-5-nano-2025-08-07" \| "gpt-5-chat-latest" \| "gpt-4.1-2025-04-14" \| "gpt-4.1-mini-2025-04-14" \| "gpt-4o-mini" \| "gpt-4o" \| "gpt-4-turbo" \| "gpt-3.5-turbo" \| "claude-opus-4-1-20250805" \| "claude-opus-4-20250514" \| "claude-sonnet-4-20250514" \| "claude-opus-4-5-20251101" \| "claude-sonnet-4-5-20250929" \| "claude-haiku-4-5-20251001" \| "claude-opus-4-6" \| "claude-sonnet-4-6" \| "claude-3-haiku-20240307" \| "Qwen/Qwen2.5-72B-Instruct-Turbo" \| "nvidia/llama-3.1-nemotron-70b-instruct" \| "meta-llama/Llama-3.3-70B-Instruct-Turbo" \| "meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo" \| "meta-llama/Llama-3.2-3B-Instruct-Turbo" \| "llama-3.3-70b-versatile" \| "llama-3.1-8b-instant" \| "llama3.3" \| "llama3.2" \| "llama3" \| "llama3.1:405b" \| "dolphin-mistral:latest" \| "openai/gpt-oss-120b" \| "openai/gpt-oss-20b" \| "google/gemini-2.5-pro-preview-03-25" \| "google/gemini-2.5-pro" \| "google/gemini-3.1-pro-preview" \| "google/gemini-3-flash-preview" \| "google/gemini-2.5-flash" \| "google/gemini-2.0-flash-001" \| "google/gemini-3.1-flash-lite-preview" \| "google/gemini-2.5-flash-lite-preview-06-17" \| "google/gemini-2.0-flash-lite-001" \| "mistralai/mistral-nemo" \| "mistralai/mistral-large-2512" \| "mistralai/mistral-medium-3.1" \| "mistralai/mistral-small-3.2-24b-instruct" \| "mistralai/codestral-2508" \| "cohere/command-r-08-2024" \| "cohere/command-r-plus-08-2024" \| "cohere/command-a-03-2025" \| "cohere/command-a-translate-08-2025" \| "cohere/command-a-reasoning-08-2025" \| "cohere/command-a-vision-07-2025" \| "deepseek/deepseek-chat" \| "deepseek/deepseek-r1-0528" \| "perplexity/sonar" \| "perplexity/sonar-pro" \| "perplexity/sonar-reasoning-pro" \| "perplexity/sonar-deep-research" \| "nousresearch/hermes-3-llama-3.1-405b" \| "nousresearch/hermes-3-llama-3.1-70b" \| "amazon/nova-lite-v1" \| "amazon/nova-micro-v1" \| "amazon/nova-pro-v1" \| "microsoft/wizardlm-2-8x22b" \| "microsoft/phi-4" \| "gryphe/mythomax-l2-13b" \| "meta-llama/llama-4-scout" \| "meta-llama/llama-4-maverick" \| "x-ai/grok-3" \| "x-ai/grok-4" \| "x-ai/grok-4-fast" \| "x-ai/grok-4.1-fast" \| "x-ai/grok-code-fast-1" \| "moonshotai/kimi-k2" \| "qwen/qwen3-235b-a22b-thinking-2507" \| "qwen/qwen3-coder" \| "Llama-4-Scout-17B-16E-Instruct-FP8" \| "Llama-4-Maverick-17B-128E-Instruct-FP8" \| "Llama-3.3-8B-Instruct" \| "Llama-3.3-70B-Instruct" \| "v0-1.5-md" \| "v0-1.5-lg" \| "v0-1.0-md" | No |+| model | The language model to use for answering the prompt. | "o3-mini" \| "o3-2025-04-16" \| "o1" \| "o1-mini" \| "gpt-5.2-2025-12-11" \| "gpt-5.1-2025-11-13" \| "gpt-5-2025-08-07" \| "gpt-5-mini-2025-08-07" \| "gpt-5-nano-2025-08-07" \| "gpt-5-chat-latest" \| "gpt-4.1-2025-04-14" \| "gpt-4.1-mini-2025-04-14" \| "gpt-4o-mini" \| "gpt-4o" \| "gpt-4-turbo" \| "claude-opus-4-1-20250805" \| "claude-opus-4-20250514" \| "claude-sonnet-4-20250514" \| "claude-opus-4-5-20251101" \| "claude-sonnet-4-5-20250929" \| "claude-haiku-4-5-20251001" \| "claude-opus-4-6" \| "claude-sonnet-4-6" \| "claude-3-haiku-20240307" \| "Qwen/Qwen2.5-72B-Instruct-Turbo" \| "nvidia/llama-3.1-nemotron-70b-instruct" \| "meta-llama/Llama-3.3-70B-Instruct-Turbo" \| "meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo" \| "meta-llama/Llama-3.2-3B-Instruct-Turbo" \| "llama-3.3-70b-versatile" \| "llama-3.1-8b-instant" \| "llama3.3" \| "llama3.2" \| "llama3" \| "llama3.1:405b" \| "dolphin-mistral:latest" \| "openai/gpt-oss-120b" \| "openai/gpt-oss-20b" \| "google/gemini-2.5-pro-preview-03-25" \| "google/gemini-2.5-pro" \| "google/gemini-3.1-pro-preview" \| "google/gemini-3-flash-preview" \| "google/gemini-2.5-flash" \| "google/gemini-2.0-flash-001" \| "google/gemini-3.1-flash-lite-preview" \| "google/gemini-2.5-flash-lite-preview-06-17" \| "google/gemini-2.0-flash-lite-001" \| "mistralai/mistral-nemo" \| "mistralai/mistral-large-2512" \| "mistralai/mistral-medium-3.1" \| "mistralai/mistral-small-3.2-24b-instruct" \| "mistralai/codestral-2508" \| "cohere/command-r-08-2024" \| "cohere/command-r-plus-08-2024" \| "cohere/command-a-03-2025" \| "cohere/command-a-translate-08-2025" \| "cohere/command-a-reasoning-08-2025" \| "cohere/command-a-vision-07-2025" \| "deepseek/deepseek-chat" \| "deepseek/deepseek-r1-0528" \| "perplexity/sonar" \| "perplexity/sonar-pro" \| "perplexity/sonar-reasoning-pro" \| "perplexity/sonar-deep-research" \| "nousresearch/hermes-3-llama-3.1-405b" \| "nousresearch/hermes-3-llama-3.1-70b" \| "amazon/nova-lite-v1" \| "amazon/nova-micro-v1" \| "amazon/nova-pro-v1" \| "microsoft/wizardlm-2-8x22b" \| "microsoft/phi-4" \| "gryphe/mythomax-l2-13b" \| "meta-llama/llama-4-scout" \| "meta-llama/llama-4-maverick" \| "x-ai/grok-3" \| "x-ai/grok-4" \| "x-ai/grok-4-fast" \| "x-ai/grok-4.1-fast" \| "x-ai/grok-code-fast-1" \| "moonshotai/kimi-k2" \| "qwen/qwen3-235b-a22b-thinking-2507" \| "qwen/qwen3-coder" \| "Llama-4-Scout-17B-16E-Instruct-FP8" \| "Llama-4-Maverick-17B-128E-Instruct-FP8" \| "Llama-3.3-8B-Instruct" \| "Llama-3.3-70B-Instruct" \| "v0-1.5-md" \| "v0-1.5-lg" \| "v0-1.0-md" | No || multiple_tool_calls | Whether to allow multiple tool calls in a single response. | bool | No || sys_prompt | The system prompt to provide additional context to the model. | str | No || conversation_history | The conversation history to provide context for the prompt. | List[Dict[str, Any]] | No |