feat(ai): agent run persistence (AI-036)#325
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_runtable (AddAgentRunmigration) +AgentRunentity +DbSetonIAppDbContext/AppDbContext(AppDbContext.Agents.cs). Columns: agent / user / edition / goal / status / output /steps_json(jsonb) / iterations / tokens / cost / latency / error / created_at. Optional FK→usersON DELETE SET NULL(a deleted user doesn't erase history); partial index on(user_id, created_at).IAgentRunWriter(Ai.Core) +DbAgentRunWriter(Application/Ai, scoped — mirrorsDbLlmTraceWriter): flattens the framework-freeAgentRunRecordinto 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/Failedbuild a persistable record uniformly across outcomes.AgentBudgetExhaustedExceptionnow carries the partialSteps+Usageaccumulated before the cap — the run you most want to inspect is the one that ran out of budget.AgentLoopthrows with them at both the cost-cap and max-steps exits (additive; AI-034 tests still pass).steps_jsonis 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
AgentRunRecordFactorytests (completed / budget-exhausted-keeps-transcript / failed);AgentLoopbudget-exhaustion test now asserts the exception carries the partial transcript + usage.\d agent_run+ a jsonb insert/read roundtrip + FK + partial index verified on Postgres.TextStack.UnitTests(267) +TextStack.AiEvals(28) green;dotnet formatclean.🤖 Generated with Claude Code