Skip to content
This repository was archived by the owner on Sep 2, 2025. It is now read-only.

Conversation

@mayank-cse1
Copy link

Issue: NameError: name 'Context' is not defined

Description

The error occurs because the Context object is referenced in the dispatch_calls function but was not imported at the beginning of the script.

The Context class is essential for managing workflow execution in llama_index, particularly when handling multiple tool calls in a sequential or parallel fashion.


** Root Cause**

  • The function dispatch_calls is defined as:
    @step(pass_context=True)
    async def dispatch_calls(self, ctx: Context, ev: GatherToolsEvent) -> ToolCallEvent:
    • Here, ctx: Context is expected as an argument, but Context is not defined or imported anywhere in the script.
    • This leads to NameError: name 'Context' is not defined when the workflow runs.

** Fix: Import Context from llama_index**

To resolve the issue, add the missing import at the beginning of the script:

from llama_index.core.workflow import (
    Workflow,
    Event,
    StartEvent,
    StopEvent,
    step,
    Context
)

This ensures that the Context object is recognized when used in dispatch_calls and other functions that require workflow execution management.

** Impact of the Fix**

  • Ensures proper workflow execution and tool dispatching in RouterOutputAgentWorkflow.
  • Prevents runtime crashes due to missing references.
  • Improves code reliability for multi-tool execution.

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant