@feltdb/feltkit 0.3.37 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent-engine.d.ts +93 -0
- package/dist/agent-engine.js +40 -0
- package/dist/agent-engine.js.map +1 -0
- package/dist/app.d.ts +306 -7
- package/dist/app.js +289 -28
- package/dist/app.js.map +1 -1
- package/dist/appboundry/build.d.ts +7 -0
- package/dist/appboundry/build.js +25 -1
- package/dist/appboundry/build.js.map +1 -1
- package/dist/appboundry/guest.js +8 -0
- package/dist/appboundry/guest.js.map +1 -1
- package/dist/appboundry/host.d.ts +21 -0
- package/dist/appboundry/host.js +25 -0
- package/dist/appboundry/host.js.map +1 -1
- package/dist/appboundry/runtime.js +1 -0
- package/dist/appboundry/runtime.js.map +1 -1
- package/dist/boards/index.d.ts +1258 -0
- package/dist/boards/index.js +1410 -0
- package/dist/boards/index.js.map +1 -0
- package/dist/boards/model.d.ts +177 -0
- package/dist/boards/model.js +177 -0
- package/dist/boards/model.js.map +1 -0
- package/dist/boards/react.d.ts +18 -0
- package/dist/boards/react.js +339 -0
- package/dist/boards/react.js.map +1 -0
- package/dist/cli/deploy-appboundry-self-hosted.js +2 -2
- package/dist/cli/deploy.js +19 -6
- package/dist/cli/deploy.js.map +1 -1
- package/dist/cli/main.js +70 -5
- package/dist/cli/main.js.map +1 -1
- package/dist/client/index.d.ts +454 -4
- package/dist/client/index.js +371 -3
- package/dist/client/index.js.map +1 -1
- package/dist/clock.d.ts +24 -0
- package/dist/clock.js +49 -0
- package/dist/clock.js.map +1 -0
- package/dist/cron.d.ts +18 -0
- package/dist/cron.js +67 -0
- package/dist/cron.js.map +1 -0
- package/dist/dashboard/assets/index-iIj7SL77.js +15 -0
- package/dist/dashboard/index.html +1 -1
- package/dist/docs.d.ts +1 -1
- package/dist/docs.js +4 -0
- package/dist/docs.js.map +1 -1
- package/dist/eve/index.d.ts +77 -0
- package/dist/eve/index.js +128 -0
- package/dist/eve/index.js.map +1 -0
- package/dist/event-stage.js +2 -0
- package/dist/event-stage.js.map +1 -1
- package/dist/index.d.ts +17 -2
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/native/build.d.ts +112 -0
- package/dist/native/build.js +472 -0
- package/dist/native/build.js.map +1 -0
- package/dist/native/index.d.ts +67 -0
- package/dist/native/index.js +113 -0
- package/dist/native/index.js.map +1 -0
- package/dist/native/instance.d.ts +3 -0
- package/dist/native/instance.js +18 -0
- package/dist/native/instance.js.map +1 -0
- package/dist/policy.d.ts +9 -1
- package/dist/policy.js +16 -3
- package/dist/policy.js.map +1 -1
- package/dist/presence.d.ts +85 -0
- package/dist/presence.js +37 -0
- package/dist/presence.js.map +1 -0
- package/dist/quota.d.ts +72 -0
- package/dist/quota.js +143 -0
- package/dist/quota.js.map +1 -0
- package/dist/react/agent-control.d.ts +191 -0
- package/dist/react/agent-control.js +366 -0
- package/dist/react/agent-control.js.map +1 -0
- package/dist/react/auth.d.ts +15 -1
- package/dist/react/auth.js +28 -5
- package/dist/react/auth.js.map +1 -1
- package/dist/react/hooks.d.ts +88 -0
- package/dist/react/hooks.js +188 -0
- package/dist/react/hooks.js.map +1 -0
- package/dist/react/index.d.ts +5 -75
- package/dist/react/index.js +4 -145
- package/dist/react/index.js.map +1 -1
- package/dist/runtime/activity.d.ts +8 -0
- package/dist/runtime/activity.js.map +1 -1
- package/dist/runtime/agent-control.d.ts +28 -0
- package/dist/runtime/agent-control.js +43 -2
- package/dist/runtime/agent-control.js.map +1 -1
- package/dist/runtime/agent-run.d.ts +166 -0
- package/dist/runtime/agent-run.js +431 -0
- package/dist/runtime/agent-run.js.map +1 -0
- package/dist/runtime/agent.d.ts +158 -1
- package/dist/runtime/agent.js +345 -12
- package/dist/runtime/agent.js.map +1 -1
- package/dist/runtime/assemble.js +15 -2
- package/dist/runtime/assemble.js.map +1 -1
- package/dist/runtime/authority.d.ts +47 -0
- package/dist/runtime/authority.js +13 -2
- package/dist/runtime/authority.js.map +1 -1
- package/dist/runtime/capabilities.js +2 -1
- package/dist/runtime/capabilities.js.map +1 -1
- package/dist/runtime/changes.d.ts +17 -0
- package/dist/runtime/changes.js +65 -2
- package/dist/runtime/changes.js.map +1 -1
- package/dist/runtime/context.d.ts +123 -0
- package/dist/runtime/contract.js +9 -3
- package/dist/runtime/contract.js.map +1 -1
- package/dist/runtime/events.js +17 -1
- package/dist/runtime/events.js.map +1 -1
- package/dist/runtime/integrations.js +7 -7
- package/dist/runtime/integrations.js.map +1 -1
- package/dist/runtime/invocations.d.ts +19 -2
- package/dist/runtime/invocations.js +16 -3
- package/dist/runtime/invocations.js.map +1 -1
- package/dist/runtime/policies.d.ts +5 -2
- package/dist/runtime/policies.js.map +1 -1
- package/dist/runtime/presence-host.d.ts +84 -0
- package/dist/runtime/presence-host.js +303 -0
- package/dist/runtime/presence-host.js.map +1 -0
- package/dist/runtime/providers.d.ts +5 -1
- package/dist/runtime/providers.js +11 -5
- package/dist/runtime/providers.js.map +1 -1
- package/dist/runtime/required-capabilities.d.ts +73 -0
- package/dist/runtime/required-capabilities.js +69 -0
- package/dist/runtime/required-capabilities.js.map +1 -0
- package/dist/runtime/resource-access.d.ts +137 -0
- package/dist/runtime/resource-access.js +177 -0
- package/dist/runtime/resource-access.js.map +1 -0
- package/dist/runtime/runtime.d.ts +143 -1
- package/dist/runtime/runtime.js +853 -44
- package/dist/runtime/runtime.js.map +1 -1
- package/dist/runtime/sessions.d.ts +12 -0
- package/dist/runtime/sessions.js +16 -1
- package/dist/runtime/sessions.js.map +1 -1
- package/dist/runtime/tenancy.d.ts +68 -1
- package/dist/runtime/tenancy.js +150 -0
- package/dist/runtime/tenancy.js.map +1 -1
- package/dist/runtime/transactions.d.ts +3 -1
- package/dist/runtime/transactions.js.map +1 -1
- package/dist/runtime/workers.d.ts +123 -0
- package/dist/runtime/workers.js +291 -0
- package/dist/runtime/workers.js.map +1 -0
- package/dist/server/eve.d.ts +287 -0
- package/dist/server/eve.js +1071 -0
- package/dist/server/eve.js.map +1 -0
- package/dist/server/index.d.ts +2 -19
- package/dist/server/index.js +102 -5
- package/dist/server/index.js.map +1 -1
- package/dist/server/mcp.d.ts +15 -22
- package/dist/server/mcp.js +40 -3
- package/dist/server/mcp.js.map +1 -1
- package/dist/server/project.js +26 -8
- package/dist/server/project.js.map +1 -1
- package/dist/server/tenancy.d.ts +9 -0
- package/dist/server/tenancy.js +62 -1
- package/dist/server/tenancy.js.map +1 -1
- package/dist/server/watch.d.ts +10 -0
- package/dist/server/watch.js +88 -0
- package/dist/server/watch.js.map +1 -0
- package/dist/testing/index.d.ts +4 -5
- package/dist/testing/index.js +3 -2
- package/dist/testing/index.js.map +1 -1
- package/docs/AGENT-CONTROL.md +166 -4
- package/docs/APPBOUNDRY.md +73 -0
- package/docs/ARCHITECTURE.md +6 -2
- package/docs/AUTH.md +37 -0
- package/docs/COMPONENTS.md +71 -0
- package/docs/EVE-COMPOSITION.md +75 -0
- package/docs/GUARANTEES.md +4 -4
- package/docs/NATIVE-AGENTS.md +353 -0
- package/docs/NATIVE.md +137 -0
- package/docs/PRESENCE-AND-SIGNALING-PROPOSAL.md +152 -0
- package/docs/README.md +6 -2
- package/docs/SECURITY.md +71 -3
- package/docs/TRANSACTIONS.md +48 -0
- package/docs/UPSTREAM-GAPS.md +16 -2
- package/package.json +42 -16
- package/skills/.claude-plugin/marketplace.json +1 -1
- package/skills/.claude-plugin/plugin.json +1 -1
- package/skills/feltkit-agent/SKILL.md +1 -1
- package/skills/feltkit-build/SKILL.md +11 -1
- package/skills/feltkit-data/SKILL.md +1 -1
- package/skills/feltkit-operations/SKILL.md +1 -1
- package/skills/feltkit-services/SKILL.md +1 -1
- package/dist/dashboard/assets/index-BhxrvY37.js +0 -15
package/docs/COMPONENTS.md
CHANGED
|
@@ -67,6 +67,77 @@ export default defineComponent(async (ctx) => {
|
|
|
67
67
|
});
|
|
68
68
|
```
|
|
69
69
|
|
|
70
|
+
## Pattern: a media worker (an SFU adapter, a recording bot)
|
|
71
|
+
|
|
72
|
+
A video call's media does not flow through FeltKit: browsers send it peer to peer, or to a media server (an SFU).
|
|
73
|
+
What belongs to the application is the authority around it: who may join which call's media, who may record it,
|
|
74
|
+
which bot is in which call, and what happened. A media worker is a component that holds that line. Everything below
|
|
75
|
+
uses only the contract above (`ComponentContext`, `ctx.afterCommit.work`, `ctx.work`) and functions; nothing here is
|
|
76
|
+
a separate API.
|
|
77
|
+
|
|
78
|
+
| Need | How |
|
|
79
|
+
|---|---|
|
|
80
|
+
| Identity | `principal: { id: "component:media", roles: ["media"] }`: a service principal with its own declared roles, never a person's. |
|
|
81
|
+
| Which calls it may touch | Functions it calls declare `resource: { collection: calls, id: "callId", agents: "grant" }`; a host admits it to one call with `ctx.grants.admitAgent(calls, callId, "component:media")` (declared components are known principals). Without that grant every call is FORBIDDEN, and revoking the grant stops it on the next call. |
|
|
82
|
+
| Starting work | A mutation records it in its own transaction: `ctx.afterCommit.work("media", "record", { callId })`. It exists exactly when the host's "start recording" commits. |
|
|
83
|
+
| Doing work | The component claims (`ctx.work.claim({ kinds: ["record"], leaseMs })`), acts, and settles (`ctx.work.finish(item, { outcome: "done", receipt })`). A worker that dies leaves the item claimable again with `resumed: true`; an upload that may have happened is settled `unknown`, never retried blindly. |
|
|
84
|
+
| Being present in the call | The worker calls a mutation that holds an `app.presence` lease for it (`ctx.presence.join(peers, …)` as `component:media`) and renews it on a timer shorter than `ttlMs`. If the worker or its process stops, the lease expires and the call's live queries show it gone; `onEnd` can settle the call. (`bind: "session"` needs a session; a component has none, so it renews.) |
|
|
85
|
+
| Browsers reaching the media server | Not with a FeltKit session token: a mutation (`media:ticket`, resource-bound to the call) authorizes the person and records a one-time ticket (`await ctx.crypto.token()` as its id, with an expiry); the browser presents it on the component's WebSocket route (`websocket: true`); the component redeems it with `ctx.call("media:redeem", { ticket })` (marks it used, returns who and which call) before it lets the connection signal. The component authenticates its own traffic; FeltKit's routes stay FeltKit's. |
|
|
86
|
+
| SFU credentials | `credentials: ["sfu-api-key"]`, read with `ctx.credential("sfu-api-key")` (`FELTKIT_CREDENTIAL_SFU_API_KEY` in production). `network: "egress"` for the SFU's API. |
|
|
87
|
+
| Signing room tokens for the SFU | `ctx.derive("sfu-room-token")`: stable secret material for this application, never in the artifact. |
|
|
88
|
+
| Health | `health()` with named checks, e.g. `{ state: "degraded", checks: { signaling: { state: "ready" }, sfu: { state: "failed", detail: "SFU unreachable" } } }`. Mark it `required: false` if calls should still work (chat, presence) while recording is down; the application then reports `partial` instead of being unavailable. |
|
|
89
|
+
| Results | The worker writes what it produced through a mutation (`ctx.call("recordings:store", { callId, file })`) under its grant, so the record, its evidence and Activity are the application's like any other write. |
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
// feltkit/app.ts (excerpt)
|
|
93
|
+
components: {
|
|
94
|
+
media: { entry: "media/component.ts", routes: ["/media/"], websocket: true, required: false,
|
|
95
|
+
principal: { id: "component:media", roles: ["media"] }, credentials: ["sfu-api-key"] },
|
|
96
|
+
},
|
|
97
|
+
|
|
98
|
+
// media/component.ts
|
|
99
|
+
import { defineComponent } from "@feltdb/feltkit/server";
|
|
100
|
+
export default defineComponent(async (ctx) => {
|
|
101
|
+
const sfu = connectSfu(await ctx.credential("sfu-api-key")); // your SFU client
|
|
102
|
+
let stopped = false;
|
|
103
|
+
const loop = (async () => {
|
|
104
|
+
while (!stopped) {
|
|
105
|
+
for (const item of await ctx.work.claim({ kinds: ["record"], leaseMs: 120_000 })) {
|
|
106
|
+
const { callId } = item.input as { callId: string };
|
|
107
|
+
const lease = await ctx.call("peers:joinAsBot", { callId, name: "Recorder" }); // FORBIDDEN without a grant
|
|
108
|
+
const renew = setInterval(() => void ctx.call("peers:renew", { id: lease.id }).catch(() => undefined), 20_000);
|
|
109
|
+
try {
|
|
110
|
+
const file = await sfu.record(callId);
|
|
111
|
+
await ctx.call("recordings:store", { callId, file });
|
|
112
|
+
await ctx.work.finish(item, { outcome: "done", receipt: { file } });
|
|
113
|
+
} catch (error) {
|
|
114
|
+
await ctx.work.finish(item, { outcome: "retry", error: { message: (error as Error).message } });
|
|
115
|
+
} finally {
|
|
116
|
+
clearInterval(renew);
|
|
117
|
+
await ctx.call("peers:leave", { id: lease.id }).catch(() => undefined);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
await new Promise((r) => setTimeout(r, 1_000));
|
|
121
|
+
}
|
|
122
|
+
})();
|
|
123
|
+
return {
|
|
124
|
+
upgrade: (request, socket, head) => sfu.acceptSignaling(request, socket, head, (ticket) => ctx.call("media:redeem", { ticket })),
|
|
125
|
+
health: async () => ({ state: (await sfu.ping()) ? "ready" : "degraded", checks: { sfu: { state: (await sfu.ping()) ? "ready" : "failed" } } }),
|
|
126
|
+
close: async () => { stopped = true; await loop; await sfu.close(); },
|
|
127
|
+
};
|
|
128
|
+
});
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
What this pattern does not give you:
|
|
132
|
+
- **FeltKit does not relay media**, and a component cannot subscribe to `app.event`/`app.channel` messages (its
|
|
133
|
+
context has no subscription). Signaling for the SFU goes over the component's own WebSocket route; signaling between
|
|
134
|
+
browsers can use `app.channel`.
|
|
135
|
+
- **Preemption of media**: ending someone's lease or revoking a grant stops the worker's next function call, not
|
|
136
|
+
packets already flowing to the SFU. Tell the SFU to drop the participant when your onEnd agent or revoking mutation
|
|
137
|
+
runs (from the worker, which polls its work, or as `afterCommit.work("media", "kick", …)`).
|
|
138
|
+
- **On AppBoundry** the component runs as a companion beside the guest only where a host enabled companions; presence,
|
|
139
|
+
channels, guest links and grants are FeltKit runtime features that the AppBoundry build refuses today.
|
|
140
|
+
|
|
70
141
|
## On AppBoundry (`components@1`)
|
|
71
142
|
|
|
72
143
|
An `appboundry.app/1` guest is a WebAssembly module with no network, no secrets, JSON-only routes and no
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# EVE and FeltKit: standalone runtime, composed host
|
|
2
|
+
|
|
3
|
+
Status: Phase 0 (investigation). Decisions below are proposals backed by the evidence cited; nothing here is
|
|
4
|
+
implemented yet.
|
|
5
|
+
|
|
6
|
+
## The boundary
|
|
7
|
+
|
|
8
|
+
| | Owns | Standalone | Composed into FeltKit |
|
|
9
|
+
|---|---|---|---|
|
|
10
|
+
| **EVE** | the agent: authoring (agent directory), compilation, the turn loop, tools, model adaptation, skills, subagents, sandboxes, runtime semantics | its own host (Nitro), its own World (local SQLite, Postgres), its own credentials | the same compiled agent, unchanged |
|
|
11
|
+
| **Host** | durable execution state, capability discovery and authority, identity, approvals, budgets, evidence, operations | EVE's World + tools | FeltDB (a FeltDB World), AppPort, FeltKit identity and approvals, Studio |
|
|
12
|
+
|
|
13
|
+
EVE must not need FeltKit; FeltKit must not give up its control plane to run EVE. The seam is EVE's existing
|
|
14
|
+
Workflow **World** interface, plus a small number of host services EVE calls (tools, model, memory).
|
|
15
|
+
|
|
16
|
+
## Where the run lives
|
|
17
|
+
|
|
18
|
+
EVE's durable execution is event-sourced through its World: each run is an append-only event log with gap-free
|
|
19
|
+
positions and an in-band fence (spec 9); runs, steps, hooks and waits are views of it; delivery is a queue whose
|
|
20
|
+
handler EVE registers in-process; session output is per-run streams. Session state lives entirely in the World
|
|
21
|
+
(`packages/eve/src/execution/durable-session-store.ts` only shapes it). The World is selected per agent build
|
|
22
|
+
(`experimental.workflow.world`), and nothing in it is Vercel-specific.
|
|
23
|
+
|
|
24
|
+
**Decision (proposed): when composed, the run lives in FeltDB through a FeltDB World.** EVE keeps its execution
|
|
25
|
+
model; FeltDB is the only authoritative store. FeltKit does not keep a second transcript or a second lease for EVE
|
|
26
|
+
runs: the World's event log and in-band fence are the run's record and its fencing. FeltKit keeps the
|
|
27
|
+
application-facing record (owner, workspace, approvals, evidence) as an agent task linked to the run id.
|
|
28
|
+
|
|
29
|
+
Measured evidence for feasibility (Workflow World 5.2.2):
|
|
30
|
+
|
|
31
|
+
- Every World write is "read the run, compare-and-set, append at the next position, update the run" in one
|
|
32
|
+
transaction: FeltDB's `ifVersion` + `requireAbsent` multi-record transactions.
|
|
33
|
+
- Delivery: a durable queue (visibility time, lease, delivery count, stable message id, idempotency keys, delayed
|
|
34
|
+
messages for timers, one orchestrator delivery per run). The local World keeps its queue in memory and
|
|
35
|
+
re-enqueues on start; a FeltDB World keeps it in FeltDB and wakes from the commit listener.
|
|
36
|
+
- Streams: append-only chunks keyed `(name, index)`, live tails from the commit listener.
|
|
37
|
+
- Size: comparable to `@workflow/world-postgres` (about 8k lines). Conformance: Workflow ships suites for the
|
|
38
|
+
in-band fence and start-hook admission; queue, streams and views are covered by EVE's own World e2e matrix
|
|
39
|
+
(`e2e/matrix.json`, `EVE_E2E_WORKFLOW_WORLD`).
|
|
40
|
+
|
|
41
|
+
## Collisions to resolve
|
|
42
|
+
|
|
43
|
+
| | EVE today | FeltKit today | Proposal |
|
|
44
|
+
|---|---|---|---|
|
|
45
|
+
| Durable run | World event log (SQLite) | agent task, transcript, lease (slices 1–2) | World event log in FeltDB; the task references it; no FeltKit transcript or lease for EVE runs |
|
|
46
|
+
| Fencing and recovery | in-band fence, queue redelivery, `reenqueueActiveRuns` | run lease, reconciliation | EVE's, over FeltDB. FeltKit reconciliation keeps only what is the host's: proposals waiting for people |
|
|
47
|
+
| Tool calls with effects | EVE tools; `approval` policies held in session state | AppPort capabilities as proposals; people approve; AppPort executes | Host tools are AppPort capabilities. A consequential call is a FeltKit proposal; the EVE tool waits on a hook; the approval decision resumes the hook. EVE's own approval policy is `never` for host tools: the host decides |
|
|
48
|
+
| Authority | the session's auth; tool-level checks | AppPort roles, tenancy, AuthBoundry | the agent's principal and tenant come from the host; every host tool call is authorized by AppPort at execution |
|
|
49
|
+
| Model and credentials | AI SDK providers with EVE's own credentials | environment model selection, credential custody, recorded generations | a host-provided model resolver: EVE asks the host for the model; credentials never enter EVE |
|
|
50
|
+
| Budgets | EVE's turn limits | durable budgets (slice 2) | enforced at the host boundaries: model resolver (generations, tokens) and tool calls; turns by EVE |
|
|
51
|
+
| Memory | `.eve/memory` files (authoritative) | FeltDB | a FeltDB memory backend |
|
|
52
|
+
| Hosting | Nitro server per agent | one FeltKit process | open question below |
|
|
53
|
+
|
|
54
|
+
## Node.js
|
|
55
|
+
|
|
56
|
+
EVE builds and tests on Node 26 (`.nvmrc`); its shipped code needs Node 24+ in one place (`AsyncDisposableStack`
|
|
57
|
+
in `eve dev`) plus the CLI's version gate. Its unit tier passes on Node 22 except for those (9351 of 9387). The
|
|
58
|
+
stack standardizes on **Node 26**: FeltKit, AppPort, AppPort Services and FeltDB move up, rather than EVE down.
|
|
59
|
+
|
|
60
|
+
## Open questions for the next prototype
|
|
61
|
+
|
|
62
|
+
1. **Hosting EVE inside FeltKit's process.** EVE's published runtime is a compiled agent behind a Nitro handler.
|
|
63
|
+
Either FeltKit mounts that handler in its own HTTP server (one process, one deploy), or EVE gains a headless
|
|
64
|
+
host entry. Prototype the first; it changes nothing in EVE.
|
|
65
|
+
2. **Hooks as the approval wait.** Confirm an EVE tool can suspend on a hook and be resumed by a FeltKit decision
|
|
66
|
+
without EVE's HITL approval state.
|
|
67
|
+
3. **Model resolver.** Confirm EVE's model call can be routed through a host-supplied resolver.
|
|
68
|
+
4. **Spec churn.** EVE pins Workflow versions and checks World compatibility (`validate-world.ts`); a FeltDB World
|
|
69
|
+
must track every Workflow upgrade.
|
|
70
|
+
|
|
71
|
+
## Distribution
|
|
72
|
+
|
|
73
|
+
`@appport/eve` is built from this fork and published (1.0.2, 1.1.0) by `npm run publish:packages` (version-stamped,
|
|
74
|
+
clean-tree, refuses re-publishing). A local repack of 1.1.0 from the same commit has a different integrity than the
|
|
75
|
+
published tarball: packing is not byte-reproducible yet.
|
package/docs/GUARANTEES.md
CHANGED
|
@@ -184,10 +184,10 @@ code in their text. `FeltKitClientError` exposes `code` and `retryable`.
|
|
|
184
184
|
| The current state does not allow it | `FAILED_PRECONDITION` | `feltkit.FAILED_PRECONDITION` | 409 | no |
|
|
185
185
|
| A record this mutation read changed before commit | `CONFLICT` | `CONFLICT` | 409 | **yes** |
|
|
186
186
|
| Any other state conflict (duplicate unique value, already applied) | `CONFLICT` | `CONFLICT` | 409 | no |
|
|
187
|
-
| An external API (`app.integration`) refused the request (4xx) | `UPSTREAM_REJECTED` | `UPSTREAM_REJECTED`, `details.status` = the API's status | 502 | no |
|
|
188
|
-
| The request was sent; the outcome is not known | `OUTCOME_UNKNOWN` | `
|
|
189
|
-
| A dependency is unreachable | `UNAVAILABLE` | `UNAVAILABLE` | 503 | **yes** |
|
|
190
|
-
| A credential or URL an operator must provide is missing | `CONFIGURATION` | `NOT_CONFIGURED` (`details.hint`) | 503 | no |
|
|
187
|
+
| An external API (`app.integration`) refused the request (4xx) | `UPSTREAM_REJECTED` | `feltkit.UPSTREAM_REJECTED`, `details.status` = the API's status | 502 | no |
|
|
188
|
+
| The request was sent; the outcome is not known | `OUTCOME_UNKNOWN` | `CONFLICT`, `details.reason: EFFECT_OUTCOME_UNKNOWN` (AppPort's `outcomeUnknown`; `classifyOutcome` answers `unknown`) | 502 (`/api`), 409 (`/appport`) | no: ask `appport.invocation.status`, verify it |
|
|
189
|
+
| A dependency is unreachable | `UNAVAILABLE` | `feltkit.UNAVAILABLE` | 503 | **yes** |
|
|
190
|
+
| A credential or URL an operator must provide is missing | `CONFIGURATION` | `feltkit.NOT_CONFIGURED` (`details.hint`) | 503 | no |
|
|
191
191
|
| Unexpected | `INTERNAL` | `INTERNAL_ERROR` | 500 | no |
|
|
192
192
|
|
|
193
193
|
An external API's 401 or 404 is `UPSTREAM_REJECTED`: it is about FeltKit's credential for that
|
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
# Native agents
|
|
2
|
+
|
|
3
|
+
An application declares an agent the way it declares a collection or a mutation. FeltKit runs it in the
|
|
4
|
+
application's own process, on the application's own FeltDB instance, through the application's own AppPort
|
|
5
|
+
capabilities and authority. There is no agent server, agent database, agent container or second runtime to
|
|
6
|
+
deploy. `feltkit deploy` ships the agent with the app, and the app's health, restart, backup and Studio cover it.
|
|
7
|
+
|
|
8
|
+
Code: `packages/sdk/src/app.ts` (`app.agent`), `src/agent-engine.ts` (engines), `src/runtime/agent-run.ts` (the
|
|
9
|
+
run, its lease, budgets, output), `src/runtime/agent.ts` (tasks, proposals, approvals, generations, the approvals
|
|
10
|
+
inbox), `src/runtime/runtime.ts` (`reconcileAgentRuns`).
|
|
11
|
+
Tests: `packages/sdk/test/native-agents.test.ts`, `test/native-agents-recovery.test.ts`,
|
|
12
|
+
`test/native-agents-security.test.ts`, `test/native-agents-limits.test.ts`, `tests/e2e/native-agents.test.mjs`
|
|
13
|
+
(deployed artifact). Example: `examples/approvals`.
|
|
14
|
+
|
|
15
|
+
## One declaration, three kinds of agent
|
|
16
|
+
|
|
17
|
+
`app.agent(name, …)` takes exactly one of `handler`, `instructions` or `project`:
|
|
18
|
+
|
|
19
|
+
- `handler`: a deterministic agent, a mutation (below).
|
|
20
|
+
- `instructions` + `tools`: a reasoning agent run by FeltKit's in-process engine (below).
|
|
21
|
+
- `project`: an agent that runs on the agent runtime from its own project directory (`agent/`), built and supervised
|
|
22
|
+
by FeltKit, acting only through the capabilities it names, in a workspace as a member with `tenantRole`, under the
|
|
23
|
+
work grant of the person working with it, with a person's approval of each exact call that needs one:
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
export const helper = app.agent("helper", { project: ".", displayName: "Product agent", roles: ["agent"], tenantRole: "agent", capabilities: ["product.*"] });
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
The browser reaches it with `client.agent("helper")`. `feltkit({ eve: { … } })` is the same declaration and keeps
|
|
30
|
+
working; see [EVE-COMPOSITION.md](EVE-COMPOSITION.md) for how the runtime is hosted.
|
|
31
|
+
|
|
32
|
+
**Direction:** one reasoning runtime. New reasoning agents use `project`. The in-process engine (`instructions`)
|
|
33
|
+
stays supported for existing applications; it is not removed until a reasoning agent declared with `instructions`
|
|
34
|
+
can run on the agent runtime unchanged (same tools, approvals, budgets, output contracts and durable transcript),
|
|
35
|
+
proven by this file's tests passing against it, and a release has deprecated it first.
|
|
36
|
+
|
|
37
|
+
## Handler and in-process reasoning agents
|
|
38
|
+
|
|
39
|
+
`app.agent(name, { principal, roles, access, on?, retry?, leaseMs?, … })` declares an agent: an identity
|
|
40
|
+
(principal type `agent`), its authority (`roles`, and nothing else), and what triggers it. Then exactly one of:
|
|
41
|
+
|
|
42
|
+
| | `handler` (deterministic) | `instructions` + `tools` (reasoning) |
|
|
43
|
+
|---|---|---|
|
|
44
|
+
| What runs | your function, as a mutation: one transaction | turns: an engine decides, FeltKit executes |
|
|
45
|
+
| Model | none | the engine's choice: the environment's model, rules, or your own |
|
|
46
|
+
| State | `ctx.db`, written once per trigger | a durable task, transcript and actions in FeltDB |
|
|
47
|
+
| Effects | the mutation's writes and `ctx.afterCommit` | AppPort capability calls, authorized and evidenced one by one |
|
|
48
|
+
| Waits for people | no | yes: approvals, pause/resume, updates |
|
|
49
|
+
|
|
50
|
+
Both are triggered the same way: `ctx.afterCommit.agent(name, input)` from a mutation, or an `app.event` named in
|
|
51
|
+
`on`. A recurring schedule starts one through existing primitives: the schedule enqueues a job, and the job's
|
|
52
|
+
handler (`services.jobs.handlers`) is a mutation that stages the agent. The job runs as the schedule's creator, only
|
|
53
|
+
while that principal still resolves (a live session or API key).
|
|
54
|
+
|
|
55
|
+
## A reasoning agent
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
// feltkit/triage.ts
|
|
59
|
+
import { s } from "@feltdb/feltkit";
|
|
60
|
+
import { app } from "./app.js";
|
|
61
|
+
import { getTicket, setPriority, closeTicket } from "./tickets.js";
|
|
62
|
+
|
|
63
|
+
export const triage = app.agent("triage", {
|
|
64
|
+
principal: { id: "triage", displayName: "Triage" },
|
|
65
|
+
roles: ["triager"], // its authority: e.g. ["tickets.read", "tickets.prioritize", "tickets.close", "feltkit.agent.write"]
|
|
66
|
+
access: "tickets.read", // the permission it needs to run at all
|
|
67
|
+
input: { ticketId: s.string() }, // validated before a run starts
|
|
68
|
+
instructions: "Read the ticket with tickets_get, then set its priority with tickets_prioritize.",
|
|
69
|
+
tools: [getTicket, setPriority, closeTicket], // published capabilities, by definition
|
|
70
|
+
autonomous: [setPriority], // consequential tools it may run without a person (your policy)
|
|
71
|
+
limits: { maxTurns: 8, maxToolCalls: 20 },
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// feltkit/tickets.ts: a person opens a ticket; triage runs after the commit
|
|
75
|
+
export const open = app.mutation({
|
|
76
|
+
access: "tickets.write",
|
|
77
|
+
args: { title: s.string() },
|
|
78
|
+
handler: async (ctx, { title }) => {
|
|
79
|
+
const ticketId = await ctx.db.insert(tickets, { title, status: "open" });
|
|
80
|
+
ctx.afterCommit.agent("triage", { ticketId });
|
|
81
|
+
return ticketId;
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
The application never imports an agent framework or a model SDK. Which model decides is the environment's
|
|
87
|
+
configuration (Studio → Models, `feltkit model set`, or a Resolver reference): switching provider or model is a
|
|
88
|
+
configuration change, not a redeploy, and no agent definition names one.
|
|
89
|
+
|
|
90
|
+
### What the declaration checks
|
|
91
|
+
|
|
92
|
+
- `tools` and `autonomous` are this app's functions **published as capabilities** (`capability: "…"`): the agent
|
|
93
|
+
reaches them through AppPort like any other caller, never by calling the function.
|
|
94
|
+
- `autonomous` is a subset of `tools`.
|
|
95
|
+
- The agent's roles grant `feltkit.agent.write` (it records its own work as agent tasks). Checked when the runtime
|
|
96
|
+
starts: a missing grant stops the start with the agent's name and the fix.
|
|
97
|
+
- Exactly one of `handler` and `instructions`.
|
|
98
|
+
|
|
99
|
+
## How a run works
|
|
100
|
+
|
|
101
|
+
A run is driven by outbox records (its trigger, and later resumes), each attempt claimed and retried with backoff
|
|
102
|
+
like every `app.agent` run, as the agent's own principal through the same call path as any request (roles →
|
|
103
|
+
`access` → `feltkit({ authorize })` → activity log). An attempt executes the run only while it holds the run's
|
|
104
|
+
lease, and continues from what FeltDB holds:
|
|
105
|
+
|
|
106
|
+
| Durable state | Where | Written |
|
|
107
|
+
|---|---|---|
|
|
108
|
+
| the task | FeltDB agent state, keyed by the run (`openTask`) | once per run |
|
|
109
|
+
| the run record: agent, definition version, engine, input, tenant | task memory `<task>.run` | once |
|
|
110
|
+
| the lease: which attempt executes the run, until when, why the last one ended | task memory `<task>.lease-eNNNN-rNNNN` | a compare-and-set chain (FeltDB supersede) |
|
|
111
|
+
| the transcript: input, each turn, each tool result, each person's update, each output refusal | task memory `<task>.msg-NNNN` | each message once, at a fixed id (FeltDB `requireAbsent`) |
|
|
112
|
+
| the validated output | task memory `<task>.output` | once |
|
|
113
|
+
| each tool call: proposal, approval, execution, outcome | action records (agent memory chains) | per state transition |
|
|
114
|
+
| each model generation: model, timing, usage, outcome | generation records | per state transition |
|
|
115
|
+
| each repair by reconciliation | task memory `<task>.recovery-…`, activity `agent.run.recovered` | once per repair |
|
|
116
|
+
|
|
117
|
+
One step looks only at the transcript's last message:
|
|
118
|
+
|
|
119
|
+
```
|
|
120
|
+
assistant asked for tools ──▶ each call is a proposal keyed <message>:<call id>
|
|
121
|
+
observation runs now, as the agent
|
|
122
|
+
consequential waits for a person, unless declared autonomous
|
|
123
|
+
any call waiting the attempt releases the run "waiting", naming the actions
|
|
124
|
+
all answered the tool results are appended
|
|
125
|
+
assistant answered only ──▶ output contract checked (if any); the task completes
|
|
126
|
+
anything else ──▶ budgets, checkpoint (pause, interrupt, updates), then the engine's next turn
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Ownership and fencing
|
|
130
|
+
|
|
131
|
+
The lease is a chain of FeltDB memory records, each superseding the last in one compare-and-set transaction:
|
|
132
|
+
`lease-e0001-r0000` (taken), `…-r0001` (renewed), …, `…-rNNNN` with `released` (why the attempt ended). Taking the
|
|
133
|
+
run is a new epoch, allowed only from a released lease or one whose holder stopped renewing past `until`; the new
|
|
134
|
+
link records `takeover: { fromEpoch, fromHolder, because }`. A live attempt renews every third of the lease (half the
|
|
135
|
+
agent's `leaseMs`, so 60 s by default).
|
|
136
|
+
|
|
137
|
+
An attempt checks that its link is still the active one before every durable write: appending to the transcript,
|
|
138
|
+
proposing, running an autonomous call, recording the output, completing or stopping. An attempt that lost the run
|
|
139
|
+
stops there (`CONFLICT`, `RUN_FENCED`); its in-flight model call is aborted. An attempt that finds the run held by a
|
|
140
|
+
live attempt is refused (`RUN_BUSY`) and its outbox record is tried again with backoff.
|
|
141
|
+
|
|
142
|
+
| A stale attempt cannot | because |
|
|
143
|
+
|---|---|
|
|
144
|
+
| append a turn that conflicts | messages are written once at fixed ids: the first write stands, and a loser adopts it (recording that its turn was discarded) |
|
|
145
|
+
| create competing proposals | proposals are keyed by the message and call id; the same key is the same proposal |
|
|
146
|
+
| run an action twice | approval is a compare-and-set on the action record; execution happens once per approval |
|
|
147
|
+
| complete, stop or continue the run | each of those is preceded by the lease check |
|
|
148
|
+
| resume an obsolete execution | a resume is a new attempt: it takes the lease and reads the run as it is now |
|
|
149
|
+
|
|
150
|
+
**Model inference is not exactly-once.** If an attempt's lease lapses while it is deciding (a frozen process) and
|
|
151
|
+
another attempt takes the run, both may compute the same turn. Only one becomes durable; the other is a recorded
|
|
152
|
+
generation and nothing else. Provider retries after an uncertain failure also repeat inference. Budgets count every
|
|
153
|
+
generation, so repeated inference is bounded.
|
|
154
|
+
|
|
155
|
+
### Lifecycle
|
|
156
|
+
|
|
157
|
+
Four records each own one part; the run's state is derived from them, never stored twice.
|
|
158
|
+
|
|
159
|
+
```
|
|
160
|
+
Task (FeltDB) ready ─▶ running ⇄ blocked ─▶ completed
|
|
161
|
+
└──────────────▶ cancelled (a person's stop, or a budget)
|
|
162
|
+
|
|
163
|
+
Lease (per attempt) (none) ─acquire▶ held ─renew▶ held ─release▶ released{completed|stopped|waiting|held|error}
|
|
164
|
+
└─ not renewed past until ─▶ expired ─acquire (new epoch)▶ held
|
|
165
|
+
released ─acquire (new epoch)▶ held
|
|
166
|
+
|
|
167
|
+
Action (proposal) proposed ─approve (a person, or the agent's autonomous policy)▶ approved ─▶ executing ─▶ succeeded | failed
|
|
168
|
+
│ └─ outcome unknown ─▶ interrupted ─settle▶ succeeded | failed
|
|
169
|
+
├─reject (a person)▶ rejected
|
|
170
|
+
└─expire / task cancelled▶ cancelled
|
|
171
|
+
approved ─(process stopped before executing; next start)▶ proposed (approval asked again)
|
|
172
|
+
failed ─retry (owner or a person)▶ proposed
|
|
173
|
+
|
|
174
|
+
Outbox (per attempt) pending ─claim▶ performing ─▶ done (result.run: the attempt's outcome)
|
|
175
|
+
├─ RUN_BUSY / error with retries left ─▶ pending (notBefore)
|
|
176
|
+
├─ error, terminal (CONFIGURATION, permission, attempts spent) ─▶ failed
|
|
177
|
+
└─ claim stale ─▶ claimed again (the run lease decides who executes)
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
| Transition | Owner | Authorized by | Persisted as | Idempotent | Reconciled when lost |
|
|
181
|
+
|---|---|---|---|---|---|
|
|
182
|
+
| start a run | a committed mutation / event / job | the agent's roles + `access` | outbox record, then task + run record | trigger id = run id | outbox recovery |
|
|
183
|
+
| take / renew / release the run | the attempt | holding the lease | lease chain | compare-and-set | expired lease → resume |
|
|
184
|
+
| append a turn or result | the lease holder | the lease | `msg-NNNN` | fixed id | next attempt continues |
|
|
185
|
+
| propose a call | the lease holder | the agent's roles, now | action record | key `msg:call` | next attempt re-proposes, same key |
|
|
186
|
+
| approve / reject | a person in the workspace who may perform it | AuthBoundry/roles at approval, owner rechecked | action record | compare-and-set; repeated decision answers current state | `decided:` → resume |
|
|
187
|
+
| approve autonomously | the lease holder | `autonomous` policy; never `approval: "required"` | action record (`policy:agent/<name>`) | compare-and-set | next attempt |
|
|
188
|
+
| expire | reconciliation, or an approval attempt | the proposal's `expiresAt` | action record (`cancelled`, `feltkit:expiry`) | compare-and-set | the pass that expires it resumes the run |
|
|
189
|
+
| pause / resume | a person | `feltkit.agent.write` | control record | revisioned | `unheld:` → resume |
|
|
190
|
+
| complete / stop | the lease holder | the lease; open actions refuse completion | task checkpoint | terminal | `unfinished:` → resume |
|
|
191
|
+
|
|
192
|
+
Impossible by construction: a completed or cancelled task reopened (every attempt and pass reads the task first and
|
|
193
|
+
leaves an ended run alone); a rejected or expired action executed (only `approved` executes, and approval is a
|
|
194
|
+
compare-and-set from `proposed`); a run completing with an action still open (completion refuses it).
|
|
195
|
+
|
|
196
|
+
### Reconciliation
|
|
197
|
+
|
|
198
|
+
Every services tick (at most every 15 s; also `runtime.reconcileAgentRuns()`), FeltKit lists open tasks of its
|
|
199
|
+
reasoning agents through FeltDB's indexed, paged listing and decides from durable state alone:
|
|
200
|
+
|
|
201
|
+
| Found | Done |
|
|
202
|
+
|---|---|
|
|
203
|
+
| a proposal past its approval window | expired (cancelled), exactly as a late approval would |
|
|
204
|
+
| released `waiting`, every action it waits on now decided | resume (`decided:`) |
|
|
205
|
+
| released `held`, the task running again | resume (`unheld:`) |
|
|
206
|
+
| a lease past `until`, never released, its attempt's outbox record not pending or performing | resume (`expired:`) |
|
|
207
|
+
| no lease, task older than 30 s | resume (`no-lease:`) |
|
|
208
|
+
| released `completed`/`stopped`, task still open | resume (`unfinished:`) |
|
|
209
|
+
| a live lease, `error` (the outbox owns the retry), a proposal still waiting, an unknown outcome, a paused task | nothing |
|
|
210
|
+
|
|
211
|
+
A resume is an outbox record whose id is derived from the task and the state it was decided from (the lease link and
|
|
212
|
+
the states of what it waited on), written with `requireAbsent`: the same state resumes once, however many passes
|
|
213
|
+
run, in however many processes. A pass never decides for a person, never executes anything, and never touches an
|
|
214
|
+
ended run; it records each repair on the task and in the activity log.
|
|
215
|
+
|
|
216
|
+
## Approvals in the application
|
|
217
|
+
|
|
218
|
+
Agent proposals are application actions, decided in the application's own interface. The API lists a proposal to a
|
|
219
|
+
person only when it is on a task owned by one of the app's declared agents, in the person's own workspace, and the
|
|
220
|
+
person may perform its capability themselves. A person without `feltkit.agent.read` is refused; agents and services
|
|
221
|
+
are refused.
|
|
222
|
+
|
|
223
|
+
| | HTTP | Client |
|
|
224
|
+
|---|---|---|
|
|
225
|
+
| list (default: waiting) | `GET /api/agent/approvals?state=proposed\|all` | `client.agentApprovals({ state })` |
|
|
226
|
+
| detail: capability, validated input, digest, attempt, the agent's explanation, the run's input, history | `GET /api/agent/approvals/:taskId/:actionId` | `client.agentApproval(taskId, actionId)` |
|
|
227
|
+
| approve / reject | `POST /api/agent/approvals/decide { taskId, actionId, attempt, inputDigest, decision, reason? }` | `client.decideAgentApproval(approval, "approve" \| "reject", reason?)` |
|
|
228
|
+
|
|
229
|
+
- The caller is the session's principal; nothing in the request names who decides.
|
|
230
|
+
- A decision binds to what was reviewed: the proposal's `attempt` (a retry is a new attempt) and, to approve, its
|
|
231
|
+
`inputDigest`. Anything else is refused (`FAILED_PRECONDITION`, `STALE_PROPOSAL`) and nothing changes.
|
|
232
|
+
- Deciding what is already decided answers its current state; concurrent approvals execute once.
|
|
233
|
+
- Approving runs the action (as the agent, through AppPort) before answering; the run then resumes.
|
|
234
|
+
- The run's transcript is not exposed: the detail carries the agent's own words for that call only.
|
|
235
|
+
|
|
236
|
+
`examples/approvals` is a small app built on it: an expense reviewer agent, an approvals list and detail, approve and
|
|
237
|
+
reject, and the expense's status afterwards.
|
|
238
|
+
|
|
239
|
+
## Output contracts
|
|
240
|
+
|
|
241
|
+
`output: s.object({ … })` (or a shape) makes the final answer a contract. The engine is told the JSON Schema; the
|
|
242
|
+
answer must be JSON (a fenced block is accepted) that validates. An answer that does not is never the output: the
|
|
243
|
+
agent receives the issues as a message (recorded with `validation: { ok: false, issues }`) and answers again, within
|
|
244
|
+
`maxTurns`. A valid answer is stored at `<task>.output` with the definition version it was validated against, and is
|
|
245
|
+
the run's `result.run.output`. When the turns are spent first, the run stops with no output.
|
|
246
|
+
|
|
247
|
+
## Budgets
|
|
248
|
+
|
|
249
|
+
| Limit | Counted from | Default |
|
|
250
|
+
|---|---|---|
|
|
251
|
+
| `maxTurns` | assistant messages in the transcript | 8 |
|
|
252
|
+
| `maxToolCalls` | tool results in the transcript | 20 |
|
|
253
|
+
| `maxGenerations` | the task's generation records, failed ones included | 2 × maxTurns |
|
|
254
|
+
| `maxActiveMs` | the lease chain: each epoch from acquisition to release or expiry (waiting for a person is not counted) | 10 min |
|
|
255
|
+
| `maxTokens` | input + output tokens the provider reported | none |
|
|
256
|
+
| `concurrency` | attempts of this agent executing in this process | 4 |
|
|
257
|
+
|
|
258
|
+
Budgets are checked before each turn, from durable records, so a restart does not reset them. Spending one stops the
|
|
259
|
+
run (task cancelled; the reason names the budget and the amount). Token usage is enforced only where the provider
|
|
260
|
+
reports it: a generation without usage is not counted, and the reason says how many were not. `concurrency` is per
|
|
261
|
+
process, not across processes; an attempt over it waits (`RUN_BUSY`) and is retried with backoff.
|
|
262
|
+
|
|
263
|
+
### Failures
|
|
264
|
+
|
|
265
|
+
| Failure | What happens |
|
|
266
|
+
|---|---|
|
|
267
|
+
| No model configured (model engine) | the attempt fails `CONFIGURATION`, saying what to set; not retried automatically (an operator retries the outbox record) |
|
|
268
|
+
| Provider error, timeout, dropped stream | the generation is recorded `failed`; the attempt is retried with backoff; earlier tool calls are not repeated |
|
|
269
|
+
| A tool fails, or its arguments break the capability's contract | its error is the tool result; nothing runs; the engine decides what next |
|
|
270
|
+
| A person stops the task while the engine decides | the turn is not recorded; nothing more runs |
|
|
271
|
+
| Process killed | its lease lapses (half of `leaseMs`, 60 s by default); outbox recovery or reconciliation resumes the run |
|
|
272
|
+
|
|
273
|
+
## Engines
|
|
274
|
+
|
|
275
|
+
An engine decides one thing: the agent's next turn (text and tool calls), from the instructions, the transcript, the
|
|
276
|
+
tools offered now and the output contract. It never reads or writes state, holds a credential, or runs a tool.
|
|
277
|
+
|
|
278
|
+
```ts
|
|
279
|
+
interface AgentEngine {
|
|
280
|
+
readonly id: string; // recorded on every run and turn
|
|
281
|
+
readonly usesModel: boolean; // a run fails clearly before starting when no model is ready
|
|
282
|
+
next(request: AgentTurnRequest): Promise<AgentTurn>;
|
|
283
|
+
}
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
| Engine | |
|
|
287
|
+
|---|---|
|
|
288
|
+
| `modelEngine()` (default) | one generation per turn with the environment's model; every generation is evidence on the task |
|
|
289
|
+
| `rulesEngine(id, decide)` | ordinary code, no model: the same lifecycle, authority, approvals and evidence |
|
|
290
|
+
| your own | anything that implements `next`; `request.model.generate` is the environment's model, recorded; honor `request.signal` |
|
|
291
|
+
|
|
292
|
+
## Inspecting runs
|
|
293
|
+
|
|
294
|
+
Runs are agent tasks: Studio's agent screen (the task, its transcript, checkpoints, actions with approve/reject/settle),
|
|
295
|
+
`GET /_feltkit/api/agent/tasks/:id`, `feltkit outbox list` (each attempt's `result.run`), the activity log
|
|
296
|
+
(`agent/<name>` attempts, `agent.run.recovered`), and the app's approvals API for people deciding.
|
|
297
|
+
|
|
298
|
+
## Testing an agent
|
|
299
|
+
|
|
300
|
+
Tests run against a fresh FeltDB instance like every FeltKit test. A `rulesEngine` agent needs no model. To test a
|
|
301
|
+
model-driven agent, point the environment's Intelligence selection at a scripted server that speaks the provider's
|
|
302
|
+
real protocol (see `test/fixtures/streaming-model.ts`), so the request, tool mapping, streaming and evidence are the
|
|
303
|
+
real ones and only the answers are scripted.
|
|
304
|
+
|
|
305
|
+
## What it costs (measured)
|
|
306
|
+
|
|
307
|
+
`node --import tsx --import ./test/isolate-env.ts bench/native-agents.ts` in `packages/sdk` (Node 22, Linux x64,
|
|
308
|
+
local FeltDB; cold starts are medians of 5–7 fresh processes; 30 warm runs each; sessions on 2026-11-24, ranges across
|
|
309
|
+
sessions):
|
|
310
|
+
|
|
311
|
+
| | Start | RSS |
|
|
312
|
+
|---|---|---|
|
|
313
|
+
| support app, no agents declared | 537–671 ms | 145–154 MB |
|
|
314
|
+
| the same app, 4 reasoning agents declared, idle | 605–690 ms | 145–155 MB |
|
|
315
|
+
|
|
316
|
+
Declaring agents adds nothing measurable at rest beyond run-to-run variation; an app without reasoning agents pays
|
|
317
|
+
about 10 µs per reconciliation pass (it returns at once) and nothing else.
|
|
318
|
+
|
|
319
|
+
| Per run (warm) | p50 | p95 | CPU | FeltDB records written |
|
|
320
|
+
|---|---|---|---|---|
|
|
321
|
+
| rules engine: 3 turns, 2 tool calls (one autonomous consequential) | 70–85 ms | 89–103 ms | 56–67 ms | 14 memories (2 of them the lease), 7 checkpoints, 1 task, 1 outbox |
|
|
322
|
+
| model engine, loopback model: 3 generations, 2 tool calls | 111–146 ms | 133–182 ms | 96–108 ms | 23 memories, 10 checkpoints, 1 task, 1 outbox |
|
|
323
|
+
| 20 rules-engine runs at once (concurrency 4 per agent) | 10–14 runs/s | | | |
|
|
324
|
+
|
|
325
|
+
| Reconciliation, 50 runs waiting for approval | |
|
|
326
|
+
|---|---|
|
|
327
|
+
| a pass that finds nothing to do | 10 ms (p50), 12 ms (max) |
|
|
328
|
+
| a pass that recovers all 50 (decisions whose resumes were lost) | 670–785 ms for the pass; every run completed after 1.9–2.0 s and 6–7 worker ticks (concurrency 4) |
|
|
329
|
+
| records written to recover 50 runs | 50 outbox records, 300 memories (recovery notes, leases, transcript), 50 checkpoints |
|
|
330
|
+
|
|
331
|
+
A real provider adds its own latency per generation (`gpt-4.1-mini` through AI Gateway: 0.8–1.4 s). The lease
|
|
332
|
+
added two memory records per attempt and no measurable latency over slice 1's 72 ms p50 within run-to-run variation.
|
|
333
|
+
|
|
334
|
+
## Choices and limits
|
|
335
|
+
|
|
336
|
+
- **Why not EVE inside FeltKit.** EVE's turn loop is reachable only through a compiled agent directory and a
|
|
337
|
+
Workflow "World" that holds the session's durable state; its in-process runtime and in-memory compiler are
|
|
338
|
+
test-only and excluded from its published build, and it requires Node 24. Embedding it would mean a second durable
|
|
339
|
+
store and either a fork or reliance on unexported internals. FeltKit owns the loop over FeltDB; the engine boundary
|
|
340
|
+
is where another reasoning implementation plugs in. EVE stays usable standalone and as a remote AppPort client.
|
|
341
|
+
- **Inference can repeat** (see Ownership and fencing); side effects and durable turns do not.
|
|
342
|
+
- **Lease checks are check-then-write.** A stale attempt can pass a check just before losing the lease; what it
|
|
343
|
+
writes then is a fixed-id message or a keyed proposal, so it either becomes the run's (it was first) or is adopted
|
|
344
|
+
away. It cannot overwrite.
|
|
345
|
+
- **Concurrency is per process.** `limits.concurrency` does not count attempts in other processes.
|
|
346
|
+
- **Approval after a restart.** An action approved but not yet executing when a process stopped goes back to
|
|
347
|
+
`proposed` at the next start (FeltKit asks the person again rather than act on a decision whose execution it did
|
|
348
|
+
not begin). The run waits for that new decision.
|
|
349
|
+
- **Retrying a failed action** (owner or person) makes a new proposal attempt after the run has already received the
|
|
350
|
+
failure; that attempt is decided and runs on its own, not as part of the run's flow.
|
|
351
|
+
- **Output to application code.** The validated output is in `result.run.output` and `<task>.output`; there is no
|
|
352
|
+
hook that hands it to a mutation yet. Persist results through a tool the agent calls.
|
|
353
|
+
- **Not in AppBoundry artifacts.** `app.agent` runs on FeltKit's runtime (as before).
|