llama_index: [Bug]: WorkflowRuntimeError: Error in step 'run_agent_step': cannot access local variable 'r' where it is not associated with a value

Bug Description

I am trying to use a Multi-Agent workflow using AgentWorkflow, and I get this error as soon the second agent is called. I get the same error by running the code example from: https://github.com/run-llama/llama_index/blob/main/docs/docs/examples/agent/agent_workflow_multi.ipynb

`async def test(): handler = agent_workflow.run( user_msg=“Write me a report on the history of the internet. Briefly describe the history of the internet, including the development of the internet, the development of the web, and the development of the internet in the 21st century.” )

await handler

import asyncio

asyncio.run(test()) ` I use the LLM from Anthropic using the basic configuration.

Version

0.12.13

Steps to Reproduce

Reproduce the code example of Multi Agent Workflow using Claude 3.5 Sonnet. As soon the second agent is called through handoff I get the error from the Logs

Relevant Logs/Tracbacks

Exception in callback Dispatcher.span.<locals>.wrapper.<locals>.handle_future_result(span_id='Workflow.run...-913ba5df3822', bound_args=<BoundArgumen...mory': None})>, instance=<llama_index....t 0x11e373020>, context=<_contextvars...t 0x11e2ab700>)(<WorkflowHand...ith a value")>) at /opt/homebrew/anaconda3/envs/imodule/lib/python3.12/site-packages/llama_index/core/instrumentation/dispatcher.py:273
handle: <Handle Dispatcher.span.<locals>.wrapper.<locals>.handle_future_result(span_id='Workflow.run...-913ba5df3822', bound_args=<BoundArgumen...mory': None})>, instance=<llama_index....t 0x11e373020>, context=<_contextvars...t 0x11e2ab700>)(<WorkflowHand...ith a value")>) at /opt/homebrew/anaconda3/envs/imodule/lib/python3.12/site-packages/llama_index/core/instrumentation/dispatcher.py:273>
Traceback (most recent call last):
  File "/opt/homebrew/anaconda3/envs/imodule/lib/python3.12/site-packages/llama_index/core/workflow/workflow.py", line 247, in _task
    new_ev = await instrumented_step(**kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/anaconda3/envs/imodule/lib/python3.12/site-packages/llama_index/core/instrumentation/dispatcher.py", line 367, in async_wrapper
    result = await func(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/anaconda3/envs/imodule/lib/python3.12/site-packages/llama_index/core/agent/workflow/multi_agent_workflow.py", line 290, in run_agent_step
    agent_output = await agent.take_step(
                   ^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/anaconda3/envs/imodule/lib/python3.12/site-packages/llama_index/core/agent/workflow/react_agent.py", line 106, in take_step
    message_content = r.message.content
                      ^
UnboundLocalError: cannot access local variable 'r' where it is not associated with a value

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/opt/homebrew/anaconda3/envs/imodule/lib/python3.12/asyncio/events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "/opt/homebrew/anaconda3/envs/imodule/lib/python3.12/site-packages/llama_index/core/instrumentation/dispatcher.py", line 285, in handle_future_result
    raise exception
  File "/opt/homebrew/anaconda3/envs/imodule/lib/python3.12/site-packages/llama_index/core/workflow/workflow.py", line 445, in _run_workflow
    raise exception_raised
  File "/opt/homebrew/anaconda3/envs/imodule/lib/python3.12/site-packages/llama_index/core/workflow/workflow.py", line 254, in _task
    raise WorkflowRuntimeError(
llama_index.core.workflow.errors.WorkflowRuntimeError: Error in step 'run_agent_step': cannot access local variable 'r' where it is not associated with a value
Traceback (most recent call last):
  File "/opt/homebrew/anaconda3/envs/imodule/lib/python3.12/site-packages/llama_index/core/workflow/workflow.py", line 247, in _task
    new_ev = await instrumented_step(**kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/anaconda3/envs/imodule/lib/python3.12/site-packages/llama_index/core/instrumentation/dispatcher.py", line 367, in async_wrapper
    result = await func(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/anaconda3/envs/imodule/lib/python3.12/site-packages/llama_index/core/agent/workflow/multi_agent_workflow.py", line 290, in run_agent_step
    agent_output = await agent.take_step(
                   ^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/anaconda3/envs/imodule/lib/python3.12/site-packages/llama_index/core/agent/workflow/react_agent.py", line 106, in take_step
    message_content = r.message.content
                      ^
UnboundLocalError: cannot access local variable 'r' where it is not associated with a value

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/****/****/***/****/****.py", line 105, in <module>
    asyncio.run(test())
  File "/opt/homebrew/anaconda3/envs/imodule/lib/python3.12/asyncio/runners.py", line 194, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/anaconda3/envs/imodule/lib/python3.12/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/anaconda3/envs/imodule/lib/python3.12/asyncio/base_events.py", line 686, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/Users/****/****/***/****/****.py", line 100, in test
    await handler
  File "/opt/homebrew/anaconda3/envs/imodule/lib/python3.12/site-packages/llama_index/core/workflow/workflow.py", line 445, in _run_workflow
    raise exception_raised
  File "/opt/homebrew/anaconda3/envs/imodule/lib/python3.12/site-packages/llama_index/core/workflow/workflow.py", line 254, in _task
    raise WorkflowRuntimeError(
llama_index.core.workflow.errors.WorkflowRuntimeError: Error in step 'run_agent_step': cannot access local variable 'r' where it is not associated with a value

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 17

Most upvoted comments

@logan-markewich thank you very much for solving the issue! I can confirm that my Multi-Agent Workflow is finally working 🚀

@rasphlat check out my notebook i shared. Does it work for you? I meant you might want to double check your llm setup, due to the max tokens thing I shared

I get the same error using both ReActAgent or FunctionAgent.