run-llama/llama_index · error · ValueError
code_execute_fn must be provided for CodeActAgent
Error message
code_execute_fn must be provided for CodeActAgent
What it means
QueryEngineTool._get_query_str derives the query string from either the first positional arg or the 'input' kwarg (matching the default fn_schema). If neither is present and _resolve_input_errors is False, it raises this ValueError — the tool was called without the input the query engine needs.
Source
Thrown at llama-index-core/llama_index/core/agent/workflow/codeact_agent.py:271
current_agent_name=self.name,
thinking_delta=last_chat_response.additional_kwargs.get(
"thinking_delta", None
),
)
)
return last_chat_response, full_response_text
async def take_step(
self,
ctx: AgentContext,
llm_input: List[ChatMessage],
tools: Sequence[BaseTool],
memory: BaseMemory,
) -> AgentOutput:
"""Take a single step with the code act agent."""
if not self.code_execute_fn:
raise ValueError("code_execute_fn must be provided for CodeActAgent")
# Get current scratchpad
scratchpad: List[ChatMessage] = await ctx.store.get(
self.scratchpad_key, default=[]
)
current_llm_input = [*llm_input, *scratchpad]
# Create a system message with tool descriptions
tool_descriptions = self._get_tool_descriptions(tools)
system_prompt = self.code_act_system_prompt.format(
tool_descriptions=tool_descriptions
)
# Add or overwrite system message
has_system = False
for i, msg in enumerate(current_llm_input):
if msg.role.value == "system":
current_llm_input[i] = ChatMessage(role="system", content=system_prompt)View on GitHub (pinned to afd0fef371)
Solutions
- Pass the query as first positional or as input=: tool.call(input='What are the sales numbers?').
- Construct the tool with resolve_input_errors=True (QueryEngineTool.from_defaults(..., resolve_input_errors=True)) so unexpected kwargs are stringified instead of raising.
- Align the tool's fn_schema with how you call it: a schema with an input field.
- Validate tool-call payloads before dispatch: ensure 'input' in kwargs or args non-empty.
Example fix
# before tool = QueryEngineTool.from_defaults(query_engine=engine) tool.call(query="sales numbers?") # ValueError: Cannot call query engine without specifying `input` # after result = tool.call(input="sales numbers?") # or make it tolerant: # tool = QueryEngineTool.from_defaults(query_engine=engine, resolve_input_errors=True)
Defensive patterns
Strategy: validation
Validate before calling
if not args and 'input' not in kwargs:
if tool._resolve_input_errors:
kwargs['input'] = str(kwargs)
else:
raise ValueError('missing input')
result = tool.call(*args, **kwargs) Type guard
def has_query_input(args: tuple, kwargs: dict) -> bool:
return len(args) > 0 or 'input' in kwargs Try / catch
try:
out = tool.call(**llm_args)
except ValueError as e:
if 'without specifying `input`' in str(e):
out = tool.call(input=llm_args.get('query') or str(llm_args))
else:
raise Prevention
- Standardize on the input kwarg or a positional query when calling QueryEngineTool.
- Build the tool with resolve_input_errors=True to tolerate schema drift.
- Pre-validate tool-call arguments before dispatch.
When it happens
Trigger: Calling query_engine_tool.call(**{'query': '...'}) (wrong kwarg name, e.g. 'query' instead of 'input'); an agent framework passing only non-positional metadata kwargs; fn_schema customized to a different field name while _get_query_str still expects input; _resolve_input_errors left False when the LLM produces malformed tool args.
Common situations: Hand-written agent loops that forward LLM JSON whose key is not 'input'; switching from OpenAIFunction agent (which uses input) to a custom runner; older tool metadata using 'query' key; LLM hallucinating argument names.
Related errors
- Max iterations of {max_iterations} reached! Either something
- No tool calls found, cannot aggregate results.
- Tool {tool.metadata.name} requires context. CodeActAgent onl
- Tool {tool.metadata.name} is not a FunctionTool. CodeActAgen
- LLM must be a FunctionCallingLLM
AI-assisted analysis of run-llama/llama_index@afd0fef371 (2026-08-15).
Data as JSON: /api/errors/0e7a695fb2d4ee23.
Report an issue: GitHub.