Skip to content

fix: custom tool registration after CreateAgent returns agentId. - #8

Merged
remdev merged 1 commit into
mainfrom
fix/custom-tools-pending-agent-id
Jun 15, 2026
Merged

fix: custom tool registration after CreateAgent returns agentId.#8
remdev merged 1 commit into
mainfrom
fix/custom-tools-pending-agent-id

Conversation

@remdev

@remdev remdev commented Jun 15, 2026

Copy link
Copy Markdown
Owner

PR title

Fix custom tool registration after CreateAgent returns agentId


Summary

  • Fix: host-backed custom tools registered under "pending" during CreateAgent are re-registered under the real agentId returned by the bridge, so the first Send works without passing local.customTools again.
  • Cleanup: remove the provisional "pending" entry after successful create; unregister "pending" if CreateAgent fails.
  • ResumeAgent: register custom tools under the known agentId when local.customTools is provided (same gap as create, but ID is known upfront).
  • Tests: callback server unit tests + createAgent / resumeAgent integration tests with mock bridge.

Problem

When local.customTools is passed only on CreateAgent (matching the TypeScript SDK pattern), Go registers execute handlers in ToolCallbackServer under "pending" because agentId is not yet known.

The bridge later calls CallCustomTool with the real agentId. The callback handler looks up tools by that ID, finds nothing, and returns "tool not found". Custom MCP tools fail on the first run.

The only workaround was to pass the same customTools map on every Send() — undocumented and surprising for Go consumers.

Solution

Before CreateAgent RPC:
  RegisterAgent("pending", tools)   // or explicit agentId if set

After successful CreateAgent:
  RegisterAgent(realAgentId, tools)
  UnregisterAgent("pending")

On CreateAgent error:
  UnregisterAgent("pending")

agent.Send behavior unchanged: passing local.customTools on send still re-registers/overrides tools.

Test plan

  • go test ./cursor/...
  • go test ./...
  • Manual: create agent with local.customTools only on CreateAgent, send a prompt that invokes the tool, verify execution succeeds without re-passing tools on Send

Files

File Change
cursor/client.go pending → real agentId migration; resume registration; failure cleanup
cursor/callback_test.go ToolCallbackServer execute / not-found / migration pattern
cursor/custom_tools_test.go createAgent and resumeAgent with httptest mock bridge

Host-backed tools were registered under "pending" before CreateAgent,
but the bridge invokes CallCustomTool with the real agentId. Re-register
tools under that ID, clean up pending on failure, and register tools on
ResumeAgent when customTools are provided.
@remdev
remdev merged commit 08a352a into main Jun 15, 2026
1 check passed
@remdev
remdev deleted the fix/custom-tools-pending-agent-id branch June 15, 2026 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant