(t *testing.T)
| 2296 | } |
| 2297 | |
| 2298 | func TestTransferTaskAllowsSubAgent(t *testing.T) { |
| 2299 | t.Parallel() |
| 2300 | |
| 2301 | // Verify that transfer_task to a valid sub-agent is NOT rejected by the validation. |
| 2302 | // We can't fully run the child session without a real model, so we just confirm |
| 2303 | // it gets past validation (it will fail later due to mock stream being empty, |
| 2304 | // which is fine — we only care that it's not blocked by the sub-agent check). |
| 2305 | prov := &mockProvider{id: "test/mock-model", stream: newStreamBuilder().AddContent("done").AddStopWithUsage(10, 5).Build()} |
| 2306 | |
| 2307 | librarian := agent.New("librarian", "Library agent", agent.WithModel(prov)) |
| 2308 | root := agent.New("root", "Root agent", agent.WithModel(prov)) |
| 2309 | |
| 2310 | agent.WithSubAgents(librarian)(root) |
| 2311 | |
| 2312 | tm := team.New(team.WithAgents(root, librarian)) |
| 2313 | |
| 2314 | rt, err := NewLocalRuntime(t.Context(), tm, WithSessionCompaction(false), WithModelStore(mockModelStore{})) |
| 2315 | require.NoError(t, err) |
| 2316 | |
| 2317 | sess := session.New(session.WithUserMessage("Test"), session.WithToolsApproved(true)) |
| 2318 | evts := make(chan Event, 128) |
| 2319 | |
| 2320 | toolCall := tools.ToolCall{ |
| 2321 | ID: "call_1", |
| 2322 | Type: "function", |
| 2323 | Function: tools.FunctionCall{ |
| 2324 | Name: "transfer_task", |
| 2325 | Arguments: `{"agent":"librarian","task":"find a book","expected_output":"book title"}`, |
| 2326 | }, |
| 2327 | } |
| 2328 | |
| 2329 | result, err := rt.handleTaskTransfer(t.Context(), sess, toolCall, NewChannelSink(evts)) |
| 2330 | require.NoError(t, err) |
| 2331 | require.NotNil(t, result) |
| 2332 | assert.False(t, result.IsError, "transfer to valid sub-agent should succeed") |
| 2333 | } |
| 2334 | |
| 2335 | // TestTransferTaskPersistsSubSessionOnError covers the case where a sub-agent's |
| 2336 | // run loop emits an ErrorEvent — for example because the model stream failed, |
nothing calls this directly
no test coverage detected