Skip to content

feat(ai): agent run persistence (AI-036)#325

Merged
mrviduus merged 1 commit into
mainfrom
ai-036-agent-run-persistence
Jun 14, 2026
Merged

feat(ai): agent run persistence (AI-036)#325
mrviduus merged 1 commit into
mainfrom
ai-036-agent-run-persistence

Conversation

@mrviduus

Copy link
Copy Markdown
Owner

Phase 6 AI-036 — agent runs are saved so the reader UI can replay an agent's steps (AI-038) and runs are observable. Persistence mechanics only; the endpoint that calls the writer is AI-037.

Changes

  • agent_run table (AddAgentRun migration) + AgentRun entity + DbSet on IAppDbContext/AppDbContext (AppDbContext.Agents.cs). Columns: agent / user / edition / goal / status / output / steps_json (jsonb) / iterations / tokens / cost / latency / error / created_at. Optional FK→users ON DELETE SET NULL (a deleted user doesn't erase history); partial index on (user_id, created_at).
  • IAgentRunWriter (Ai.Core) + DbAgentRunWriter (Application/Ai, scoped — mirrors DbLlmTraceWriter): flattens the framework-free AgentRunRecord into the entity, serializing the step transcript to jsonb. Awaited by the caller (the run is already finished — no latency to hide, recommendation Add Claude Code GitHub Workflow #3).
  • AgentRunRecord (Ai.Core) + AgentRunRecordFactory (Ai.Agents): Completed / BudgetExhausted / Failed build a persistable record uniformly across outcomes.
  • Budget-exhausted runs keep their transcript (recommendation Fix build errors: Add missing packages and NuGet source configuration #1): AgentBudgetExhaustedException now carries the partial Steps + Usage accumulated before the cap — the run you most want to inspect is the one that ran out of budget. AgentLoop throws with them at both the cost-cap and max-steps exits (additive; AI-034 tests still pass).
  • steps_json is a single jsonb column (recommendation feat: add full-text search library with PostgreSQL FTS #2) — read whole for "show steps", not queried per field.

Verification

  • AgentRunRecordFactory tests (completed / budget-exhausted-keeps-transcript / failed); AgentLoop budget-exhaustion test now asserts the exception carries the partial transcript + usage.
  • Migration applied locally; \d agent_run + a jsonb insert/read roundtrip + FK + partial index verified on Postgres.
  • Full TextStack.UnitTests (267) + TextStack.AiEvals (28) green; dotnet format clean.

🤖 Generated with Claude Code

agent_run table + AgentRun entity + DbSet; IAgentRunWriter (Ai.Core) /
DbAgentRunWriter (Application/Ai, scoped) flatten a framework-free
AgentRunRecord into the entity with the step transcript as jsonb.
AgentRunRecordFactory builds Completed/BudgetExhausted/Failed records
uniformly. AgentBudgetExhaustedException now carries the partial Steps+Usage
so a budget-exhausted run keeps its transcript; AgentLoop throws with them.
Endpoint that persists is AI-037.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@mrviduus mrviduus merged commit fee689c into main Jun 14, 2026
5 checks passed
@mrviduus mrviduus deleted the ai-036-agent-run-persistence branch June 14, 2026 22:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant