Announce Working Directory
Tell the model the workspace’s working directory, so it uses relative paths instead of guessing absolute ones. FileSystem and Shell add it themselves; add it yourself when your agent’s own tools work in the run’s workspace.
While Pydantic AI Harness is on 0.x releases, the API may change between minor releases; when it does, deprecation warnings and release-note migration guidance tell you (or your agent) exactly how to upgrade. See the version policy.
pip install pydantic-ai-harness
uv add pydantic-ai-harness
from pydantic_ai import Agent
from pydantic_ai.capabilities import LocalWorkspace
from pydantic_ai_harness import AnnounceWorkingDirectory
agent = Agent('anthropic:claude-opus-5-5', capabilities=[LocalWorkspace('.'), AnnounceWorkingDirectory()])
The model’s instructions then include the line: The working directory is /home/me/project.
The line asks the workspace for its directory with working_dir(). A sandbox that isn’t running yet is started to answer, before the first request, even if the model never calls a tool. Without a workspace, or with one that is gone, the line is left out, and the first tool call reports why.
AnnounceWorkingDirectory has a fixed id, so any number of them on one agent, including the ones FileSystem and Shell bring, merge into one line. A FileSystem or Shell with defer_loading=True doesn’t bring it, so a sandbox isn’t started for tools the model may never load; add AnnounceWorkingDirectory() yourself to name the directory anyway.
See the source.
Bases: AbstractCapability[AgentDepsT]
Tell the model the workspace’s working directory, so it uses relative paths instead of guessing absolute ones.
Shell and FileSystem add it themselves. Add it to an agent whose own tools work in ctx.workspace.
One-off: two of them would state the same line, so they share a fixed id and merge into one.
None or '' means the default, announce_working_directory.
@async
def for_run(ctx: RunContext[AgentDepsT]) -> AbstractCapability[AgentDepsT]
A copy for this run, so the line is worked out once and stays the same on every request of the run.
AbstractCapability[AgentDepsT]
def get_instructions() -> Callable[[RunContext[AgentDepsT]], Awaitable[str | None]]
Name the working directory, asking the workspace, which starts a sandbox that isn’t running.
Callable[[RunContext[AgentDepsT]], Awaitable[str | None]]