This test verifies that the fix in _handle_agent_response_and_continue()
correctly rebuilds the AgentResponse model with both endpoints and skill IDs
for subsequent turns in multi-turn A2A conversations.
The test simulates a multi-turn scenario where:
1. First turn: LLM returns skill ID 'Research'
2. Second turn: LLM returns skill ID 'Writing' (different agent)
3. Third turn: LLM returns skill ID 'Research' again
All turns should accept skill IDs without validation errors.
Co-Authored-By: João <joao@crewai.com>
This commit fixes issue #3897 where the LLM would return a skill.id
(e.g., 'Research') instead of the full endpoint URL, causing a
Pydantic validation error.
Changes:
- Added resolve_agent_identifier() function to map skill IDs to endpoints
- Added extract_agent_identifiers_from_cards() to collect both endpoints and skill IDs
- Modified _execute_task_with_a2a() to rebuild AgentResponse model after fetching AgentCards
- Updated _delegate_to_a2a() to use resolver for identifier resolution
- Updated _augment_prompt_with_a2a() to explicitly instruct LLM about both identifier types
- Added comprehensive unit tests for resolve_agent_identifier()
- Added integration tests replicating the exact issue from #3897
The fix allows the dynamic Pydantic model to accept both endpoint URLs
and skill IDs in the Literal constraint, then resolves skill IDs to
their canonical endpoints before delegation. This maintains backward
compatibility while fixing the validation error.
Fixes#3897
Co-Authored-By: João <joao@crewai.com>