run-llama/llama_index · error · ValueError

Tool {tool.metadata.name} is not a FunctionTool. CodeActAgen

Error message

Tool {tool.metadata.name} is not a FunctionTool. CodeActAgent only supports Functions and FunctionTools.

What it means

FunctionTool.call raises when the wrapped function was declared with a Context parameter (requires_context, detected via _is_context_param on the signature) but the required context keyword (ctx_param_name) is absent from the merged call kwargs (defaults + partial_params + kwargs). Context-aware tools must be invoked with a Context object supplied by the agent/workflow runtime.

Source

Thrown at llama-index-core/llama_index/core/agent/workflow/codeact_agent.py:144

        """Get the tool functions while validating that they are valid tools for the CodeActAgent."""
        callables = []
        for tool in tools:
            if (
                tool.metadata.name == "handoff"
                or tool.metadata.name == EXECUTE_TOOL_NAME
            ):
                continue

            if isinstance(tool, FunctionTool):
                if tool.requires_context:
                    raise ValueError(
                        f"Tool {tool.metadata.name} requires context. "
                        "CodeActAgent only supports tools that do not require context."
                    )

                callables.append(tool.real_fn)
            else:
                raise ValueError(
                    f"Tool {tool.metadata.name} is not a FunctionTool. "
                    "CodeActAgent only supports Functions and FunctionTools."
                )

        return callables

    def _extract_code_from_response(self, response_text: str) -> Optional[str]:
        """
        Extract code from the LLM response using XML-style <execute> tags.

        Args:
            response_text: The LLM response text

        Returns:
            Extracted code or None if no code found

        """
        # Match content between <execute> and </execute> tags

View on GitHub (pinned to afd0fef371)

Solutions

  1. Invoke the tool through the Workflow/AgentWorkflow runtime (e.g. ctx.run or agent handler) so Context is injected automatically.
  2. In direct tests, pass a Context explicitly: tool.call(ctx=Context(workflow)) or the ctx parameter name declared in the signature.
  3. Remove the Context parameter (and requires_context implication) if the tool does not actually need workflow state.
  4. Pre-check tool.requires_context before calling manually and construct an appropriate Context.

Example fix

# before
async def my_tool(query: str, ctx: Context) -> str: ...
tool = FunctionTool.from_defaults(fn=my_tool)
out = tool.call(query="hi")  # ValueError: Context is required for this tool

# after
from llama_index.core.workflow.context import Context
ctx = Context(workflow=MyWorkflow())
out = tool.call(query="hi", ctx=ctx)
Defensive patterns

Strategy: validation

Validate before calling

if tool.requires_context:
    assert tool.ctx_param_name, 'context param undetected'
    kwargs[tool.ctx_param_name] = ctx  # ctx from workflow runtime
tool.call(**kwargs)

Type guard

def tool_needs_context(tool) -> bool:
    return bool(getattr(tool, "requires_context", False))

Try / catch

try:
    out = tool.call(**kwargs)
except ValueError as e:
    if "Context is required" in str(e):
        out = tool.call(**kwargs, **{tool.ctx_param_name: make_context()})
    else:
        raise

Prevention

When it happens

Trigger: Calling tool.call(query='hi') directly instead of through an agent run when the fn signature has ctx: Context; invoking a context-requiring tool from a framework path that does not inject Context (custom runner, plain __call__ outside Workflow/AgentWorkflow); renaming the ctx parameter so _is_context_param no longer matches.

Common situations: Testing context tools outside the workflow runtime; hand-rolled agent loops that call tools manually; upgrading to workflows where ctx injection only happens via handler.run(...); partial_params set for everything except the context.

Related errors


AI-assisted analysis of run-llama/llama_index@afd0fef371 (2026-08-15). Data as JSON: /api/errors/7a69fecfc68bb439. Report an issue: GitHub.