refactor(agent): introduce durable run core#289
Draft
robelest wants to merge 1 commit into
Draft
Conversation
07d4c51 to
7126a06
Compare
commit: |
d1e4447 to
1c7134f
Compare
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.
Summary
Agent V2 is a breaking refactor that makes Agent a Convex-native durable execution primitive.
Agent now owns threads, messages, runs, tools, approvals, usage, structured output, cancellation, and run event streams.
@convex-dev/streamstores ordered run events. Apps compose auth, files, RAG, rate limits, billing, workflows, and provider SDKs outside Agent.Install Preview
Publint: https://publint.dev/pkg.pr.new/robelest/agent/@convex-dev/agent@f41be5f
Demo: https://tame-bloodhound-220.convex.site
Core API
Main namespaces:
Provider-Agnostic Models
Agent core no longer imports AI SDK types. Apps provide an
AgentModelthat yields Agent-owned events.OpenRouter in the demo is app-owned provider composition, not core Agent API.
Durable Runs
Start creates durable intent. Execute advances the run in an action. The browser should call a mutation; provider work stays in scheduled/internal actions.
Runs persist lifecycle, usage, output, result message IDs, cancellation, and stream correlation.
Tools And Approvals
Tools are Agent-native. Approval state is projected into bounded internal rows, so approval queries do not replay full streams.
React API
The primary React surface is
useAgent. Stream stays internal to Agent users.useAgentcombines Convex realtime messages, paginated history, Stream-backed run events, optimistic sends, approvals, usage, output, and cancellation.HTTP Run Streams
Agent serves run events through Stream’s HTTP protocol without exposing nested Stream component refs.
App-Owned Composition
Agent V2 deliberately moves cross-cutting product concerns out of the component. Agent should feel like an unopinionated primitive: it records durable agent work and exposes that work through runs, messages, tools, approvals, usage, output, and events. The app decides who may call it, what context to load, where files live, how retrieval works, when work is rate-limited, how workflows orchestrate it, and how usage becomes billing.
Auth/session stays in the app. Agent receives the already-authorized user/thread boundary.
Files stay in app storage. Agent messages keep typed file references, but Agent does not own file tables, dedupe, refcounts, parsing, or cleanup.
Context replaces Agent-owned memories/vector tables. Retrieval is an app policy that produces
AgentContextBlock[]forruns.execute.RAG stays app-owned. The app can use
@convex-dev/rag, OpenRouter embeddings, or any retriever, then pass search results as context.Rate limits stay app-owned. The app checks quota before starting or executing Agent work.
Workflows orchestrate Agent; Agent does not own workflow semantics. The app links external workflow IDs to runs when useful.
Billing stays app-owned. Agent records usage on the run; the app turns usage into invoices, credits, or ledger entries.
Demo
The example is now a support-case app:
@convex-dev/raguseAgentValidation
vp run typechecknpm run lintvp exec vitest runnpm run buildgit diff --checknpm run deploy:demo:devAll PR checks are currently green.
Notes
This PR is intentionally large. It is the clean-break Agent V2 branch, not a compatibility patch over the AI SDK/UIMessage-centered implementation.