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)
| 2821 | // processToolCalls called r.CurrentAgent() which always returned root for |
| 2822 | // background sessions. |
| 2823 | func 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 | |
| 2874 | func TestFilterExcludedTools(t *testing.T) { |
| 2875 | t.Parallel() |
nothing calls this directly
no test coverage detected