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

Function TestTransferTaskRejectsNonSubAgent

pkg/runtime/runtime_test.go:2259–2296  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2257}
2258
2259func TestTransferTaskRejectsNonSubAgent(t *testing.T) {
2260 t.Parallel()
2261
2262 // root has librarian as sub-agent but NOT planner.
2263 // planner exists in the team. transfer_task to planner should be rejected.
2264 prov := &mockProvider{id: "test/mock-model", stream: &mockStream{}}
2265
2266 librarian := agent.New("librarian", "Library agent", agent.WithModel(prov))
2267 root := agent.New("root", "Root agent", agent.WithModel(prov))
2268 planner := agent.New("planner", "Planner agent", agent.WithModel(prov))
2269
2270 agent.WithSubAgents(librarian)(root)
2271
2272 tm := team.New(team.WithAgents(root, planner, librarian))
2273
2274 rt, err := NewLocalRuntime(t.Context(), tm, WithSessionCompaction(false), WithModelStore(mockModelStore{}))
2275 require.NoError(t, err)
2276
2277 sess := session.New(session.WithUserMessage("Test"))
2278 evts := make(chan Event, 128)
2279
2280 toolCall := tools.ToolCall{
2281 ID: "call_1",
2282 Type: "function",
2283 Function: tools.FunctionCall{
2284 Name: "transfer_task",
2285 Arguments: `{"agent":"planner","task":"do something","expected_output":""}`,
2286 },
2287 }
2288
2289 result, err := rt.handleTaskTransfer(t.Context(), sess, toolCall, NewChannelSink(evts))
2290 require.NoError(t, err)
2291 require.NotNil(t, result)
2292 assert.True(t, result.IsError, "transfer to non-sub-agent should return an error result")
2293 assert.Contains(t, result.Output, "cannot transfer task to planner")
2294 assert.Contains(t, result.Output, "librarian")
2295 assert.Equal(t, "root", rt.CurrentAgentName(t.Context()), "current agent should remain root")
2296}
2297
2298func TestTransferTaskAllowsSubAgent(t *testing.T) {
2299 t.Parallel()

Callers

nothing calls this directly

Calls 12

handleTaskTransferMethod · 0.95
CurrentAgentNameMethod · 0.95
NewFunction · 0.92
NewFunction · 0.92
WithAgentsFunction · 0.92
NewFunction · 0.92
WithUserMessageFunction · 0.92
NewLocalRuntimeFunction · 0.85
WithSessionCompactionFunction · 0.85
WithModelStoreFunction · 0.85
NewChannelSinkFunction · 0.85
ContextMethod · 0.80

Tested by

no test coverage detected