(t *testing.T)
| 515 | } |
| 516 | |
| 517 | func TestSessionFromEventsWithToolDefinitions(t *testing.T) { |
| 518 | t.Parallel() |
| 519 | |
| 520 | events := []map[string]any{ |
| 521 | {"type": "agent_choice", "content": "Let me read that file.", "agent_name": "root"}, |
| 522 | { |
| 523 | "type": "tool_call", |
| 524 | "tool_call": map[string]any{ |
| 525 | "id": "call_123", |
| 526 | "type": "function", |
| 527 | "function": map[string]any{ |
| 528 | "name": "read_file", |
| 529 | "arguments": `{"path": "test.txt"}`, |
| 530 | }, |
| 531 | }, |
| 532 | "tool_definition": map[string]any{ |
| 533 | "name": "read_file", |
| 534 | "category": "filesystem", |
| 535 | "description": "Read the contents of a file", |
| 536 | }, |
| 537 | }, |
| 538 | { |
| 539 | "type": "tool_call_response", |
| 540 | "tool_call_id": "call_123", |
| 541 | "response": "file content", |
| 542 | }, |
| 543 | {"type": "stream_stopped"}, |
| 544 | } |
| 545 | |
| 546 | sess := SessionFromEvents(events, "test", []string{"read the file"}) |
| 547 | |
| 548 | // Find the assistant message with tool calls |
| 549 | var assistantMsg *session.Message |
| 550 | for _, item := range sess.Messages { |
| 551 | if item.Message != nil && item.Message.Message.Role == chat.MessageRoleAssistant && len(item.Message.Message.ToolCalls) > 0 { |
| 552 | assistantMsg = item.Message |
| 553 | break |
| 554 | } |
| 555 | } |
| 556 | |
| 557 | require.NotNil(t, assistantMsg, "should have assistant message with tool calls") |
| 558 | assert.Len(t, assistantMsg.Message.ToolCalls, 1) |
| 559 | assert.Len(t, assistantMsg.Message.ToolDefinitions, 1) |
| 560 | |
| 561 | // Verify tool call |
| 562 | toolCall := assistantMsg.Message.ToolCalls[0] |
| 563 | assert.Equal(t, "call_123", toolCall.ID) |
| 564 | assert.Equal(t, "read_file", toolCall.Function.Name) |
| 565 | |
| 566 | // Verify tool definition |
| 567 | toolDef := assistantMsg.Message.ToolDefinitions[0] |
| 568 | assert.Equal(t, "read_file", toolDef.Name) |
| 569 | assert.Equal(t, "filesystem", toolDef.Category) |
| 570 | assert.Equal(t, "Read the contents of a file", toolDef.Description) |
| 571 | } |
| 572 | |
| 573 | func TestSessionFromEventsWithReasoningContent(t *testing.T) { |
| 574 | t.Parallel() |
nothing calls this directly
no test coverage detected