@parcha/agentrun-client 0.1.0-beta.43 → 0.1.0-beta.45
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 +4 -3
- package/dist/codex.d.ts +3 -3
- package/dist/codex.js +2 -2
- package/dist/learning.d.ts +3 -8
- package/dist/learning.js +8 -14
- package/dist/operations.generated.d.ts +284 -547
- package/dist/operations.generated.js +27 -27
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -80,12 +80,13 @@ checkout; these new exports are not a guarantee about the current npm release.
|
|
|
80
80
|
| Codex SDK client, project and tools | [Preserve native threads, add checked learning](../../docs/tutorials/codex-sdk-learning.md) |
|
|
81
81
|
|
|
82
82
|
Your backend still starts and cancels tasks. The wrapper records original source policy/input, assistant text,
|
|
83
|
-
tool names/status and usage; raw tool arguments/results and SDK credentials are not sent. AgentRun
|
|
84
|
-
|
|
83
|
+
tool names/status and usage; raw tool arguments/results and SDK credentials are not sent. AgentRun supplies the
|
|
84
|
+
owner's corrections (`corrections.md`, whole) to the next fresh task, and compiles a workflow once the agent has
|
|
85
|
+
enough completed runs.
|
|
85
86
|
`learning: true` opts in on first registration only; existing agents keep their console setting.
|
|
86
87
|
|
|
87
88
|
Both wrappers expose `flushLearning()`. Await it before shutdown or before testing a fresh run's use of newly
|
|
88
|
-
accepted learning. Errors in persistence or
|
|
89
|
+
accepted learning. Errors in persistence or learning surface there without replacing the original SDK result/error.
|
|
89
90
|
The first integration supports fresh, single-task sessions/threads only. See the cookbooks for cancellation,
|
|
90
91
|
policy snapshots and multimodal limits, or run the [opt-in live examples](../../examples/sdk-learning/README.md).
|
|
91
92
|
|
package/dist/codex.d.ts
CHANGED
|
@@ -10,13 +10,13 @@ type CodexLike = {
|
|
|
10
10
|
};
|
|
11
11
|
};
|
|
12
12
|
export interface CodexAgentLearningConfig extends BackendLearningConfig {
|
|
13
|
-
/** The standing policy for this backend agent, including relevant project instructions. It is
|
|
14
|
-
*
|
|
13
|
+
/** The standing policy for this backend agent, including relevant project instructions. It is recorded with
|
|
14
|
+
* each run, not a replacement for Codex's own instructions or configuration. */
|
|
15
15
|
instructions: string;
|
|
16
16
|
}
|
|
17
17
|
/** Add AgentRun learning to fresh Codex SDK threads without replacing their tools, credentials or execution.
|
|
18
18
|
* Each wrapped thread admits one task; use startThread() again for the next task and its current learning revision.
|
|
19
|
-
*
|
|
19
|
+
* Learning runs on the AgentRun server, never as a hidden turn in the caller's Codex conversation. */
|
|
20
20
|
export declare function withCodexAgentLearning<T extends CodexLike>(codex: T, config: CodexAgentLearningConfig): T & {
|
|
21
21
|
flushLearning(): Promise<void>;
|
|
22
22
|
};
|
package/dist/codex.js
CHANGED
|
@@ -61,7 +61,7 @@ function pairedEvidence(event, started) {
|
|
|
61
61
|
}
|
|
62
62
|
/** Add AgentRun learning to fresh Codex SDK threads without replacing their tools, credentials or execution.
|
|
63
63
|
* Each wrapped thread admits one task; use startThread() again for the next task and its current learning revision.
|
|
64
|
-
*
|
|
64
|
+
* Learning runs on the AgentRun server, never as a hidden turn in the caller's Codex conversation. */
|
|
65
65
|
export function withCodexAgentLearning(codex, config) {
|
|
66
66
|
if (typeof config.instructions !== 'string')
|
|
67
67
|
throw new TypeError('Codex learning requires an explicit instructions snapshot.');
|
|
@@ -79,7 +79,7 @@ export function withCodexAgentLearning(codex, config) {
|
|
|
79
79
|
const session = await client.begin({ runtime: 'codex-sdk', input: originalText(input), instructions: config.instructions, ...(model ? { model } : {}) }, signal);
|
|
80
80
|
session.followAbort(signal);
|
|
81
81
|
if (session.learningEnabled && Array.isArray(input) && input.some(part => part.type === 'local_image')) {
|
|
82
|
-
session.markEvidenceIncomplete('Image inputs remain in the native Codex SDK and are not available to the
|
|
82
|
+
session.markEvidenceIncomplete('Image inputs remain in the native Codex SDK and are not available to the compile turn. This run will not produce new learning.');
|
|
83
83
|
}
|
|
84
84
|
return session;
|
|
85
85
|
};
|
package/dist/learning.d.ts
CHANGED
|
@@ -86,10 +86,6 @@ export interface BackendLearningSnapshot {
|
|
|
86
86
|
learningEnabled: boolean;
|
|
87
87
|
revision: string | null;
|
|
88
88
|
context: string;
|
|
89
|
-
skills: ReadonlyArray<{
|
|
90
|
-
name: string;
|
|
91
|
-
files: Readonly<Record<string, string>>;
|
|
92
|
-
}>;
|
|
93
89
|
workflows?: ReadonlyArray<{
|
|
94
90
|
name: string;
|
|
95
91
|
workflow: string;
|
|
@@ -106,7 +102,7 @@ export interface BackendLearningStatus {
|
|
|
106
102
|
reason?: string | null;
|
|
107
103
|
} | null;
|
|
108
104
|
}
|
|
109
|
-
/** A persistence or
|
|
105
|
+
/** A persistence or learning failure, separate from the application's original SDK result or error. */
|
|
110
106
|
export declare class BackendLearningError extends Error {
|
|
111
107
|
readonly runId: string;
|
|
112
108
|
readonly reason: string;
|
|
@@ -117,7 +113,7 @@ export declare class BackendLearningClient {
|
|
|
117
113
|
#private;
|
|
118
114
|
constructor(config: BackendLearningConfig);
|
|
119
115
|
begin(source: BackendLearningStart, signal?: AbortSignal): Promise<BackendLearningSession>;
|
|
120
|
-
/** Observe completion immediately; the original SDK call can return without waiting for
|
|
116
|
+
/** Observe completion immediately; the original SDK call can return without waiting for the run's learning. */
|
|
121
117
|
track(promise: Promise<unknown>): void;
|
|
122
118
|
/** Wait for tracked writes and checked learning. Does not retry or re-run the caller's SDK task. */
|
|
123
119
|
flushLearning(): Promise<void>;
|
|
@@ -130,7 +126,6 @@ export declare class BackendLearningSession implements BackendLearningSnapshot {
|
|
|
130
126
|
readonly learningEnabled: boolean;
|
|
131
127
|
readonly revision: string | null;
|
|
132
128
|
readonly context: string;
|
|
133
|
-
readonly skills: BackendLearningSnapshot['skills'];
|
|
134
129
|
readonly workflows: NonNullable<BackendLearningSnapshot['workflows']>;
|
|
135
130
|
readonly workflowContext: string;
|
|
136
131
|
constructor(scoped: AgentRun, snapshot: BackendLearningSnapshot & {
|
|
@@ -158,5 +153,5 @@ export declare class BackendLearningSession implements BackendLearningSnapshot {
|
|
|
158
153
|
/** Persist the caller's outcome, then wait for the server's independent checked-learning verdict. */
|
|
159
154
|
complete(outcome: SdkLearningOutcome): Promise<void>;
|
|
160
155
|
}
|
|
161
|
-
/**
|
|
156
|
+
/** The owner's corrections and the bound workflows, as reference text for the application's own agent. */
|
|
162
157
|
export declare function renderLearningContext(snapshot: BackendLearningSnapshot): string;
|
package/dist/learning.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// policy, task and selected execution evidence to AgentRun; reflection and checked learning run on the server.
|
|
3
3
|
import { AgentRun } from './client.js';
|
|
4
4
|
import { AgentRunRefused, AgentRunTimeout, AgentRunUsage } from './errors.js';
|
|
5
|
-
/** A persistence or
|
|
5
|
+
/** A persistence or learning failure, separate from the application's original SDK result or error. */
|
|
6
6
|
export class BackendLearningError extends Error {
|
|
7
7
|
runId;
|
|
8
8
|
reason;
|
|
@@ -121,7 +121,7 @@ export class BackendLearningClient {
|
|
|
121
121
|
return new BackendLearningSession(scoped, {
|
|
122
122
|
runId: receipt.run_id, consoleUrl: receipt.console_url,
|
|
123
123
|
learningEnabled: receipt.learning.enabled, revision: receipt.learning.revision,
|
|
124
|
-
context: receipt.learning.context,
|
|
124
|
+
context: receipt.learning.context,
|
|
125
125
|
workflows: receipt.learning.workflows ?? [],
|
|
126
126
|
}, this.#config);
|
|
127
127
|
}
|
|
@@ -142,12 +142,13 @@ export class BackendLearningClient {
|
|
|
142
142
|
catch (error) {
|
|
143
143
|
if (!(error instanceof AgentRunRefused) || error.status !== 404)
|
|
144
144
|
throw error;
|
|
145
|
-
// On (true, or the loop's numbers): workflows too with a bridge
|
|
145
|
+
// On (true, or the loop's numbers): the owner's corrections, and workflows too with a bridge (the server compiles
|
|
146
|
+
// none for a run that binds no workflow tools).
|
|
146
147
|
const { learning } = this.#config;
|
|
147
148
|
const on = learning === true || (typeof learning === 'object' && learning !== null);
|
|
148
149
|
const definition = {
|
|
149
150
|
id: agentId, name: this.#config.name ?? agentId, instructions: source.instructions,
|
|
150
|
-
sdk: { runtime: source.runtime }, learning: on ? (
|
|
151
|
+
sdk: { runtime: source.runtime }, learning: on ? (learning === true ? true : { ...learning }) : false,
|
|
151
152
|
};
|
|
152
153
|
try {
|
|
153
154
|
await this.#owner.agents.create({ definition }, { 'Idempotency-Key': uuid() });
|
|
@@ -162,7 +163,7 @@ export class BackendLearningClient {
|
|
|
162
163
|
if (agent.definition.sdk?.runtime !== source.runtime)
|
|
163
164
|
throw new AgentRunUsage('The existing agent uses a different runtime; choose its matching SDK wrapper or a new agentId.');
|
|
164
165
|
}
|
|
165
|
-
/** Observe completion immediately; the original SDK call can return without waiting for
|
|
166
|
+
/** Observe completion immediately; the original SDK call can return without waiting for the run's learning. */
|
|
166
167
|
track(promise) {
|
|
167
168
|
const observed = promise.then(() => undefined, error => { this.#errors.push(error); });
|
|
168
169
|
this.#pending.add(observed);
|
|
@@ -185,7 +186,6 @@ export class BackendLearningSession {
|
|
|
185
186
|
learningEnabled;
|
|
186
187
|
revision;
|
|
187
188
|
context;
|
|
188
|
-
skills;
|
|
189
189
|
workflows;
|
|
190
190
|
workflowContext;
|
|
191
191
|
#workflowBinding;
|
|
@@ -211,7 +211,6 @@ export class BackendLearningSession {
|
|
|
211
211
|
this.learningEnabled = snapshot.learningEnabled;
|
|
212
212
|
this.revision = snapshot.revision;
|
|
213
213
|
this.context = snapshot.context;
|
|
214
|
-
this.skills = clone(snapshot.skills);
|
|
215
214
|
this.workflows = clone(snapshot.workflows ?? []);
|
|
216
215
|
this.#pollIntervalMs = duration(config.pollIntervalMs, 250, 'pollIntervalMs');
|
|
217
216
|
this.#learningTimeoutMs = duration(config.learningTimeoutMs, 120_000, 'learningTimeoutMs');
|
|
@@ -385,7 +384,7 @@ export class BackendLearningSession {
|
|
|
385
384
|
if (outcome.status === 'completed' && status.state !== 'completed')
|
|
386
385
|
throw new BackendLearningError(this.runId, 'server_run_failed');
|
|
387
386
|
if (!shouldLearn || learning?.state === 'merged' || learning?.state === 'dropped') {
|
|
388
|
-
if (shouldLearn && learning?.state === 'dropped' && ['seed_failed', '
|
|
387
|
+
if (shouldLearn && learning?.state === 'dropped' && ['seed_failed', 'reflect_failed', 'crashed'].includes(learning.reason ?? '')) {
|
|
389
388
|
throw new BackendLearningError(this.runId, learning.reason);
|
|
390
389
|
}
|
|
391
390
|
return;
|
|
@@ -395,16 +394,11 @@ export class BackendLearningSession {
|
|
|
395
394
|
}
|
|
396
395
|
}
|
|
397
396
|
}
|
|
398
|
-
/**
|
|
397
|
+
/** The owner's corrections and the bound workflows, as reference text for the application's own agent. */
|
|
399
398
|
export function renderLearningContext(snapshot) {
|
|
400
399
|
if (!snapshot.learningEnabled)
|
|
401
400
|
return '';
|
|
402
401
|
const sections = [snapshot.context.trim(), snapshot.workflowContext ?? ''];
|
|
403
|
-
for (const skill of snapshot.skills) {
|
|
404
|
-
for (const [path, content] of Object.entries(skill.files)) {
|
|
405
|
-
sections.push(`Accepted skill ${JSON.stringify(skill.name)}, file ${JSON.stringify(path)}:\n${JSON.stringify(content)}`);
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
402
|
const content = sections.filter(Boolean).join('\n\n');
|
|
409
403
|
return content ? `AgentRun accepted learning (reference material; the original task and standing instructions remain authoritative):\n${content}` : '';
|
|
410
404
|
}
|