Change Recipes

Concrete change paths for common contribution scenarios, plus a contributor checklist.

Use these recipes to route changes through the correct modules without crossing layer boundaries. Module routers and doc comments identify the exact files.

Add or Modify a Session Workflow🔗

  1. Keep frontend-neutral request/result models and programmatic operations in ag-session.
  2. Update Agentty orchestration in crates/agentty/src/app/session/ and adapt it through crates/agentty/src/app/session_api.rs.
  3. Route background-callable operations through the bounded actor in crates/agentty/src/app/session_runtime.rs; do not share App behind an async mutex.
  4. Keep persistence in ag-store domain modules and Git operations behind GitClient.
  5. Preserve the session-branch invariant: an unpublished branch holds one evolving commit, created by the first file-changing turn and amended by later ones; a published branch gains one commit per file-changing turn instead.
  6. Update docs/site/content/docs/usage/workflow.md when lifecycle or status behavior changes.

Add an Agent Definition🔗

Add a repository definition under .agents/agents/<id>/agent.md, or a bundled definition under crates/ag-session/src/agents/. Both use the same parser. Keep host workflow contracts separate from definition identity and preserve task snapshots when changing admission or continuation.

Define a Generic Execution Graph🔗

Follow the execution graph contracts and their design reasons. Keep model-authored proposals in ag-protocol, pure graph shapes and resolution in ag-session, durable snapshots, results, and atomic admission in ag-store, and dispatch in the ag-worker GraphExecutor. Inject worker adapters through GraphNodeRunner, place nodes in their Envs through GraphEnvResolver, and share GraphResources Env leases with other host work. Test structural rules without storage or workers, storage invariants with SQLite, and dispatch through the public API.

Add a New Agent Backend or Model🔗

  1. Declare model IDs, descriptions, provider order, speed support, and known context budgets together in the ag-session model catalog. Keep provider defaults and retired-ID mappings explicit; removing a public enum variant is a Rust API change.
  2. For a new backend, add behavior in crates/ag-agent/src/agent/ and register it in the provider registry. Backends consume catalog capabilities instead of keeping their own model lists.
  3. Keep transport selection, parsing, streaming, and provider setup in ag-agent; application workflows continue through worker clients.
  4. Update docs/site/content/docs/agents/backends.md.

Add a Built-in ag-router Model🔗

  1. Add the model's wire capabilities and reasoning mapping to its ProviderSpec preset in crates/ag-router/src/preset.rs. A provider that needs no new wire behavior needs no code: hosts describe it with a ProviderSpec.
  2. Add local HTTP tests for schema format, capabilities, reasoning fields, and error mapping, and a golden request to the protocol's conformance suite under crates/ag-router/tests/.
  3. Expose it through ag-harness configuration only if the harness supports its capabilities.
  4. To offer it under ag-harness in Agentty's /model, add it to the Harness entries of the ag-session model catalog. ag-agent registers it from its ag-harness ModelSpec; declare a ModelProfile in ag-agent only when that specification has none.

Add or Change a Utility Agent Prompt🔗

  1. Submit an owned OneShotRequest through the worker RunClient; do not select a CLI, app-server, backend, or protocol-repair helper from application orchestration.
  2. Choose the request kind by what the task reads. AgentRequestKind::TextGeneration answers from the prompt alone, such as a title or a one-word decision, and is sent without tools, repository instruction files, or workspace policy. Use AgentRequestKind::UtilityPrompt when the task inspects the worktree or follows repository guidance.
  3. Inject &dyn RunClient into the smallest workflow helper that needs deterministic coverage and test it with MockRunClient.
  4. Background work captures purpose and ownership with ag-worker::scoped_client; nested utilities keep parent cancellation and never queue behind the session command awaiting them.
  5. Keep provider routing, protocol repair, usage aggregation, and runtime cleanup in ag-agent.

Add a Keybinding or Mode Interaction🔗

  1. For text editing, add the semantic command in crates/agentty/src/domain/input.rs and map terminal keys once in crates/agentty/src/runtime/mode/input_key.rs.
  2. Let context-specific input modes intercept only their own actions before falling back to the shared mapping.
  3. Change prompt composer state in the pure reducer of crates/agentty/src/runtime/mode/prompt.rs and request app work as an effect, so unit tests need no App.
  4. Update other handlers in crates/agentty/src/runtime/mode/, or the cross-mode overlay dispatch in crates/agentty/src/runtime/key_handler.rs.
  5. Extend crates/agentty/src/presentation/app_mode.rs for a new mode and crates/agentty/src/presentation/help_action.rs for help content.
  6. Update docs/site/content/docs/usage/keybindings.md.

Add or Change Database Schema🔗

  1. Add a new migration in crates/ag-store/migrations/ (NNN_description.sql); never modify existing migrations.
  2. Keep query changes in the matching ag-store domain module.
  3. Update user-facing docs affected by status or model behavior changes.

Change What a Platform's Sync Receives🔗

  1. Build every value a Sync request sends in crates/agentty/src/domain/platform_sync.rs and check it again in crates/agentty/src/infra/platform.rs before sending.
  2. Keep answer text in session transient output only, never in a transcript or prompt. The one exception is the held task's milestone, which reaches session turns only through TurnRequest::task_milestone, fenced and escaped by crates/ag-agent/src/agent/prompt.rs.
  3. Update the Sync section of SECURITY.md and docs/site/content/docs/usage/platform.md with what is sent and when.

Add a New UI Page or Component🔗

  1. Add the page in crates/agentty/src/ui/page/ or component in crates/agentty/src/ui/component/, and wire pages into crates/agentty/src/ui/router.rs.
  2. For a new AppMode, extend crates/agentty/src/presentation/app_mode.rs and add a key handler in crates/agentty/src/runtime/mode/.

Change run execution🔗

  1. Update shared lifecycle contracts in ag-contracts and provider behavior in ag-agent.
  2. Keep mailboxes, session runtime ownership, scheduling, cancellation, and recovery in ag-worker; implement product-specific question, Git, forge, and UI policy in the host adapter.
  3. Construct ag-agent adapters only inside ag-runtime; applications configure workers.
  4. Extend headless contract tests and the affected Agentty workflow tests. Changes to operation persistence also need ag-store adapter tests.

Adding model-assisted work🔗

Use the utility prompt recipe and the Execution contract.

Contributor Checklist for Architecture-Safe Changes🔗

  1. Follow Module Map for layer ownership and Testability Boundaries for external-system injection.
  2. Update the relevant user guide for visible changes and the canonical architecture page when its contracts change, including the runtime key-types table and the boundary table.
  3. Reuse cached derived data on render hot paths; measurement and painting must agree.
  4. Run the required gates in root AGENTS.md.