Skip to content

Latest commit

 

History

History
169 lines (123 loc) · 5.12 KB

File metadata and controls

169 lines (123 loc) · 5.12 KB

Bug Fix: Tool Execution Error

Date: 2026-01-24 Issue: "Function run_one_shot not found" during tool execution Status: ✅ Fixed

Problem

When the assistant suggested using the run_one_shot tool and user confirmed:

cmbchat_assistant: I can create a Python script that...
                   Shall I proceed?

user: yes

cmbchat_assistant: ***** Suggested tool call: run_one_shot *****
                   Arguments: {...}

>>>>>>>> EXECUTED FUNCTION run_one_shot...
Output:
Error: Function run_one_shot not found.

The tool was being suggested but not executed.

Root Cause

In the AG2/AutoGen framework, there's a distinction between:

  1. Seeing a tool (LLM knows about it, can suggest it)
  2. Executing a tool (Agent can actually run it)

Wrong Registration (Before)

toolkit.register_for_llm(assistant)
toolkit.register_for_execution(assistant)  # ❌ Wrong agent

This registers tools for both seeing and executing on the assistant agent.

Why This Failed

In AG2's architecture:

  • AssistantAgent with LLM → Suggests tools, generates responses
  • UserProxyAgent without LLM → Executes tools, handles human input

Tools must be executed by the UserProxyAgent, not the AssistantAgent.

Solution

Correct Registration (After)

# Register tools for LLM (assistant can see and suggest them)
toolkit.register_for_llm(assistant)

# Register tools for execution (MUST be on user_proxy in AG2)
toolkit.register_for_execution(user_proxy)

Why This Works

  1. Assistant sees the tool via register_for_llm → Can suggest it to user
  2. User proxy executes the tool via register_for_execution → Can actually run it
  3. Standard AG2 pattern for tool-using agents

AG2 Tool Execution Pattern

┌────────────────────────────────────────┐
│  AssistantAgent (with LLM)             │
│  - Sees tools (register_for_llm)       │
│  - Suggests tool calls in responses    │
│  - Does NOT execute tools              │
└──────────────┬─────────────────────────┘
               │
               │ Suggests: "Use run_one_shot"
               ↓
┌────────────────────────────────────────┐
│  UserProxyAgent (no LLM)               │
│  - Executes tools (register_for_exec)  │
│  - Gets human input                    │
│  - Runs actual tool functions          │
└────────────────────────────────────────┘

Verification

After the fix, the flow should be:

user: "What's the sum of two Gaussians?"

cmbchat_assistant: I can create a Python script that:
                   - Defines two Gaussian functions
                   - Computes their sum
                   - Plots the visualization
                   This takes ~30 seconds. Shall I proceed?

user: yes

cmbchat_assistant: ***** Suggested tool call: run_one_shot *****
                   Arguments: {"task": "...", "max_rounds": 5}

>>>>>>>> EXECUTING FUNCTION run_one_shot...  ✅ Works!
Output: {"status": "success", "work_dir": "...", ...}

cmbchat_assistant: ✓ Script created successfully!
                   I've generated 'gaussian_sum.py' in ./cmbchat_work/...

Related AG2 Documentation

From AG2 docs on tool registration:

  • register_for_llm(agent) - Makes tool visible to the agent's LLM
  • register_for_execution(agent) - Allows agent to execute the tool
  • register_tool(agent) - Shorthand for both (not used here)

Standard pattern for assistant + user_proxy:

# Pattern 1: AssistantAgent suggests, UserProxyAgent executes
tool.register_for_llm(assistant)
tool.register_for_execution(user_proxy)

# Pattern 2: Both can suggest and execute (less common)
tool.register_tool(assistant)
tool.register_tool(user_proxy)

We use Pattern 1 because:

  • Only assistant has LLM, so only it can intelligently suggest tools
  • User proxy handles execution and human interaction
  • Clear separation of concerns

Commit

git commit -m "Fix: Register tools for execution on user_proxy, not assistant"

Testing

To test the fix:

cd /Users/boris/GitHub/cmbchat
cmbchat

# Test interaction:
> What's the sum of two Gaussians?
> yes

# Should now execute successfully without "not found" error

Similar Issues

If you see other tool-related errors:

  • "Tool not found" → Check register_for_llm is on assistant
  • "Cannot execute" → Check register_for_execution is on user_proxy
  • "Tool not suggested" → Check tool is in toolkit and LLM sees it
  • "Tool executes but no result" → Check tool's return value format

Status

✅ Fixed and committed ✅ Ready for testing ✅ Should work correctly now


Next step: Restart cmbchat and try the Gaussian question again!