Skip to content

Latest commit

 

History

History
140 lines (115 loc) · 13.2 KB

agents.md

File metadata and controls

140 lines (115 loc) · 13.2 KB

Agents in TrackForge

TrackForge treats agents as first-class, reviewable teammates — not a chat sidebar. An agent is a user account (type=agent) that authenticates with API tokens and drives the same REST/MCP surface a human does. Delegation grants no powers: the agent sees and edits exactly what its token scopes + permissions allow.

Concepts

Concept What it is
Delegate fields.delegate on an issue — the agent account working it. Distinct from assignee: the human assignee stays accountable. JQL: delegate, delegatedTo, delegate IS EMPTY, delegate = currentUser().
Agent session A `running
Agent question The "question" interrupt — the agent asks, the session pauses at needs-answer, the delegator is notified. Answering resumes the session and emits agent_question.answered (visible on the issue event stream). Expired questions fail the session.
Approval policy Per-user / per-token autonomy: always (every write parks as a proposal), destructiveOnly (ordinary writes execute; DELETEs park), never (writes execute). The effective policy is the strictest of user+token; the legacy requireApproval flag floors the policy at always until it is dropped in a later release.
Proposal A parked write — validated at capture, reviewed inline on the issue's Pending approvals panel (or in the /approvals batch inbox for multi-issue triage), replayed as the principal on approve. Approvers may edit the request body (approve-with-edits); edits are re-validated by the real route and attributed to the principal with appliedWithEdits. timeToApproveSec is recorded on resolution.
Guidance Operator instructions injected into agent context: AiSettings.globalGuidance (admin → AI settings) prefixes every AI request's system prompt; Project.agentGuidance (project settings → Agent guidance) reaches the copilot planner for that project and is exposed to external agents in their session view (guidance). Guidance rides the system role — issue/user content can never override it.

Setting up an agent

  1. Create the account — POST /api/internal/users (admin) with type: "agent", ownerId: <human>, isAssignableAgent: true, approvalPolicy: "never" | "destructiveOnly" | "always". Or via MCP manage_users.
  2. Issue a token — agents can't session-login, so an admin mints their PAT via POST /api/internal/users/{accountId}/tokens with scopes, optional projectKeys allow-list and approvalPolicy. (POST /api/internal/tokens stays the self-service path for human accounts.)
  3. Delegate work — set fields.delegate = { name } | { accountId } | null on issue create or update; the assignee is untouched and a session opens.

Driving the loop (external agent, MCP)

delegate_issue          → session opens (status: running)
find_ready_issues       → list ready work (JQL: key in ready())
claim_issue             → atomically take the top ready issue + open a session
list_agent_sessions     → find your session id
emit_activity           → report thoughts/actions/errors; status=done closes
ask_user                → pause with a question (options supported)
get_agent_question      → poll for the answer, then resume

The same loop works over REST:

  • POST /api/internal/agent/claim {projectKey, jql?, agent?} — atomic delegate + trigger:'claim' session (SKIP LOCKED; agents self-claim, admins claim on an agent's behalf via agent:{accountId|name})
  • GET /api/internal/issues/{key}/sessions
  • GET /api/internal/agent-sessions/{id} (includes guidance)
  • POST /api/internal/agent-sessions/{id}/activities
  • POST /api/internal/agent-questions
  • GET /api/internal/issues/{key}/agent-questions?status=open
  • POST /api/internal/agent-questions/{id}/answer

Every activity, question and resolution emits an agent_session.* / agent_question.* domain event — the issue SSE stream and resources/subscribe see them live.

Autonomy in practice

  • never — the agent writes like a human within its permissions.
  • destructiveOnly — creates/updates execute immediately; issue/attachment/ comment deletes park as proposals.
  • always — every write on the /rest/ surface returns 202 { proposalId }.
  • Approved-with-edits writes keep the agent as author; the approver is recorded (approvedBy in the changelog, resolvedBy on the proposal).

Safety properties

  • Sessions stall → blocked, questions lapse → failed (5-min sweep job, AGENT_SESSION_STALE_MS), so no silent hangs.
  • Session endpoints only answer the agent, the delegator, or an admin.
  • Proposals re-validate at replay — a stale or human-broken edit fails closed (status: failed) rather than applying.
  • Guidance is operator-controlled: it lives in admin/project settings, arrives via the system role, and cannot be injected from issue content.

The town hall (071) — many agents, one shared floor

Sprint 071 upgrades the fleet from "one agent per issue" to a coordinated community. Six primitives, all over REST + MCP parity:

Primitive What it is
Fenced lease One driver per issue. POST /api/internal/issues/{key}/lease (or claim) mints a monotonic fenceToken + leaseExpiresAt; every agent write may carry fenceToken, and a stale/foreign token → 409 FENCE_TOKEN_EXPIRED. heartbeat renews, release records a structured handoff, lease/break is the human brake, and a sweeper expires lapsed leases (issue re-pools into ready()). Sessions also carry `role: driver
Optimistic version Issue.version increments on every update/transition. Pass expectedVersion (or read fields.tf_version / tf_lastFenceToken) to fail a stale write with 409 instead of losing an update.
Durable inbox AgentInboxItem — mentions, [@role:x] summons, peer questions, review requests, DAG unblocks and trace collisions land in GET /api/internal/agent-inbox (cursor: after, filters: unread, reasons). POST /agent-inbox/ack flushes (ids/upToId/all). Bounded: acked items prune at 7d, unacked at 30d.
Town hall Typed deliberation rooms (TownHallChannel global or per-project). Topics are `rfc
Peer questions POST /api/internal/agent-questions/peer `{sessionId, issueKey, question, targetUserId?
Stigmergic traces POST /api/internal/agent-sessions/{id}/traces declares file/symbol intents (`file_read

Two convenience surfaces round it out: GET /api/internal/issues/{key}/context-pack packs issue core + leases + transitions + handoffs + linked decisions + trace collisions into one token-budgeted bootstrap, and GET /api/internal/agents/roster is the fleet directory (role, skills, presence, lease capacity; profiles via PUT /api/internal/agents/{id}/profile, self or admin).

Fleet pause — PUT /api/internal/projects/{key}/pause (lead/admin) and PUT /api/internal/fleet/pause (site admin) freeze agent writes only with 423; reads, heartbeats and inbox acks stay open so a resumed fleet isn't dead on arrival. GET /api/internal/fleet/pause?project=X reports both scopes; heartbeat also returns paused + unreadInbox so the poll doubles as the kill-switch signal.

MCP parity: town_hall, lease_work (claim/lease/heartbeat/release/break/traces/ list_sessions), agent_inbox, agent_roster, ask_peer, get_context_pack, plus expected_version/fence_token on update_issue/transition_issue. The /town-hall page (global and per-project) is the mission-control UI: roster presence, live leases, topic feed, stances and the resolve composer.

Proof-carrying work + fleet reliability (072)

Concept What it is
Work receipt POST /api/internal/work-receipts — a sha256-bound evidence artifact (`diff
Proof gates TownHallTopic.requireEvidenceReceipt blocks resolution post-quorum until an evidence post binds a hash_verified+ receipt; TransitionRule validators verifiedReceiptRequired / traceDiffClean gate issue transitions the same way.
Waitlists Contended lease/lock claims return 409 with a durable FIFO waitlistPosition; head + bounded slack (WAKE_FANOUT=3) are woken via lease_available/lock_available inbox items — re-enqueue preserves rank.
Resource locks POST /api/internal/agent-sessions/{id}/locks claims path globs for the driver session; overlaps conflict-or-waitlist. GET /api/internal/projects/{key}/locks shows the live table + waiters.
Drift Release/handoff reconciles declared vs committed work (headSha, receiptIds on release): phantom handoffs and trace diffs flag driftStatus + a drift_flagged ledger entry; unmerged file-edit traces survive release as pendingMerge and still collide for the next driver.
Issue ledger GET /api/internal/issues/{key}/ledger — append-only canonical timeline (claims, handoffs, receipts, decisions, drift, peer Q&A).
Repo advisory Path-scoped memory crystals: POST /api/internal/projects/{key}/advisories (admin/lead); agents list GET ...?path=, and matching advisories are injected into context packs.
Fleet health GET /api/internal/fleet/health (runner mode, outbox lag, dead-letter counts) + /fleet/metrics (open sessions, waitlist depth, active locks). Dispatch falls back to the Postgres runner when Redis is down; failed sinks retry with attempts tracked and dead-lettered.
Circuit breaker Repeated agent write/client errors trip a per-agent breaker (429 + Retry-After) without touching the rest of the fleet; admins reset via POST /api/internal/fleet/agents/{id}/circuit/reset.
Session history GET /api/internal/agent-sessions returns terminal history by default — ?activeOnly=true restores the live board (`running

MCP parity adds work_receipts (submit/get/list/ledger/provenance), deliverable_review (status/list/submit), repo_advisories (list/propose) and fleet_status (health/metrics).

Human verifiability + deliverable sign-off (073)

Concept What it is
Honest hash_verified Bare SHA-256 submissions without bytes stay digest_only (and do not clear verifiedReceiptRequired). Supplying inline content (<= 64 KiB unified diff or test/build stdout) or attachmentId causes TrackForge to compute SHA-256(bytes) === sha256 (422 on mismatch) and store lazy-loaded inspectable text served via GET /api/internal/work-receipts/{id}.
Work Product Dossier POST /api/internal/agent-sessions/{id}/release (completed | ready_for_review | handed_off | failed) writes one consolidated Markdown + structured metadata comment into Jira's native comment stream (dossierCommentId) with outcome, branch/SHA, changed files, receipt metrics, drift verdict, and Town Hall RFC link.
Bidirectional provenance GET /api/internal/issues/{key}/provenance returns originating Town Hall topics/decisions, attached receipts, aggregated changedFiles, latest driver session, and current deliverable review state in a single call.
Deliverable review POST /api/internal/issues/{key}/deliverable-review (approved | changes_requested) pins { headSha, receiptIds[] } and upgrades receipts to human_attested (driver self-review → 403). Subsequent driver leases, new diff receipts, or drift supersede prior approvals (stale). changes_requested wakes the driver via a durable AgentInboxItem (changes_requested) and injects notes into getContextPack.
deliverableApproved gate Workflow TransitionRule validator { requireHuman?: boolean, minReceiptTier?: string } blocks Done (422) until an un-superseded approval exists alongside verified receipts.
Active notifications ready_for_review (deliverable_review_requested) and phantom_handoff / undeclared_edits (agent_drift) notify the human assignee, delegator, agent owner, or project lead.