How shepherd-agents/shepherd works
Purpose and entry points
Shepherd is a Python 3.11+ framework for executing agent tasks as durable, inspectable, reversible runs. Tasks declare capability grants in Python signatures; filesystem/Git changes are retained as proposals and explicitly selected, applied, released, or discarded. The public distribution facade and user CLI live in shepherd/packages/meta/src/shepherd/__init__.py and shepherd/packages/meta/src/shepherd/cli/; runnable examples begin at examples/quickstart/agent_task.py.
Public programming model and dialect
The core model separates task contracts, scopes, effects, providers, outputs, and runs. shepherd_core defines shared types, task discovery, provider contracts, and effect representation (shepherd/packages/core/src/shepherd_core/run.py, shepherd/packages/core/src/shepherd_core/effects/registry.py). The dialect layer turns decorated functions and workflow steps into executable task envelopes, derives permission plans, validates source, and drives runs (shepherd/packages/dialect/src/shepherd_dialect/nucleus.py, shepherd/packages/dialect/src/shepherd_dialect/run_driver.py, shepherd/packages/dialect/src/shepherd_dialect/permission_plan.py).
Runtime lifecycle and execution flow
A run proceeds through explicit lifecycle phases—configure, prepare, context setup, execute, extract, artifact, apply, and cleanup—rather than directly mutating a caller workspace. The runtime builds task/source state, resolves bindings and providers, dispatches effects, emits artifacts/trace events, then materializes retained outputs. Key ownership paths are shepherd/packages/runtime/src/shepherd_runtime/_lifecycle/_pipeline.py, shepherd/packages/runtime/src/shepherd_runtime/execution.py, and shepherd/packages/runtime/src/shepherd_runtime/task/pipeline.py.
Scopes, effects, persistence, and reversibility
Runtime scopes form the isolation and composition boundary: nested bindings, checkpoints, resumptions, handler stacks, and effect materialization are coordinated under the scope runtime. Durable streams and project persistence preserve run history for inspection/resume, while cache policy can reuse eligible work. See shepherd/packages/runtime/src/shepherd_runtime/_scope/runtime.py, shepherd/packages/runtime/src/shepherd_runtime/effects/handle.py, and shepherd/packages/runtime/src/shepherd_runtime/_persistence_manager.py.
Workspace authority and versioned outputs
Workspace-control implements named repository bindings, read-only/read-write authority, run handles, changesets, output publication, and retained-output settlement. It is the policy boundary between an agent’s proposed filesystem result and a user-visible workspace update. Git-facing primitives support canonical identities and repository recovery in commons-vcs/src/commons_vcs/kernel.py and commons-vcs/src/commons_vcs/backends/git.py; the higher-level authority model is in shepherd/packages/dialect/src/shepherd_dialect/workspace_control/authority.py and shepherd/packages/dialect/src/shepherd_dialect/workspace_control/output_publication.py.
Isolation, providers, and external services
Execution can occur locally or on container devices; container support includes Podman, FUSE overlays, VM extraction, and provider execution (shepherd/packages/runtime/src/shepherd_runtime/device/container/device.py, shepherd/packages/runtime/src/shepherd_runtime/device/container/podman.py). Native enforcement targets macOS Seatbelt and Linux Landlock through confinement/workspace-control paths. Provider adapters integrate Claude, OpenAI, LiteLLM, and OpenCode (shepherd/packages/providers/src/shepherd_providers/claude/provider.py, shepherd/packages/providers/src/shepherd_providers/openai/provider.py); MCP support appears in both context and provider boundaries.
Ecosystem and parallel substrate work
Reusable context packages supply workspace, session, database, KV-store, app-store, and MCP effect surfaces (shepherd/packages/contexts/src/shepherd_contexts/workspace/, shepherd/packages/contexts/src/shepherd_contexts/mcp/). Domain packages provide coding and authoring workflows. The repository also contains independent/reference substrate efforts: vcs-core/packages/core/src/vcs_core/ is a large Git/SQLite-backed versioned-world runtime with CLI/session/materialization layers, while shepherd2/src/shepherd2/ and shepherd/packages/kernel-v3-reference/src/shepherd_kernel_v3_reference/ are newer/reference kernel and trace designs rather than the primary packaged runtime path.
Main entry points: _pipeline.py Lifecycle pipeline · execution.py Execution engine · nucleus.py Dialect nucleus · __init__.py Package facade & CLI
Components 21
Public Surface
- Package facade & CLI
shepherd/packages/meta/src/shepherd/__init__.py - Quickstart task
examples/quickstart/agent_task.py
Task Model & Dialect
- Core contracts · Defines task discovery, provider contracts, runs, and effect representations.
shepherd/packages/core/src/shepherd_core/run.py - Effect registry
shepherd/packages/core/src/shepherd_core/effects/registry.py - Dialect nucleus · Converts decorated functions and workflow steps into executable tasks.
shepherd/packages/dialect/src/shepherd_dialect/nucleus.py - Permission planning
shepherd/packages/dialect/src/shepherd_dialect/permission_plan.py - Run driver
shepherd/packages/dialect/src/shepherd_dialect/run_driver.py
Durable Runtime
- Lifecycle pipeline · Coordinates configure through cleanup without directly mutating the caller workspace.
shepherd/packages/runtime/src/shepherd_runtime/_lifecycle/_pipeline.py - Task pipeline
shepherd/packages/runtime/src/shepherd_runtime/task/pipeline.py - Execution engine
shepherd/packages/runtime/src/shepherd_runtime/execution.py - Scope runtime · Coordinates nested bindings, checkpoints, resumptions, and handler stacks.
shepherd/packages/runtime/src/shepherd_runtime/_scope/runtime.py - Effect handling
shepherd/packages/runtime/src/shepherd_runtime/effects/handle.py - Run persistence · Preserves history for inspection and resume while applying cache policy.
shepherd/packages/runtime/src/shepherd_runtime/_persistence_manager.py
Workspace & Versioning
- Workspace authority · Controls named bindings, access modes, run handles, and changesets.
shepherd/packages/dialect/src/shepherd_dialect/workspace_control/authority.py - Output publication
shepherd/packages/dialect/src/shepherd_dialect/workspace_control/output_publication.py - Git primitives
commons-vcs/src/commons_vcs/kernel.py - Git backend
commons-vcs/src/commons_vcs/backends/git.py
Execution Integrations
- Container devices · Supports Podman, FUSE overlays, VM extraction, and provider execution.
shepherd/packages/runtime/src/shepherd_runtime/device/container/device.py - Podman adapter
shepherd/packages/runtime/src/shepherd_runtime/device/container/podman.py - Provider adapters · Integrates Claude, OpenAI, LiteLLM, and OpenCode; MCP crosses provider boundaries.
shepherd/packages/providers/src/shepherd_providers/claude/provider.py - Context packages · Supplies workspace, session, database, KV-store, app-store, and MCP contexts.
Connections 21
- Quickstart task → Package facade & CLI: uses
- Package facade & CLI → Dialect nucleus: exposes
- Dialect nucleus → Core contracts: builds on
- Core contracts → Effect registry: defines effects
- Dialect nucleus → Permission planning: derives grants
- Dialect nucleus → Run driver: drives
- Run driver → Lifecycle pipeline: starts run
- Lifecycle pipeline → Task pipeline: prepares task
- Lifecycle pipeline → Execution engine: executes phase
- Execution engine → Scope runtime: runs within
- Scope runtime → Effect handling: coordinates
- Effect handling → Effect registry: dispatches
- Lifecycle pipeline → Run persistence: records runs
- Execution engine → Provider adapters: invokes
- Execution engine → Context packages: binds contexts
- Execution engine → Container devices: can isolate on
- Container devices → Podman adapter: uses
- Lifecycle pipeline → Workspace authority: settles outputs through
- Workspace authority → Output publication: authorizes
- Output publication → Git primitives: versions changesets
- Git primitives → Git backend: implemented by