MCPcopy Index your code
hub / github.com/docker/docker-agent / TestProcessToolCalls_UsesPinnedAgent

Function TestProcessToolCalls_UsesPinnedAgent

pkg/runtime/runtime_test.go:2823–2872  ·  view source on GitHub ↗

TestProcessToolCalls_UsesPinnedAgent verifies that tool-call events emitted by processToolCalls carry the pinned agent's name, not root's. Before the fix, processToolCalls called r.CurrentAgent() which always returned root for background sessions.

(t *testing.T)

Source from the content-addressed store, hash-verified

2821// processToolCalls called r.CurrentAgent() which always returned root for
2822// background sessions.
2823func TestProcessToolCalls_UsesPinnedAgent(t *testing.T) {
2824 t.Parallel()
2825
2826 var executed bool
2827 workerTool := tools.Tool{
2828 Name: "worker_tool",
2829 Parameters: map[string]any{},
2830 Handler: func(_ context.Context, _ tools.ToolCall) (*tools.ToolCallResult, error) {
2831 executed = true
2832 return tools.ResultSuccess("ok"), nil
2833 },
2834 }
2835
2836 prov := &mockProvider{id: "test/mock-model", stream: &mockStream{}}
2837 worker := agent.New("worker", "Worker agent", agent.WithModel(prov))
2838 root := agent.New("root", "Root agent", agent.WithModel(prov))
2839 tm := team.New(team.WithAgents(root, worker))
2840
2841 rt, err := NewLocalRuntime(t.Context(), tm, WithSessionCompaction(false), WithModelStore(mockModelStore{}))
2842 require.NoError(t, err)
2843 rt.registerDefaultTools()
2844 assert.Equal(t, "root", rt.CurrentAgentName(t.Context()))
2845
2846 // Simulate a background session pinned to "worker".
2847 sess := session.New(
2848 session.WithUserMessage("go"),
2849 session.WithToolsApproved(true),
2850 session.WithAgentName("worker"),
2851 )
2852
2853 calls := []tools.ToolCall{{
2854 ID: "call-1",
2855 Type: "function",
2856 Function: tools.FunctionCall{Name: "worker_tool", Arguments: "{}"},
2857 }}
2858
2859 events := make(chan Event, 32)
2860 rt.processToolCalls(t.Context(), sess, calls, []tools.Tool{workerTool}, NewChannelSink(events))
2861 close(events)
2862
2863 assert.True(t, executed, "worker_tool handler should have been called")
2864
2865 // Every event emitted must reference "worker", not "root".
2866 for ev := range events {
2867 if named, ok := ev.(interface{ GetAgentName() string }); ok {
2868 assert.Equal(t, "worker", named.GetAgentName(),
2869 "event %T should reference pinned agent \"worker\", not root", ev)
2870 }
2871 }
2872}
2873
2874func TestFilterExcludedTools(t *testing.T) {
2875 t.Parallel()

Callers

nothing calls this directly

Calls 15

registerDefaultToolsMethod · 0.95
CurrentAgentNameMethod · 0.95
processToolCallsMethod · 0.95
ResultSuccessFunction · 0.92
NewFunction · 0.92
NewFunction · 0.92
WithAgentsFunction · 0.92
NewFunction · 0.92
WithUserMessageFunction · 0.92
WithToolsApprovedFunction · 0.92
WithAgentNameFunction · 0.92
NewLocalRuntimeFunction · 0.85

Tested by

no test coverage detected