a2aproject / a2aproject/a2a-samples

Using variable 'task' before assignment

未關閉
#52 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Jupyter Notebook
星號
1.8k
分支
751
PR 合併指標
30 天內沒有已合併 PR

描述

When running the demo UI with agents created via https://mozilla-ai.github.io/any-agent/serving/#__tabbed_1_2, I ran into the following exception.

https://github.com/google-a2a/a2a-samples/blob/08dde55c070f43be3fc2abf9ff976b689891991f/samples/python/hosts/multiagent/host_agent.py#L179

```
xception in thread Thread-1 ():
Traceback (most recent call last):
File "/Users/nbrake/.local/share/uv/python/cpython-3.12.8-macos-aarch64-none/lib/python3.12/threading.py", line 1075, in _bootstrap_inner
self.run()
File "/Users/nbrake/.local/share/uv/python/cpython-3.12.8-macos-aarch64-none/lib/python3.12/threading.py", line 1012, in run
self._target(*self._args, **self._kwargs)
File "/Users/nbrake/scm/a2a-samples/demo/ui/service/server/server.py", line 98, in
target=lambda: asyncio.run(self.manager.process_message(message))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/nbrake/.local/share/uv/python/cpython-3.12.8-macos-aarch64-none/lib/python3.12/asyncio/runners.py", line 194, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "/Users/nbrake/.local/share/uv/python/cpython-3.12.8-macos-aarch64-none/lib/python3.12/asyncio/runners.py", line 118, in run
return self._loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/nbrake/.local/share/uv/python/cpython-3.12.8-macos-aarch64-none/lib/python3.12/asyncio/base_events.py", line 686, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "/Users/nbrake/scm/a2a-samples/demo/ui/service/server/adk_host_manager.py", line 186, in process_message
async for event in self._host_runner.run_async(
File "/Users/nbrake/scm/a2a-samples/demo/ui/.venv/lib/python3.12/site-packages/google/adk/runners.py", line 196, in run_async
async for event in invocation_context.agent.run_async(invocation_context):
File "/Users/nbrake/scm/a2a-samples/demo/ui/.venv/lib/python3.12/site-packages/google/adk/agents/base_agent.py", line 147, in run_async
async for event in self._run_async_impl(ctx):
File "/Users/nbrake/scm/a2a-samples/demo/ui/.venv/lib/python3.12/site-packages/google/adk/agents/llm_agent.py", line 278, in _run_async_impl
async for event in self._llm_flow.run_async(ctx):
File "/Users/nbrake/scm/a2a-samples/demo/ui/.venv/lib/python3.12/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 279, in run_async
async for event in self._run_one_step_async(invocation_context):
File "/Users/nbrake/scm/a2a-samples/demo/ui/.venv/lib/python3.12/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 309, in _run_one_step_async
async for event in self._postprocess_async(
File "/Users/nbrake/scm/a2a-samples/demo/ui/.venv/lib/python3.12/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 381, in _postprocess_async
async for event in self._postprocess_handle_function_calls_async(
File "/Users/nbrake/scm/a2a-samples/demo/ui/.venv/lib/python3.12/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 456, in _postprocess_handle_function_calls_async
if function_response_event := await functions.handle_function_calls_async(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/nbrake/scm/a2a-samples/demo/ui/.venv/lib/python3.12/site-packages/google/adk/flows/llm_flows/functions.py", line 166, in handle_function_calls_async
function_response = await __call_tool_async(
^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/nbrake/scm/a2a-samples/demo/ui/.venv/lib/python3.12/site-packages/google/adk/flows/llm_flows/functions.py", line 431, in __call_tool_async
return await tool.run_async(args=args, tool_context=tool_context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/nbrake/scm/a2a-samples/demo/ui/.venv/lib/python3.12/site-packages/google/adk/tools/function_tool.py", line 80, in run_async
return await self.func(**args_to_call) or {}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/nbrake/scm/a2a-samples/samples/python/hosts/multiagent/host_agent.py", line 179, in send_message
return await convert_parts(task.parts, tool_context)
^^^^
UnboundLocalError: cannot access local variable 'task' where it is not associated with a value
```

貢獻指南

開啟貢獻指南

研究方向

The error occurs in samples/python/hosts/multiagent/host_agent.py at line 179, where 'task' is referenced before assignment. Examine the function 'send_message' to see how 'task' is defined and used. Look at the surrounding code to understand the flow and ensure 'task' is properly initialized before line 179. Run the demo UI with the agents to reproduce and verify the fix.

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
ai, backend
Issue 類型
缺陷
難度
3/5
預估耗時
1-2 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。