[BUG] Agent.copy() / Crew.copy() fails with TypeError when A2A config has auth (ClientAuthScheme is abstract)
Description
Agent.copy() (and therefore Crew.copy()) raises a TypeError for any agent whose a2a config has auth set, even when auth is one of CrewAI's own concrete schemes such as BearerTokenAuth.
BaseAgent.copy() serializes the agent with model_dump() and rebuilds it with type(self)(**copied_data). The dumped auth is now a plain dict, and pydantic re-validates it against the declared field type ClientAuthScheme. That is an abstract base class, so it can't be instantiated.
Agents with an A2AConfig / A2AClientConfig that has no auth copy fine.
Steps to Reproduce
from crewai import Agent
from crewai.a2a.config import A2AClientConfig
from crewai.a2a.auth.client_schemes import BearerTokenAuth
agent = Agent(
role="r", goal="g", backstory="b", llm="gpt-4o-mini",
a2a=A2AClientConfig(
endpoint="http://example.com/.well-known/agent-card.json",
auth=BearerTokenAuth(token="t"),
),
)
agent.copy()
The same happens with the deprecated A2AConfig(..., auth=BearerTokenAuth(...)), and with Crew.copy() on a crew that contains such an agent.
Expected behavior
agent.copy() / crew.copy() returns a copy whose a2a.auth is the same, or an equivalent, auth scheme instance.
Actual behavior
TypeError: Can't instantiate abstract class ClientAuthScheme without an implementation for abstract method 'apply_auth'
crewai/crew.py copy -> [agent.copy() for agent in self.agents]
crewai/agents/agent_builder/base_agent.py copy -> return type(self)(**copied_data, ...)
pydantic/main.py __init__ -> validate_python
Impact
Anything that copies a crew before running it fails as soon as an agent uses A2A authentication. One example is running each request on a fresh copy of the crew so that concurrent requests don't share state.
Environment
- crewAI: reproduced on 1.15.3. The same
copy()implementation and the sameauth: ClientAuthScheme | Nonefield type are still in 1.15.41. - Python 3.12, pydantic 2.x
Possible fix
Keep the a2a field out of the model_dump() and pass the existing config object through, the same way llm, tools and knowledge are already passed. Alternatively, deep-copy the a2a config instead of re-validating it.
I can reproduce this on current main: BaseAgent.copy() round-trips the agent through model_dump() and the dumped auth dict gets re-validated against the abstract ClientAuthScheme, which cannot be instantiated. I will work on a fix, keeping the a2a config out of the dump and passing it through (the same pattern llm, tools and knowledge already use), with a regression test covering Agent.copy() and Crew.copy() with an authenticated A2A config.