@pattern-js/mod-agents 0.2.2 → 0.3.0-main.4a77893

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/README.md CHANGED
@@ -1,9 +1,12 @@
1
1
  # @pattern-js/mod-agents
2
2
 
3
- The **neutral** agents contracts layer for [Pattern](../../README.md) — plain-JSON
4
- agent/tool/guardrail descriptors and the modality-agnostic turn event protocol,
5
- with **no SDK dependency**. Provider mods reify the descriptors; apps consume the
6
- events. Neither has to know about the other.
3
+ [pattern-js.dev](https://pattern-js.dev) · [npm](https://www.npmjs.com/package/@pattern-js/mod-agents)
4
+
5
+ The **neutral** agents layer for [Pattern](../../README.md): plain-JSON
6
+ agent/tool/guardrail descriptors, the modality-agnostic turn event protocol, and
7
+ the native agent run loop, with **no provider SDK**. It calls a model through a
8
+ seam that `@pattern-js/mod-ai` implements; apps consume the events. Each layer is
9
+ decoupled.
7
10
 
8
11
  ```bash
9
12
  npm install @pattern-js/mod-agents
@@ -11,28 +14,29 @@ npm install @pattern-js/mod-agents
11
14
 
12
15
  ## When to use
13
16
 
14
- Install it whenever you want agents in your app — but never *alone*. It
15
- contributes the `boundary.tool` pair, the toolset/guardrail ops, and the live
16
- tool registry (`AGENTS_SERVICE`); it does **not** run an agent. Pair it with a
17
- provider (`@pattern-js/mod-agents-openai`) that reifies the descriptors and emits
18
- the turn events.
17
+ Install it whenever you want agents in your app, always alongside a model
18
+ provider. It contributes the `boundary.tool` pair, the toolset/guardrail ops, the
19
+ live tool registry (`AGENTS_SERVICE`), and **the native agent run loop**; the loop
20
+ needs a model to run. Pair it with `@pattern-js/mod-ai` (the model provider: it
21
+ implements the neutral model seam this loop calls and adds the `ai.model` node +
22
+ capability ops).
19
23
 
20
24
  **When not:** a single model call with no tools, no agent loop, and no streaming
21
- turn events — a provider op straight from the canvas is lighter than the agents
22
- stack.
25
+ turn events. An `ai.text.generate` op straight from the canvas is lighter than
26
+ the agents stack.
23
27
 
24
28
  ## Prerequisites
25
29
 
26
- Always ship it with a provider. Usually also `@pattern-js/mod-store` (history +
27
- blobs) and `@pattern-js/mod-vault` (the API key).
30
+ Always ship it with `@pattern-js/mod-ai` (the model provider). Usually also
31
+ `@pattern-js/mod-store` (history + blobs) and `@pattern-js/mod-vault` (provider keys).
28
32
 
29
33
  ## Config
30
34
 
31
- The contracts always ship paired with a provider — add both as strings in
32
- `pattern.config.json`:
35
+ The agents layer always ships paired with the model provider. Add both as strings
36
+ in `pattern.config.json`:
33
37
 
34
38
  ```jsonc
35
- { "mods": ["@pattern-js/mod-agents", "@pattern-js/mod-agents-openai"] }
39
+ { "mods": ["@pattern-js/mod-agents", "@pattern-js/mod-ai"] }
36
40
  ```
37
41
 
38
42
  For options, export a local wrapper mod that calls the `agentsMod({...})` factory.
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @pattern-js/mod-agents — the agent ops, re-hosted natively.
3
+ *
4
+ * `agents.agent` builds a DESCRIPTOR (plain JSON, no model work). `agents.run`
5
+ * drives the native loop over the neutral model service (mod-ai), streaming the
6
+ * turn-event protocol while `output`/`history` settle as values. History is
7
+ * explicit: pull it from a store node, push the updated one back. Pre-flight
8
+ * problems (no model provider) FAIL the node loudly; mid-turn problems (rate
9
+ * limits, guardrail trips) become turn events and a soft outcome.
10
+ */
11
+ import { type OpDefinition } from "@pattern-js/core";
12
+ export declare const agentRunOps: OpDefinition[];
13
+ //# sourceMappingURL=agent-ops.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-ops.d.ts","sourceRoot":"","sources":["../src/agent-ops.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAA8C,KAAK,YAAY,EAAE,MAAM,kBAAkB,CAAC;AA6SjG,eAAO,MAAM,WAAW,EAAE,YAAY,EAAiD,CAAC"}
@@ -0,0 +1,271 @@
1
+ /**
2
+ * @pattern-js/mod-agents — the agent ops, re-hosted natively.
3
+ *
4
+ * `agents.agent` builds a DESCRIPTOR (plain JSON, no model work). `agents.run`
5
+ * drives the native loop over the neutral model service (mod-ai), streaming the
6
+ * turn-event protocol while `output`/`history` settle as values. History is
7
+ * explicit: pull it from a store node, push the updated one back. Pre-flight
8
+ * problems (no model provider) FAIL the node loudly; mid-turn problems (rate
9
+ * limits, guardrail trips) become turn events and a soft outcome.
10
+ */
11
+ import { required, stream, value, z } from "@pattern-js/core";
12
+ import { agentsService } from "./well-known.js";
13
+ import { aiModelService } from "./model-service.js";
14
+ import { startTurn, decodeState } from "./loop.js";
15
+ import { agentSchema, historySchema, messagePartSchema, modelRefSchema, toolsetSchema, turnEventSchema, } from "./types.js";
16
+ async function maybe(ctx, port) {
17
+ return ctx.input.has(port) ? (await ctx.input.value(port)) : undefined;
18
+ }
19
+ const asArray = (v) => (v == null ? [] : Array.isArray(v) ? v : [v]);
20
+ /* ── agents.agent ──────────────────────────────────────────────────────── */
21
+ const agentOp = {
22
+ type: "agents.agent",
23
+ title: "agents.agent",
24
+ description: "Define an agent (a value you wire into agents.run, a handoff, or a tool). Wire a model from ai.model; " +
25
+ "name/instructions default to config but can be wired at runtime to vary them per request (a wired value " +
26
+ "overrides config); tools/guardrails/handoffs wire in as inputs. No model = the configured default.",
27
+ config: z.object({
28
+ name: z.string().min(1),
29
+ /** The system prompt: what this agent does and how it answers. */
30
+ instructions: z.string().min(1),
31
+ /** Shown to other agents deciding whether to hand off to this one. */
32
+ handoffDescription: z.string().optional(),
33
+ }),
34
+ inputs: {
35
+ // name + instructions are config by default but ALSO wireable at runtime —
36
+ // a wired value (even one derived from the request) overrides the config, so
37
+ // a pipeline can vary an agent's identity per turn (e.g. chat's voice mode
38
+ // swaps in spoken-style instructions). Unwired ⇒ the config value stands.
39
+ name: value(z.string()),
40
+ instructions: value(z.string()),
41
+ model: value(modelRefSchema),
42
+ tools: value(toolsetSchema),
43
+ guardrails: value(), // GuardrailDescriptor | GuardrailDescriptor[]
44
+ handoffs: value(), // AgentDescriptor | AgentDescriptor[]
45
+ },
46
+ outputs: { agent: value(agentSchema) },
47
+ execute: async (ctx) => {
48
+ const cfg = ctx.config;
49
+ const [nameIn, instructionsIn, model, tools, guardrailsIn, handoffsIn] = await Promise.all([
50
+ maybe(ctx, "name"),
51
+ maybe(ctx, "instructions"),
52
+ maybe(ctx, "model"),
53
+ maybe(ctx, "tools"),
54
+ maybe(ctx, "guardrails"),
55
+ maybe(ctx, "handoffs"),
56
+ ]);
57
+ const guardrails = asArray(guardrailsIn);
58
+ const handoffs = asArray(handoffsIn).map((h) => agentSchema.parse(h));
59
+ const agent = {
60
+ kind: "agent",
61
+ name: nameIn ?? cfg.name,
62
+ instructions: instructionsIn ?? cfg.instructions,
63
+ model: model ? modelRefSchema.parse(model) : undefined,
64
+ handoffDescription: cfg.handoffDescription,
65
+ tools,
66
+ guardrails: guardrails.length ? guardrails : undefined,
67
+ handoffs: handoffs.length ? handoffs : undefined,
68
+ };
69
+ return { agent };
70
+ },
71
+ };
72
+ /* ── run plumbing ──────────────────────────────────────────────────────── */
73
+ const runOutputs = {
74
+ events: stream(turnEventSchema),
75
+ output: value(),
76
+ history: value(historySchema),
77
+ stopReason: value(z.enum(["complete", "interrupted", "error", "cancelled"])),
78
+ stateToken: value(z.string().nullable()),
79
+ };
80
+ function softOutputs(outcome) {
81
+ return {
82
+ output: outcome.then((o) => o.output),
83
+ history: outcome.then((o) => o.history ?? []),
84
+ stopReason: outcome.then((o) => o.stopReason),
85
+ stateToken: outcome.then((o) => o.stateToken),
86
+ };
87
+ }
88
+ /**
89
+ * Turn-scoped abort: a STREAMING run settles for the engine before the turn
90
+ * finishes (the SSE tail flows after result-ready), so engine.cancelRun can't
91
+ * reach it — a Stop button aborts via AGENTS_SERVICE.abortTurn(turnId). The
92
+ * run-level ctx.signal still chains in (editor Stop, sub-runs).
93
+ */
94
+ function turnAbort(ctx, turnId) {
95
+ const ctrl = new AbortController();
96
+ const svc = agentsService(ctx);
97
+ svc.registerTurn(turnId, ctrl);
98
+ return { signal: AbortSignal.any([ctx.signal, ctrl.signal]), release: () => svc.releaseTurn(turnId) };
99
+ }
100
+ function looksLikeParts(v) {
101
+ return Array.isArray(v) && v.length > 0 && v.every((p) => messagePartSchema.safeParse(p).success);
102
+ }
103
+ /** Shape the user turn: string | parts → one user message; neutral items pass through. */
104
+ function userMessages(input) {
105
+ if (typeof input === "string")
106
+ return [{ role: "user", content: input }];
107
+ if (looksLikeParts(input))
108
+ return [{ role: "user", content: input }];
109
+ if (Array.isArray(input))
110
+ return input;
111
+ throw new Error("agents.run: input must be a string, a parts array, or neutral messages");
112
+ }
113
+ const DEFAULT_MAX_TURNS = 10;
114
+ /* ── agents.run ────────────────────────────────────────────────────────── */
115
+ const runOp = {
116
+ type: "agents.run",
117
+ title: "agents.run",
118
+ description: "Run an agent: input (text or parts) + optional history in → turn events stream + final output + updated history out. " +
119
+ "Tool calls are linked sub-runs; the events stream always terminates with `done`.",
120
+ config: z.object({ maxTurns: z.number().int().positive().optional() }),
121
+ inputs: {
122
+ agent: required(agentSchema),
123
+ input: required(),
124
+ history: value(historySchema),
125
+ turnId: value(z.string()),
126
+ },
127
+ outputs: runOutputs,
128
+ execute: async (ctx) => {
129
+ const [descRaw, input, history, turnId] = await Promise.all([
130
+ ctx.input.value("agent"),
131
+ ctx.input.value("input"),
132
+ maybe(ctx, "history"),
133
+ maybe(ctx, "turnId"),
134
+ ]);
135
+ const model = aiModelService(ctx); // pre-flight: loud if no provider
136
+ const descriptor = agentSchema.parse(descRaw);
137
+ const messages = [...(history ?? []), ...userMessages(input)];
138
+ const { maxTurns } = ctx.config;
139
+ const tid = turnId ?? ctx.runId;
140
+ const { signal, release } = turnAbort(ctx, tid);
141
+ const { events, outcome } = startTurn({
142
+ ctx,
143
+ model,
144
+ descriptor,
145
+ messages,
146
+ maxTurns: maxTurns ?? DEFAULT_MAX_TURNS,
147
+ ids: { turnId: tid, runId: ctx.runId },
148
+ signal,
149
+ });
150
+ void outcome.finally(release);
151
+ return { events, ...softOutputs(outcome) };
152
+ },
153
+ };
154
+ /* ── agents.run.resume (HITL) ──────────────────────────────────────────── */
155
+ const resumeOp = {
156
+ type: "agents.run.resume",
157
+ title: "agents.run.resume",
158
+ description: "Resume an interrupted run (HITL): the stateToken from approval.request + approve/reject decisions → the turn continues streaming.",
159
+ config: z.object({}),
160
+ inputs: {
161
+ agent: required(agentSchema),
162
+ stateToken: required(z.string()),
163
+ /** [{ id, approved }] (or one object) matching approval.request interruptions. */
164
+ decisions: required(),
165
+ turnId: value(z.string()),
166
+ },
167
+ outputs: runOutputs,
168
+ execute: async (ctx) => {
169
+ const [descRaw, stateToken, decisionsIn, turnId] = await Promise.all([
170
+ ctx.input.value("agent"),
171
+ ctx.input.value("stateToken"),
172
+ ctx.input.value("decisions"),
173
+ maybe(ctx, "turnId"),
174
+ ]);
175
+ const model = aiModelService(ctx);
176
+ const descriptor = agentSchema.parse(descRaw);
177
+ const saved = decodeState(stateToken);
178
+ const decisions = asArray(decisionsIn);
179
+ const tid = turnId ?? ctx.runId;
180
+ const { signal, release } = turnAbort(ctx, tid);
181
+ const { events, outcome } = startTurn({
182
+ ctx,
183
+ model,
184
+ descriptor,
185
+ messages: saved.messages,
186
+ maxTurns: DEFAULT_MAX_TURNS,
187
+ ids: { turnId: tid, runId: ctx.runId },
188
+ signal,
189
+ resume: { saved, decisions },
190
+ });
191
+ void outcome.finally(release);
192
+ return { events, ...softOutputs(outcome) };
193
+ },
194
+ };
195
+ /* ── agents.history.compact ────────────────────────────────────────────── */
196
+ const compactOp = {
197
+ type: "agents.history.compact",
198
+ title: "agents.history.compact",
199
+ description: "Squeeze a long history: items beyond keepRecent are summarized into one message (a visible node, so you SEE when memory compresses). Wire a model from ai.model or use the default.",
200
+ config: z.object({
201
+ /** Compact only when the history exceeds this many items. */
202
+ threshold: z.number().int().positive().default(60),
203
+ /** Most-recent items kept verbatim. */
204
+ keepRecent: z.number().int().positive().default(20),
205
+ }),
206
+ inputs: { history: required(historySchema), model: value(modelRefSchema) },
207
+ outputs: { history: value(historySchema), compacted: value(z.boolean()) },
208
+ execute: async (ctx) => {
209
+ const cfg = ctx.config;
210
+ const [history, modelRef] = await Promise.all([
211
+ ctx.input.value("history"),
212
+ maybe(ctx, "model"),
213
+ ]);
214
+ if (history.length <= cfg.threshold)
215
+ return { history, compacted: false };
216
+ const old = history.slice(0, history.length - cfg.keepRecent);
217
+ const recent = history.slice(history.length - cfg.keepRecent);
218
+ const model = aiModelService(ctx);
219
+ const { text } = await model.generateText({
220
+ ctx,
221
+ modelRef,
222
+ system: "Summarize the following conversation log into a compact brief that preserves facts, names, decisions and open tasks. Reply with the summary only.",
223
+ messages: [{ role: "user", content: JSON.stringify(old) }],
224
+ signal: ctx.signal,
225
+ });
226
+ const summaryItem = { role: "user", content: `[Summary of the earlier conversation]\n${text}` };
227
+ ctx.log("info", "history compacted", { from: history.length, to: recent.length + 1 });
228
+ return { history: [summaryItem, ...recent], compacted: true };
229
+ },
230
+ };
231
+ /* ── agents.mcp.client ─────────────────────────────────────────────────── */
232
+ const mcpOp = {
233
+ type: "agents.mcp.client",
234
+ title: "agents.mcp.client",
235
+ description: "Connect to an MCP server and expose its tools as a toolset value (connection pooled by mod-ai). http: url (+headers) · stdio: command (+args). " +
236
+ 'For stdio you can paste a WHOLE command line into `command` (e.g. "docker mcp gateway run --profile X"); it is ' +
237
+ "tokenized automatically; `args` are appended.",
238
+ config: z.object({
239
+ transport: z.enum(["http", "stdio"]).default("http"),
240
+ url: z.string().optional(),
241
+ command: z.string().optional(),
242
+ args: z.array(z.string()).optional(),
243
+ serverLabel: z.string().optional(),
244
+ }),
245
+ inputs: {
246
+ /** Auth headers for http transport — wire vault.read into a builder. */
247
+ headers: value(z.record(z.string(), z.string())),
248
+ },
249
+ outputs: { toolset: value(toolsetSchema) },
250
+ execute: async (ctx) => {
251
+ const cfg = ctx.config;
252
+ const headers = await maybe(ctx, "headers");
253
+ const toolset = {
254
+ kind: "toolset",
255
+ tools: [
256
+ {
257
+ origin: "mcp",
258
+ transport: cfg.transport,
259
+ url: cfg.url,
260
+ headers,
261
+ command: cfg.command,
262
+ args: cfg.args,
263
+ serverLabel: cfg.serverLabel,
264
+ },
265
+ ],
266
+ };
267
+ return { toolset };
268
+ },
269
+ };
270
+ export const agentRunOps = [agentOp, runOp, resumeOp, compactOp, mcpOp];
271
+ //# sourceMappingURL=agent-ops.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-ops.js","sourceRoot":"","sources":["../src/agent-ops.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAqC,MAAM,kBAAkB,CAAC;AACjG,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAmC,MAAM,WAAW,CAAC;AACpF,OAAO,EACL,WAAW,EACX,aAAa,EACb,iBAAiB,EACjB,cAAc,EACd,aAAa,EACb,eAAe,GAOhB,MAAM,YAAY,CAAC;AAEpB,KAAK,UAAU,KAAK,CAAI,GAAc,EAAE,IAAY;IAClD,OAAO,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAE,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAO,CAAC,CAAC,CAAC,SAAS,CAAC;AAChF,CAAC;AAED,MAAM,OAAO,GAAG,CAAI,CAAU,EAAO,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAE,CAAS,CAAC,CAAC,CAAC,CAAC,CAAM,CAAC,CAAC,CAAC;AAEpG,8EAA8E;AAE9E,MAAM,OAAO,GAAiB;IAC5B,IAAI,EAAE,cAAc;IACpB,KAAK,EAAE,c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E,CAAC,QAAQ,EAAE;QAC9B,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE;QACpC,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;KACnC,CAAC;IACF,MAAM,EAAE;QACN,wEAAwE;QACxE,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;KACjD;IACD,OAAO,EAAE,EAAE,OAAO,EAAE,KAAK,CAAC,aAAa,CAAC,EAAE;IAC1C,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;QACrB,MAAM,GAAG,GAAG,GAAG,CAAC,MAMf,CAAC;QACF,MAAM,OAAO,GAAG,MAAM,KAAK,CAAyB,GAAG,EAAE,SAAS,CAAC,CAAC;QACpE,MAAM,OAAO,GAAsB;YACjC,IAAI,EAAE,SAAS;YACf,KAAK,EAAE;gBACL;oBACE,MAAM,EAAE,KAAK;oBACb,SAAS,EAAE,GAAG,CAAC,SAAS;oBACxB,GAAG,EAAE,GAAG,CAAC,GAAG;oBACZ,OAAO;oBACP,OAAO,EAAE,GAAG,CAAC,OAAO;oBACpB,IAAI,EAAE,GAAG,CAAC,IAAI;oBACd,WAAW,EAAE,GAAG,CAAC,WAAW;iBAC7B;aACF;SACF,CAAC;QACF,OAAO,EAAE,OAAO,EAAE,CAAC;IACrB,CAAC;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAmB,CAAC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC"}
package/dist/index.d.ts CHANGED
@@ -5,5 +5,8 @@ export { AGENTS_SERVICE, agentsService, workflowToolRef, type AgentsService, typ
5
5
  export { AgentsRegistry } from "./service.js";
6
6
  export { agentBoundaryOps, toolTrigger, toolReturn } from "./boundaries.js";
7
7
  export { agentsOps } from "./ops.js";
8
- export { agentSchema, guardrailSchema, historySchema, messagePartSchema, toolRefSchema, toolsetSchema, turnEventSchema, type AgentDescriptor, type GuardrailDescriptor, type History, type MessagePart, type ToolRef, type ToolsetDescriptor, type TurnEvent, type TurnStopReason, } from "./types.js";
8
+ export { agentRunOps } from "./agent-ops.js";
9
+ export { agentSchema, guardrailSchema, historySchema, messagePartSchema, modelRefSchema, neutralMessageSchema, toolRefSchema, toolsetSchema, turnEventSchema, usageSchema, type AgentDescriptor, type GuardrailDescriptor, type History, type MessagePart, type ModelRef, type NeutralMessage, type ToolRef, type ToolsetDescriptor, type TurnEvent, type TurnStopReason, type Usage, } from "./types.js";
10
+ export { AI_MCP_SERVICE, AI_MODEL_SERVICE, aiMcpService, aiModelService, type AiMcpService, type AiModelService, type GenerateTextInput, type McpToolRef, type NeutralChunk, type NeutralToolDef, type StreamTurnInput, } from "./model-service.js";
11
+ export { startTurn, decodeState, type Decision, type TurnOutcome } from "./loop.js";
9
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAE7E,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAEnC,OAAO,EACL,cAAc,EACd,aAAa,EACb,eAAe,EACf,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,KAAK,wBAAwB,GAC9B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC5E,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EACL,WAAW,EACX,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,e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,EACnB,KAAK,eAAe,GACrB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,KAAK,QAAQ,EAAE,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC"}
package/dist/index.js CHANGED
@@ -5,5 +5,8 @@ export { AGENTS_SERVICE, agentsService, workflowToolRef, } from "./well-known.js
5
5
  export { AgentsRegistry } from "./service.js";
6
6
  export { agentBoundaryOps, toolTrigger, toolReturn } from "./boundaries.js";
7
7
  export { agentsOps } from "./ops.js";
8
- export { agentSchema, guardrailSchema, historySchema, messagePartSchema, toolRefSchema, toolsetSchema, turnEventSchema, } from "./types.js";
8
+ export { agentRunOps } from "./agent-ops.js";
9
+ export { agentSchema, guardrailSchema, historySchema, messagePartSchema, modelRefSchema, neutralMessageSchema, toolRefSchema, toolsetSchema, turnEventSchema, usageSchema, } from "./types.js";
10
+ export { AI_MCP_SERVICE, AI_MODEL_SERVICE, aiMcpService, aiModelService, } from "./model-service.js";
11
+ export { startTurn, decodeState } from "./loop.js";
9
12
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAE7E,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAEnC,OAAO,EACL,cAAc,EACd,aAAa,EACb,eAAe,GAIhB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC5E,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EACL,WAAW,EACX,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,eAAe,GAShB,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAE7E,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAEnC,OAAO,EACL,cAAc,EACd,aAAa,EACb,eAAe,GAIhB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC5E,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EACL,WAAW,EACX,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,cAAc,EACd,oBAAoB,EACpB,aAAa,EACb,aAAa,EACb,eAAe,EACf,WAAW,GAYZ,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,YAAY,EACZ,cAAc,GAQf,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAE,WAAW,EAAmC,MAAM,WAAW,CAAC"}
package/dist/loop.d.ts ADDED
@@ -0,0 +1,72 @@
1
+ /**
2
+ * @pattern-js/mod-agents — the native agent run loop.
3
+ *
4
+ * Replaces the @openai/agents Runner: we drive the model↔tool turn loop
5
+ * ourselves over the neutral AiModelService (mod-ai implements it). Each model
6
+ * step is a single `streamTurn` call; THIS loop owns multi-step. Tools are
7
+ * linked sub-runs (`ctx.invoke`) / op-registry calls / MCP; handoffs swap the
8
+ * active agent; guardrails are tool sub-runs; HITL pauses with a stateToken.
9
+ *
10
+ * It emits the neutral `turnEventSchema` and the produced stream ALWAYS
11
+ * terminates with a `done` event — complete | interrupted | error | cancelled.
12
+ */
13
+ import type { OpContext } from "@pattern-js/core";
14
+ import { type AiModelService } from "./model-service.js";
15
+ import type { AgentDescriptor, NeutralMessage, TurnEvent, TurnStopReason } from "./types.js";
16
+ interface Ids {
17
+ turnId: string;
18
+ runId: string;
19
+ }
20
+ export interface TurnOutcome {
21
+ stopReason: TurnStopReason;
22
+ /** Final text/structured output; null on error/interruption/cancel. */
23
+ output: unknown;
24
+ /** Full neutral history after the run; null on hard failure/cancel. */
25
+ history: NeutralMessage[] | null;
26
+ /** Serialized loop state when interrupted (HITL resume token). */
27
+ stateToken: string | null;
28
+ }
29
+ export interface Decision {
30
+ id: string;
31
+ approved: boolean;
32
+ }
33
+ /** A pending tool call buffered for human approval. */
34
+ interface Pending {
35
+ callId: string;
36
+ toolName: string;
37
+ args: Record<string, unknown>;
38
+ }
39
+ /** The serialized HITL state (opaque to consumers; this loop owns the shape). */
40
+ interface SavedState {
41
+ messages: NeutralMessage[];
42
+ activeAgent: string;
43
+ pending: Pending[];
44
+ }
45
+ declare const decodeState: (t: string) => SavedState;
46
+ export interface StartTurnParams {
47
+ ctx: OpContext;
48
+ model: AiModelService;
49
+ descriptor: AgentDescriptor;
50
+ /** Conversation so far (history + the new user turn). */
51
+ messages: NeutralMessage[];
52
+ maxTurns: number;
53
+ ids: Ids;
54
+ signal: AbortSignal;
55
+ /** Resume path: decisions to apply against the saved pending approvals. */
56
+ resume?: {
57
+ saved: SavedState;
58
+ decisions: Decision[];
59
+ };
60
+ }
61
+ /**
62
+ * Run an agent turn (fresh or resumed). Returns the neutral event stream plus a
63
+ * settled outcome. Mirrors the old `pumpTurn` contract: the stream never
64
+ * rejects and always closes with `done`.
65
+ */
66
+ export declare function startTurn(params: StartTurnParams): {
67
+ events: ReadableStream<TurnEvent>;
68
+ outcome: Promise<TurnOutcome>;
69
+ };
70
+ /** Re-expose the saved state shape for the resume op. */
71
+ export { decodeState };
72
+ //# sourceMappingURL=loop.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loop.d.ts","sourceRoot":"","sources":["../src/loop.ts"],"names":[],"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