Skip to content

AbstractAgent class can't be extended without importing private util module #2795

@clhodapp

Description

@clhodapp

Initial Checks

Description

At present, the definition of AbstractAgent requires the user to implement the abstract overide method, defined as such:

@contextmanager
@abstractmethod
def override(
    self,
    *,
    deps: AgentDepsT | _utils.Unset = _utils.UNSET,
    model: models.Model | models.KnownModelName | str | _utils.Unset = _utils.UNSET,
    toolsets: Sequence[AbstractToolset[AgentDepsT]] | _utils.Unset = _utils.UNSET,
    tools: Sequence[Tool[AgentDepsT] | ToolFuncEither[AgentDepsT, ...]] | _utils.Unset = _utils.UNSET,
) -> Iterator[None]:
    """Context manager to temporarily override agent dependencies, model, toolsets, or tools.

    This is particularly useful when testing.
    You can find an example of this [here](../testing.md#overriding-model-via-pytest-fixtures).

    Args:
	deps: The dependencies to use instead of the dependencies passed to the agent run.
	model: The model to use instead of the model passed to the agent run.
	toolsets: The toolsets to use instead of the toolsets passed to the agent constructor and agent run.
	tools: The tools to use instead of the tools registered with the agent.
    """
    raise NotImplementedError
    yield

The problem is that _utils is a private module, and thus is improper to reference from outside of PydanticAI itself.

This implicitly makes it impossible to actually implement AbstractAgent from outside of PydanticAI without violating the "rules" of good Python.

Python, Pydantic AI & LLM client version

Python - 3.12
PydanticAI - 0.8.1
LLM Client - All

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions