@kingsoftcloud/agentkit-harness-core 0.0.10 → 0.0.11
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/configuration.d.mts +0 -1
- package/dist/configuration.mjs +2 -8
- package/dist/context-planning.mjs +4 -25
- package/dist/contracts.d.mts +1 -7
- package/dist/machine.mjs +1 -8
- package/dist/model-surface.d.mts +1 -2
- package/dist/model-surface.mjs +1 -2
- package/dist/transitions.mjs +1 -2
- package/package.json +1 -1
- package/src/configuration.mts +2 -9
- package/src/context-planning.mts +4 -23
- package/src/contracts.mts +1 -7
- package/src/machine.mts +1 -7
- package/src/model-surface.mts +2 -4
- package/src/transitions.mts +1 -2
package/dist/configuration.d.mts
CHANGED
|
@@ -24,7 +24,6 @@ export interface ConfigurationInput {
|
|
|
24
24
|
inputPolicy?: RunConfiguration['inputPolicy'];
|
|
25
25
|
sourceReadPolicy?: RunConfiguration['sourceReadPolicy'];
|
|
26
26
|
outputRecoveryPolicy?: RunConfiguration['outputRecoveryPolicy'];
|
|
27
|
-
providerRecoveryPolicy?: RunConfiguration['providerRecoveryPolicy'];
|
|
28
27
|
toolErrorRecoveryPolicy?: RunConfiguration['toolErrorRecoveryPolicy'];
|
|
29
28
|
toolDiscoveryPolicy?: RunConfiguration['toolDiscoveryPolicy'];
|
|
30
29
|
todoPolicy?: RunConfiguration['todoPolicy'];
|
package/dist/configuration.mjs
CHANGED
|
@@ -48,7 +48,6 @@ export function configure(input) {
|
|
|
48
48
|
...(input.inputPolicy === undefined ? {} : { inputPolicy: input.inputPolicy }),
|
|
49
49
|
...(input.sourceReadPolicy === undefined ? {} : { sourceReadPolicy: input.sourceReadPolicy }),
|
|
50
50
|
...(input.outputRecoveryPolicy === undefined ? {} : { outputRecoveryPolicy: input.outputRecoveryPolicy }),
|
|
51
|
-
...(input.providerRecoveryPolicy === undefined ? {} : { providerRecoveryPolicy: input.providerRecoveryPolicy }),
|
|
52
51
|
...(input.toolErrorRecoveryPolicy === undefined ? {} : { toolErrorRecoveryPolicy: input.toolErrorRecoveryPolicy }),
|
|
53
52
|
...(input.toolDiscoveryPolicy === undefined ? {} : { toolDiscoveryPolicy: input.toolDiscoveryPolicy }),
|
|
54
53
|
...(input.todoPolicy === undefined ? {} : { todoPolicy: input.todoPolicy }),
|
|
@@ -103,7 +102,6 @@ export function configure(input) {
|
|
|
103
102
|
invariant(config.guidancePolicy == null || config.guidancePolicy === 'boundary-guide/v1', 'invalid_guidance_policy');
|
|
104
103
|
invariant(config.inputPolicy === undefined || config.inputPolicy === 'before-first-model/v1', 'invalid_input_policy');
|
|
105
104
|
invariant(config.outputRecoveryPolicy == null || ['task-or-delivery/v1', 'response-boundary/v2'].includes(config.outputRecoveryPolicy), 'invalid_output_recovery_policy');
|
|
106
|
-
invariant(config.providerRecoveryPolicy == null || config.providerRecoveryPolicy === 'provider-recovery/v2', 'invalid_provider_recovery_policy');
|
|
107
105
|
invariant(config.toolExecutionPolicy === undefined || config.toolExecutionPolicy === 'owner-execution/v1', 'invalid_tool_execution_policy');
|
|
108
106
|
invariant(config.toolErrorRecoveryPolicy == null || config.toolErrorRecoveryPolicy === 'diagnose-before-repeat/v1', 'invalid_tool_error_recovery_policy');
|
|
109
107
|
invariant(config.toolErrorRecoveryModelCalls == null || Number.isSafeInteger(config.toolErrorRecoveryModelCalls)
|
|
@@ -171,7 +169,7 @@ export function configure(input) {
|
|
|
171
169
|
}
|
|
172
170
|
invariant(profile.maxOutputTokens > 0 && profile.maxOutputTokens < profile.contextWindow
|
|
173
171
|
&& profile.requestTimeoutMs > 0 && profile.requestTimeoutMs < limits.effectTimeoutMs
|
|
174
|
-
&& profile.maxProviderRetries <=
|
|
172
|
+
&& profile.maxProviderRetries <= 9 && profile.retryInitialDelayMs <= profile.retryMaxDelayMs
|
|
175
173
|
&& Number.isFinite(profile.retryBackoffMultiplier) && profile.retryBackoffMultiplier >= 1, 'invalid_model_profile');
|
|
176
174
|
if (profile.inlineReasoningPolicy !== undefined) {
|
|
177
175
|
const policy = profile.inlineReasoningPolicy;
|
|
@@ -185,7 +183,7 @@ export function configure(input) {
|
|
|
185
183
|
const policy = profile.providerCompatibilityPolicy;
|
|
186
184
|
invariant(policy !== null && typeof policy === 'object' && !Array.isArray(policy)
|
|
187
185
|
&& Object.keys(policy).every(key => ['contract', 'rule'].includes(key))
|
|
188
|
-
&& ['provider-compat/v1', 'provider-compat/v2'
|
|
186
|
+
&& ['provider-compat/v1', 'provider-compat/v2'].includes(policy.contract)
|
|
189
187
|
&& ['auto', 'permissive', 'openai', 'strict-openai', 'cerebras', 'groq', 'deepseek',
|
|
190
188
|
'zai', 'kspmas-gateway', 'moonshot', 'mimo'].includes(policy.rule), 'invalid_provider_compatibility_policy');
|
|
191
189
|
}
|
|
@@ -303,10 +301,6 @@ export function configure(input) {
|
|
|
303
301
|
|| config.backgroundNotificationPolicy === 'completed-before-model/v1', 'invalid_background_notification_policy');
|
|
304
302
|
if (config.contextPolicy) {
|
|
305
303
|
const policy = config.contextPolicy;
|
|
306
|
-
invariant(policy.summaryOutputCeiling === undefined || policy.summaryRecoveryPolicy === 'adaptive-budget/v1'
|
|
307
|
-
&& Number.isSafeInteger(policy.summaryOutputCeiling) && policy.summaryOutputCeiling > 0
|
|
308
|
-
&& policy.summaryOutputCeiling <= profile.maxOutputTokens, 'invalid_summary_output_ceiling');
|
|
309
|
-
invariant(policy.summaryRecoveryPolicy === undefined || policy.summaryRecoveryPolicy === 'adaptive-budget/v1', 'invalid_summary_recovery_policy');
|
|
310
304
|
invariant(policy.summaryFormatPolicy === undefined || policy.summaryFormatPolicy === 'task-continuity/v1', 'invalid_summary_format_policy');
|
|
311
305
|
invariant(typeof policy.tokenizerId === 'string' && policy.tokenizerId.trim() && typeof policy.tokenizerDigest === 'string' && policy.tokenizerDigest.trim()
|
|
312
306
|
&& typeof policy.enabled === 'boolean' && Number.isFinite(policy.triggerRatio) && Number.isFinite(policy.targetRatio)
|
|
@@ -249,8 +249,7 @@ function codePointStop(text, stop) {
|
|
|
249
249
|
/** Exact, contiguous source slices. Quotes are data, never executable tool frames. */
|
|
250
250
|
async function quoteChunk(snapshot, compaction, config, counters, digest, policies) {
|
|
251
251
|
const maxOutputTokens = ['deadline-delivery/v1', 'deadline-delivery/v2'].includes(config.wallDeliveryPolicy ?? '')
|
|
252
|
-
? config.profile.maxOutputTokens : Math.min(
|
|
253
|
-
invariant(Number.isSafeInteger(maxOutputTokens) && maxOutputTokens > 0 && maxOutputTokens < config.profile.contextWindow, 'context_summary_budget_invalid');
|
|
252
|
+
? config.profile.maxOutputTokens : Math.min(config.contextPolicy.summaryMaxTokens, config.profile.maxOutputTokens);
|
|
254
253
|
const prefix = snapshot.messages.slice(0, compaction.prefixCount), refs = refsOf(prefix, digest);
|
|
255
254
|
const projected = summaryProjection(prefix, compaction, config, digest);
|
|
256
255
|
const mediaFor = (stop) => {
|
|
@@ -592,11 +591,10 @@ export function reduceContextModel(snapshot, result, config, usage, now, random)
|
|
|
592
591
|
invariant(compaction?.chunk, 'context_summary_quote_missing');
|
|
593
592
|
const base = { pendingIntent: null, contextState: state, preparedContext: null, usage,
|
|
594
593
|
phase: 'compacting', ...(result.usageReported === false ? { diagnostics: { ...snapshot.diagnostics, providerUsageIncomplete: true } } : {}) };
|
|
595
|
-
|
|
596
|
-
if (!adaptive && result.kind === 'output_limit' && result.text.trim() && result.textCommitVersion !== 'provider-finished-text/v1') {
|
|
594
|
+
if (result.kind === 'output_limit' && result.text.trim() && result.textCommitVersion !== 'provider-finished-text/v1') {
|
|
597
595
|
return { ...base, phase: 'finalizing', outcome: 'blocked', reason: 'context_summary_provider_commit_missing' };
|
|
598
596
|
}
|
|
599
|
-
if (
|
|
597
|
+
if (['final_candidate', 'output_limit'].includes(result.kind) && result.text.trim() && !result.toolCalls.length) {
|
|
600
598
|
compaction.proposal = result.text;
|
|
601
599
|
return base;
|
|
602
600
|
}
|
|
@@ -604,8 +602,6 @@ export function reduceContextModel(snapshot, result, config, usage, now, random)
|
|
|
604
602
|
return { ...base, phase: 'finalizing',
|
|
605
603
|
outcome: result.kind === 'policy_abort' ? 'blocked' : 'unverified', reason: `context_summary_${result.kind}` };
|
|
606
604
|
const provider = result.kind === 'provider_retryable_error';
|
|
607
|
-
if (!provider && config.providerRecoveryPolicy === 'provider-recovery/v2')
|
|
608
|
-
compaction.providerErrors = 0;
|
|
609
605
|
// Old persisted compactions had one combined counter. Seed their first
|
|
610
606
|
// provider retry conservatively; new compactions keep the two limits separate.
|
|
611
607
|
const attempts = provider ? (compaction.providerErrors ?? compaction.errors) + 1 : compaction.errors + 1;
|
|
@@ -614,26 +610,9 @@ export function reduceContextModel(snapshot, result, config, usage, now, random)
|
|
|
614
610
|
else
|
|
615
611
|
compaction.errors = attempts;
|
|
616
612
|
const limit = provider ? config.profile.maxProviderRetries : config.contextPolicy.maxSummaryRetries;
|
|
617
|
-
if (attempts > limit)
|
|
618
|
-
if (adaptive || provider && config.providerRecoveryPolicy === 'provider-recovery/v2') {
|
|
619
|
-
compaction.errors = 0;
|
|
620
|
-
compaction.providerErrors = 0;
|
|
621
|
-
return { ...base, phase: 'paused', resumePhase: 'compacting', outcome: null,
|
|
622
|
-
reason: provider ? 'provider_unavailable' : 'context_summary_unavailable', retryNotBefore: 0 };
|
|
623
|
-
}
|
|
613
|
+
if (attempts > limit)
|
|
624
614
|
return { ...base, phase: 'finalizing', outcome: 'unverified', reason: 'context_summary_retry_exhausted' };
|
|
625
|
-
}
|
|
626
|
-
if (adaptive && result.kind === 'output_limit') {
|
|
627
|
-
const previous = compaction.chunk.maxOutputTokens;
|
|
628
|
-
const ceiling = Math.min(config.contextPolicy.summaryOutputCeiling ?? config.profile.maxOutputTokens, config.profile.maxOutputTokens, Math.floor(config.profile.contextWindow / 2));
|
|
629
|
-
if (previous < ceiling)
|
|
630
|
-
compaction.summaryOutputTokens = Math.min(ceiling, previous * 2);
|
|
631
|
-
else
|
|
632
|
-
compaction.quoteLimit = Math.max(1, Math.floor((compaction.chunk.stop - compaction.chunk.start) / 2));
|
|
633
|
-
compaction.chunk = null;
|
|
634
|
-
}
|
|
635
615
|
if (result.kind === 'context_overflow') {
|
|
636
|
-
invariant(compaction.chunk, 'context_summary_quote_missing');
|
|
637
616
|
const length = compaction.chunk.stop - compaction.chunk.start;
|
|
638
617
|
if (length <= 2)
|
|
639
618
|
return { ...base, phase: 'finalizing', outcome: 'blocked', reason: 'context_summary_quote_overflow' };
|
package/dist/contracts.d.mts
CHANGED
|
@@ -182,7 +182,7 @@ export interface ModelProfile {
|
|
|
182
182
|
rule: 'auto' | 'permissive' | 'openai' | 'strict-openai' | 'cerebras' | 'groq' | 'deepseek' | 'zai' | 'kspmas-gateway' | 'moonshot' | 'mimo';
|
|
183
183
|
};
|
|
184
184
|
providerCompatibilityPolicy?: {
|
|
185
|
-
contract: 'provider-compat/v1' | 'provider-compat/v2'
|
|
185
|
+
contract: 'provider-compat/v1' | 'provider-compat/v2';
|
|
186
186
|
rule: NonNullable<ModelProfile['inlineReasoningPolicy']>['rule'];
|
|
187
187
|
};
|
|
188
188
|
streaming?: boolean;
|
|
@@ -330,9 +330,6 @@ export interface HookState {
|
|
|
330
330
|
}
|
|
331
331
|
export interface ContextPlanningPolicy {
|
|
332
332
|
summaryFormatPolicy?: 'task-continuity/v1';
|
|
333
|
-
/** Adapt summary quotes after output exhaustion; preserve history on failure. */
|
|
334
|
-
summaryRecoveryPolicy?: 'adaptive-budget/v1';
|
|
335
|
-
summaryOutputCeiling?: number;
|
|
336
333
|
tokenizerId: string;
|
|
337
334
|
tokenizerDigest: string;
|
|
338
335
|
enabled: boolean;
|
|
@@ -413,7 +410,6 @@ export interface ContextCompaction {
|
|
|
413
410
|
/** Provider retry attempts are separate from invalid-summary/proposal attempts.
|
|
414
411
|
* Absence on restored legacy runs conservatively inherits `errors`. */
|
|
415
412
|
providerErrors?: number;
|
|
416
|
-
summaryOutputTokens?: number;
|
|
417
413
|
hookSubject: ObjectValue;
|
|
418
414
|
hooksComplete: boolean;
|
|
419
415
|
workspaceRevision?: string | null;
|
|
@@ -537,8 +533,6 @@ export interface RunConfiguration {
|
|
|
537
533
|
modelRecoveryPolicy: 'manual' | 'pure-inference/v1';
|
|
538
534
|
guidancePolicy?: 'boundary-guide/v1' | null;
|
|
539
535
|
outputRecoveryPolicy?: 'task-or-delivery/v1' | 'response-boundary/v2' | null;
|
|
540
|
-
/** v2 counts consecutive provider failures and pauses (resumable) instead of failing when they run out. */
|
|
541
|
-
providerRecoveryPolicy?: 'provider-recovery/v2' | null;
|
|
542
536
|
toolErrorRecoveryPolicy?: 'diagnose-before-repeat/v1' | null;
|
|
543
537
|
toolErrorRecoveryModelCalls?: number | null;
|
|
544
538
|
deliveryReviewPolicy?: DeliveryReviewPolicy | null;
|
package/dist/machine.mjs
CHANGED
|
@@ -329,9 +329,6 @@ export function reduceModel(snapshot, input, config, now, random, digest = canon
|
|
|
329
329
|
const replay = boundReplay(result, config);
|
|
330
330
|
const usage = addUsage(snapshot.usage, { ...result.usage, modelCalls: 0, toolCalls: 0 });
|
|
331
331
|
const base = { pendingIntent: null, preparedContext: null, usage,
|
|
332
|
-
// provider-recovery/v2: any provider response ends the consecutive-failure streak.
|
|
333
|
-
...(config.providerRecoveryPolicy === 'provider-recovery/v2' && result.kind !== 'provider_retryable_error'
|
|
334
|
-
&& snapshot.providerErrors ? { providerErrors: 0 } : {}),
|
|
335
332
|
...(snapshot.pendingGuidanceIds?.length && effectiveGuidanceResponse(result) ? { pendingGuidanceIds: [] } : {}),
|
|
336
333
|
...(result.usageReported === false || result.failureDiagnostic || snapshot.diagnostics.lastModelFailure
|
|
337
334
|
? { diagnostics: { ...snapshot.diagnostics,
|
|
@@ -474,13 +471,9 @@ export function reduceModel(snapshot, input, config, now, random, digest = canon
|
|
|
474
471
|
const attempts = (provider ? snapshot.providerErrors : snapshot.modelErrors) + 1;
|
|
475
472
|
const exhausted = attempts > (provider ? config.profile.maxProviderRetries : config.profile.maxRetries);
|
|
476
473
|
const delay = retryDelay(result, attempts, config, random);
|
|
477
|
-
// An unavailable provider is not a task failure: pause with a fresh budget so the Host can resume later.
|
|
478
|
-
if (provider && exhausted && config.providerRecoveryPolicy === 'provider-recovery/v2')
|
|
479
|
-
return { ...base, phase: 'paused',
|
|
480
|
-
resumePhase: 'preparing_context', outcome: null, reason: 'provider_unavailable', providerErrors: 0, retryNotBefore: 0 };
|
|
481
474
|
return { ...base, phase: exhausted ? 'finalizing' : 'preparing_context', outcome: exhausted ? 'failed' : null,
|
|
482
475
|
reason: exhausted ? `${result.kind}_retry_exhausted` : null,
|
|
483
|
-
providerErrors: provider ? attempts :
|
|
476
|
+
providerErrors: provider ? attempts : snapshot.providerErrors,
|
|
484
477
|
modelErrors: provider ? snapshot.modelErrors : attempts, retryNotBefore: exhausted ? 0 : now + delay,
|
|
485
478
|
messages: provider ? snapshot.messages : [...snapshot.messages, { role: 'user', kind: responseContinuationPending(snapshot, config)
|
|
486
479
|
? 'response_continuation_feedback' : 'model_feedback',
|
package/dist/model-surface.d.mts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { ArtifactRef, Message, RunConfiguration, VerificationReport } from './contracts.mjs';
|
|
2
|
-
export declare const NATIVE_LOCAL_RESOURCE_PROFILES: readonly ["bounded/v1", "local-development/v1", "local-development/v2"];
|
|
3
2
|
/** Facts are supplied by the execution owner, never inferred from prompt prose. */
|
|
4
3
|
export interface WorkspaceBrowserCapability {
|
|
5
4
|
contract: 'agentkit.workspace-browser-capability/v1';
|
|
@@ -24,7 +23,7 @@ export interface ModelSurface {
|
|
|
24
23
|
environmentNames?: string[];
|
|
25
24
|
commandResources?: {
|
|
26
25
|
contract: 'agentkit.local-resource-profile/v1';
|
|
27
|
-
profile:
|
|
26
|
+
profile: 'bounded/v1' | 'local-development/v1';
|
|
28
27
|
requestedLimits: {
|
|
29
28
|
cpuSeconds: number;
|
|
30
29
|
addressSpaceBytes: number;
|
package/dist/model-surface.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { canonical, copy, invariant } from './values.mjs';
|
|
2
|
-
export const NATIVE_LOCAL_RESOURCE_PROFILES = ['bounded/v1', 'local-development/v1', 'local-development/v2'];
|
|
3
2
|
const bytes = (value) => new TextEncoder().encode(canonical(value)).length;
|
|
4
3
|
export function validateModelSurface(surface) {
|
|
5
4
|
if (surface === undefined)
|
|
@@ -36,7 +35,7 @@ export function validateModelSurface(surface) {
|
|
|
36
35
|
invariant(env.commandBackend === 'local_process' && resources
|
|
37
36
|
&& Object.keys(resources).sort().join(',') === 'contract,profile,requestedLimits'
|
|
38
37
|
&& resources.contract === 'agentkit.local-resource-profile/v1'
|
|
39
|
-
&&
|
|
38
|
+
&& ['bounded/v1', 'local-development/v1'].includes(resources.profile)
|
|
40
39
|
&& resources.requestedLimits && Object.keys(resources.requestedLimits).sort().join(',') === [...keys].sort().join(',')
|
|
41
40
|
&& Object.values(resources.requestedLimits).every(value => Number.isSafeInteger(value) && value > 0), 'invalid_model_command_resources');
|
|
42
41
|
}
|
package/dist/transitions.mjs
CHANGED
|
@@ -148,8 +148,7 @@ export function reduceCommand(snapshot, command, pending = null, bindings = {})
|
|
|
148
148
|
if (snapshot.phase !== 'paused')
|
|
149
149
|
reason = 'not_paused';
|
|
150
150
|
else
|
|
151
|
-
changes = { phase: snapshot.resumePhase ?? 'preparing_context', resumePhase: null
|
|
152
|
-
...(['provider_unavailable', 'context_summary_unavailable'].includes(snapshot.reason ?? '') ? { reason: null } : {}) };
|
|
151
|
+
changes = { phase: snapshot.resumePhase ?? 'preparing_context', resumePhase: null };
|
|
153
152
|
break;
|
|
154
153
|
case 'submit_interaction': {
|
|
155
154
|
const pending = snapshot.pendingInteraction;
|
package/package.json
CHANGED
package/src/configuration.mts
CHANGED
|
@@ -36,7 +36,6 @@ export interface ConfigurationInput {
|
|
|
36
36
|
inputPolicy?: RunConfiguration['inputPolicy'];
|
|
37
37
|
sourceReadPolicy?: RunConfiguration['sourceReadPolicy'];
|
|
38
38
|
outputRecoveryPolicy?: RunConfiguration['outputRecoveryPolicy'];
|
|
39
|
-
providerRecoveryPolicy?: RunConfiguration['providerRecoveryPolicy'];
|
|
40
39
|
toolErrorRecoveryPolicy?: RunConfiguration['toolErrorRecoveryPolicy'];
|
|
41
40
|
toolDiscoveryPolicy?: RunConfiguration['toolDiscoveryPolicy'];
|
|
42
41
|
todoPolicy?: RunConfiguration['todoPolicy'];
|
|
@@ -96,7 +95,6 @@ export function configure(input: ConfigurationInput): RunConfiguration {
|
|
|
96
95
|
...(input.inputPolicy === undefined ? {} : { inputPolicy: input.inputPolicy }),
|
|
97
96
|
...(input.sourceReadPolicy === undefined ? {} : { sourceReadPolicy: input.sourceReadPolicy }),
|
|
98
97
|
...(input.outputRecoveryPolicy === undefined ? {} : { outputRecoveryPolicy: input.outputRecoveryPolicy }),
|
|
99
|
-
...(input.providerRecoveryPolicy === undefined ? {} : { providerRecoveryPolicy: input.providerRecoveryPolicy }),
|
|
100
98
|
...(input.toolErrorRecoveryPolicy === undefined ? {} : { toolErrorRecoveryPolicy: input.toolErrorRecoveryPolicy }),
|
|
101
99
|
...(input.toolDiscoveryPolicy === undefined ? {} : { toolDiscoveryPolicy: input.toolDiscoveryPolicy }),
|
|
102
100
|
...(input.todoPolicy === undefined ? {} : { todoPolicy: input.todoPolicy }),
|
|
@@ -152,7 +150,6 @@ export function configure(input: ConfigurationInput): RunConfiguration {
|
|
|
152
150
|
invariant(config.guidancePolicy == null || config.guidancePolicy === 'boundary-guide/v1', 'invalid_guidance_policy');
|
|
153
151
|
invariant(config.inputPolicy === undefined || config.inputPolicy === 'before-first-model/v1', 'invalid_input_policy');
|
|
154
152
|
invariant(config.outputRecoveryPolicy == null || ['task-or-delivery/v1', 'response-boundary/v2'].includes(config.outputRecoveryPolicy), 'invalid_output_recovery_policy');
|
|
155
|
-
invariant(config.providerRecoveryPolicy == null || config.providerRecoveryPolicy === 'provider-recovery/v2', 'invalid_provider_recovery_policy');
|
|
156
153
|
invariant(config.toolExecutionPolicy === undefined || config.toolExecutionPolicy === 'owner-execution/v1', 'invalid_tool_execution_policy');
|
|
157
154
|
invariant(config.toolErrorRecoveryPolicy == null || config.toolErrorRecoveryPolicy === 'diagnose-before-repeat/v1', 'invalid_tool_error_recovery_policy');
|
|
158
155
|
invariant(config.toolErrorRecoveryModelCalls == null || Number.isSafeInteger(config.toolErrorRecoveryModelCalls)
|
|
@@ -222,7 +219,7 @@ export function configure(input: ConfigurationInput): RunConfiguration {
|
|
|
222
219
|
}
|
|
223
220
|
invariant(profile.maxOutputTokens > 0 && profile.maxOutputTokens < profile.contextWindow
|
|
224
221
|
&& profile.requestTimeoutMs > 0 && profile.requestTimeoutMs < limits.effectTimeoutMs
|
|
225
|
-
&& profile.maxProviderRetries <=
|
|
222
|
+
&& profile.maxProviderRetries <= 9 && profile.retryInitialDelayMs <= profile.retryMaxDelayMs
|
|
226
223
|
&& Number.isFinite(profile.retryBackoffMultiplier) && profile.retryBackoffMultiplier >= 1, 'invalid_model_profile');
|
|
227
224
|
if (profile.inlineReasoningPolicy !== undefined) {
|
|
228
225
|
const policy = profile.inlineReasoningPolicy;
|
|
@@ -236,7 +233,7 @@ export function configure(input: ConfigurationInput): RunConfiguration {
|
|
|
236
233
|
const policy = profile.providerCompatibilityPolicy;
|
|
237
234
|
invariant(policy !== null && typeof policy === 'object' && !Array.isArray(policy)
|
|
238
235
|
&& Object.keys(policy).every(key => ['contract', 'rule'].includes(key))
|
|
239
|
-
&& ['provider-compat/v1', 'provider-compat/v2'
|
|
236
|
+
&& ['provider-compat/v1', 'provider-compat/v2'].includes(policy.contract)
|
|
240
237
|
&& ['auto', 'permissive', 'openai', 'strict-openai', 'cerebras', 'groq', 'deepseek',
|
|
241
238
|
'zai', 'kspmas-gateway', 'moonshot', 'mimo'].includes(policy.rule), 'invalid_provider_compatibility_policy');
|
|
242
239
|
}
|
|
@@ -357,10 +354,6 @@ export function configure(input: ConfigurationInput): RunConfiguration {
|
|
|
357
354
|
|| config.backgroundNotificationPolicy === 'completed-before-model/v1', 'invalid_background_notification_policy');
|
|
358
355
|
if (config.contextPolicy) {
|
|
359
356
|
const policy = config.contextPolicy;
|
|
360
|
-
invariant(policy.summaryOutputCeiling === undefined || policy.summaryRecoveryPolicy === 'adaptive-budget/v1'
|
|
361
|
-
&& Number.isSafeInteger(policy.summaryOutputCeiling) && policy.summaryOutputCeiling > 0
|
|
362
|
-
&& policy.summaryOutputCeiling <= profile.maxOutputTokens, 'invalid_summary_output_ceiling');
|
|
363
|
-
invariant(policy.summaryRecoveryPolicy === undefined || policy.summaryRecoveryPolicy === 'adaptive-budget/v1', 'invalid_summary_recovery_policy');
|
|
364
357
|
invariant(policy.summaryFormatPolicy === undefined || policy.summaryFormatPolicy === 'task-continuity/v1',
|
|
365
358
|
'invalid_summary_format_policy');
|
|
366
359
|
invariant(typeof policy.tokenizerId === 'string' && policy.tokenizerId.trim() && typeof policy.tokenizerDigest === 'string' && policy.tokenizerDigest.trim()
|
package/src/context-planning.mts
CHANGED
|
@@ -230,8 +230,7 @@ function codePointStop(text: string, stop: number): number {
|
|
|
230
230
|
async function quoteChunk(snapshot: RunSnapshot, compaction: ContextCompaction, config: RunConfiguration,
|
|
231
231
|
counters: ContextCounters, digest: (value: unknown) => string, policies: NativePolicyRegistry): Promise<void> {
|
|
232
232
|
const maxOutputTokens = ['deadline-delivery/v1', 'deadline-delivery/v2'].includes(config.wallDeliveryPolicy ?? '')
|
|
233
|
-
? config.profile.maxOutputTokens : Math.min(
|
|
234
|
-
invariant(Number.isSafeInteger(maxOutputTokens) && maxOutputTokens > 0 && maxOutputTokens < config.profile.contextWindow, 'context_summary_budget_invalid');
|
|
233
|
+
? config.profile.maxOutputTokens : Math.min(config.contextPolicy!.summaryMaxTokens, config.profile.maxOutputTokens);
|
|
235
234
|
const prefix = snapshot.messages.slice(0, compaction.prefixCount), refs = refsOf(prefix, digest);
|
|
236
235
|
const projected = summaryProjection(prefix, compaction, config, digest);
|
|
237
236
|
const mediaFor = (stop: number): NonNullable<Message['media']> => {
|
|
@@ -526,41 +525,23 @@ export function reduceContextModel(snapshot: RunSnapshot, result: ModelResult, c
|
|
|
526
525
|
invariant(compaction?.chunk, 'context_summary_quote_missing');
|
|
527
526
|
const base: Partial<RunSnapshot> = { pendingIntent: null, contextState: state, preparedContext: null, usage,
|
|
528
527
|
phase: 'compacting', ...(result.usageReported === false ? { diagnostics: { ...snapshot.diagnostics, providerUsageIncomplete: true } } : {}) };
|
|
529
|
-
|
|
530
|
-
if (!adaptive && result.kind === 'output_limit' && result.text.trim() && result.textCommitVersion !== 'provider-finished-text/v1') {
|
|
528
|
+
if (result.kind === 'output_limit' && result.text.trim() && result.textCommitVersion !== 'provider-finished-text/v1') {
|
|
531
529
|
return { ...base, phase: 'finalizing', outcome: 'blocked', reason: 'context_summary_provider_commit_missing' };
|
|
532
530
|
}
|
|
533
|
-
if (
|
|
531
|
+
if (['final_candidate', 'output_limit'].includes(result.kind) && result.text.trim() && !result.toolCalls.length) {
|
|
534
532
|
compaction.proposal = result.text; return base;
|
|
535
533
|
}
|
|
536
534
|
if (['policy_abort', 'user_abort', 'provider_terminal_error'].includes(result.kind)) return { ...base, phase: 'finalizing',
|
|
537
535
|
outcome: result.kind === 'policy_abort' ? 'blocked' : 'unverified', reason: `context_summary_${result.kind}` };
|
|
538
536
|
const provider = result.kind === 'provider_retryable_error';
|
|
539
|
-
if (!provider && config.providerRecoveryPolicy === 'provider-recovery/v2') compaction.providerErrors = 0;
|
|
540
537
|
// Old persisted compactions had one combined counter. Seed their first
|
|
541
538
|
// provider retry conservatively; new compactions keep the two limits separate.
|
|
542
539
|
const attempts = provider ? (compaction.providerErrors ?? compaction.errors) + 1 : compaction.errors + 1;
|
|
543
540
|
if (provider) compaction.providerErrors = attempts;
|
|
544
541
|
else compaction.errors = attempts;
|
|
545
542
|
const limit = provider ? config.profile.maxProviderRetries : config.contextPolicy!.maxSummaryRetries;
|
|
546
|
-
if (attempts > limit) {
|
|
547
|
-
if (adaptive || provider && config.providerRecoveryPolicy === 'provider-recovery/v2') {
|
|
548
|
-
compaction.errors = 0; compaction.providerErrors = 0;
|
|
549
|
-
return { ...base, phase: 'paused', resumePhase: 'compacting', outcome: null,
|
|
550
|
-
reason: provider ? 'provider_unavailable' : 'context_summary_unavailable', retryNotBefore: 0 };
|
|
551
|
-
}
|
|
552
|
-
return { ...base, phase: 'finalizing', outcome: 'unverified', reason: 'context_summary_retry_exhausted' };
|
|
553
|
-
}
|
|
554
|
-
if (adaptive && result.kind === 'output_limit') {
|
|
555
|
-
const previous = compaction.chunk.maxOutputTokens;
|
|
556
|
-
const ceiling = Math.min(config.contextPolicy!.summaryOutputCeiling ?? config.profile.maxOutputTokens,
|
|
557
|
-
config.profile.maxOutputTokens, Math.floor(config.profile.contextWindow / 2));
|
|
558
|
-
if (previous < ceiling) compaction.summaryOutputTokens = Math.min(ceiling, previous * 2);
|
|
559
|
-
else compaction.quoteLimit = Math.max(1, Math.floor((compaction.chunk.stop - compaction.chunk.start) / 2));
|
|
560
|
-
compaction.chunk = null;
|
|
561
|
-
}
|
|
543
|
+
if (attempts > limit) return { ...base, phase: 'finalizing', outcome: 'unverified', reason: 'context_summary_retry_exhausted' };
|
|
562
544
|
if (result.kind === 'context_overflow') {
|
|
563
|
-
invariant(compaction.chunk, 'context_summary_quote_missing');
|
|
564
545
|
const length = compaction.chunk.stop - compaction.chunk.start;
|
|
565
546
|
if (length <= 2) return { ...base, phase: 'finalizing', outcome: 'blocked', reason: 'context_summary_quote_overflow' };
|
|
566
547
|
compaction.quoteLimit = Math.max(1, Math.floor(length / 2)); compaction.chunk = null;
|
package/src/contracts.mts
CHANGED
|
@@ -105,7 +105,7 @@ export interface ModelProfile {
|
|
|
105
105
|
/** Absent on older Runs; projection policy is frozen at admission. */
|
|
106
106
|
inlineReasoningPolicy?: { contract: 'profiled-content/v1' | 'profiled-content/v2'; rule: 'auto' | 'permissive' | 'openai'
|
|
107
107
|
| 'strict-openai' | 'cerebras' | 'groq' | 'deepseek' | 'zai' | 'kspmas-gateway' | 'moonshot' | 'mimo' };
|
|
108
|
-
providerCompatibilityPolicy?: { contract: 'provider-compat/v1' | 'provider-compat/v2'
|
|
108
|
+
providerCompatibilityPolicy?: { contract: 'provider-compat/v1' | 'provider-compat/v2'; rule: NonNullable<ModelProfile['inlineReasoningPolicy']>['rule'] };
|
|
109
109
|
streaming?: boolean; outputTokenParameter?: 'max_tokens' | 'max_completion_tokens';
|
|
110
110
|
streamTimeoutPolicy?: 'idle/v1'; providerThinkingDisplay?: boolean;
|
|
111
111
|
/** Absent on historical Runs, whose OpenAI usage reports required equality. */
|
|
@@ -181,9 +181,6 @@ export interface HookState {
|
|
|
181
181
|
}
|
|
182
182
|
export interface ContextPlanningPolicy {
|
|
183
183
|
summaryFormatPolicy?: 'task-continuity/v1';
|
|
184
|
-
/** Adapt summary quotes after output exhaustion; preserve history on failure. */
|
|
185
|
-
summaryRecoveryPolicy?: 'adaptive-budget/v1';
|
|
186
|
-
summaryOutputCeiling?: number;
|
|
187
184
|
tokenizerId: string; tokenizerDigest: string; enabled: boolean;
|
|
188
185
|
/** Estimates bound complete requests; exact counters keep the strict summary ceiling. */
|
|
189
186
|
summaryBudgetMode?: 'strict' | 'context_bounded_estimate';
|
|
@@ -228,7 +225,6 @@ export interface ContextCompaction {
|
|
|
228
225
|
/** Provider retry attempts are separate from invalid-summary/proposal attempts.
|
|
229
226
|
* Absence on restored legacy runs conservatively inherits `errors`. */
|
|
230
227
|
providerErrors?: number;
|
|
231
|
-
summaryOutputTokens?: number;
|
|
232
228
|
hookSubject: ObjectValue; hooksComplete: boolean;
|
|
233
229
|
workspaceRevision?: string | null;
|
|
234
230
|
/** References into the immutable prefix; cleared groups must belong to removedRefs. */
|
|
@@ -306,8 +302,6 @@ export interface RunConfiguration {
|
|
|
306
302
|
modelRecoveryPolicy: 'manual' | 'pure-inference/v1';
|
|
307
303
|
guidancePolicy?: 'boundary-guide/v1' | null;
|
|
308
304
|
outputRecoveryPolicy?: 'task-or-delivery/v1' | 'response-boundary/v2' | null;
|
|
309
|
-
/** v2 counts consecutive provider failures and pauses (resumable) instead of failing when they run out. */
|
|
310
|
-
providerRecoveryPolicy?: 'provider-recovery/v2' | null;
|
|
311
305
|
toolErrorRecoveryPolicy?: 'diagnose-before-repeat/v1' | null;
|
|
312
306
|
toolErrorRecoveryModelCalls?: number | null;
|
|
313
307
|
deliveryReviewPolicy?: DeliveryReviewPolicy | null;
|
package/src/machine.mts
CHANGED
|
@@ -311,9 +311,6 @@ export function reduceModel(snapshot: RunSnapshot, input: ModelResult, config: R
|
|
|
311
311
|
const replay = boundReplay(result, config);
|
|
312
312
|
const usage = addUsage(snapshot.usage, { ...result.usage, modelCalls: 0, toolCalls: 0 });
|
|
313
313
|
const base: Partial<RunSnapshot> = { pendingIntent: null, preparedContext: null, usage,
|
|
314
|
-
// provider-recovery/v2: any provider response ends the consecutive-failure streak.
|
|
315
|
-
...(config.providerRecoveryPolicy === 'provider-recovery/v2' && result.kind !== 'provider_retryable_error'
|
|
316
|
-
&& snapshot.providerErrors ? { providerErrors: 0 } : {}),
|
|
317
314
|
...(snapshot.pendingGuidanceIds?.length && effectiveGuidanceResponse(result) ? { pendingGuidanceIds: [] } : {}),
|
|
318
315
|
...(result.usageReported === false || result.failureDiagnostic || snapshot.diagnostics.lastModelFailure
|
|
319
316
|
? { diagnostics: { ...snapshot.diagnostics,
|
|
@@ -443,12 +440,9 @@ export function reduceModel(snapshot: RunSnapshot, input: ModelResult, config: R
|
|
|
443
440
|
const attempts = (provider ? snapshot.providerErrors : snapshot.modelErrors) + 1;
|
|
444
441
|
const exhausted = attempts > (provider ? config.profile.maxProviderRetries : config.profile.maxRetries);
|
|
445
442
|
const delay = retryDelay(result, attempts, config, random);
|
|
446
|
-
// An unavailable provider is not a task failure: pause with a fresh budget so the Host can resume later.
|
|
447
|
-
if (provider && exhausted && config.providerRecoveryPolicy === 'provider-recovery/v2') return { ...base, phase: 'paused',
|
|
448
|
-
resumePhase: 'preparing_context', outcome: null, reason: 'provider_unavailable', providerErrors: 0, retryNotBefore: 0 };
|
|
449
443
|
return { ...base, phase: exhausted ? 'finalizing' : 'preparing_context', outcome: exhausted ? 'failed' : null,
|
|
450
444
|
reason: exhausted ? `${result.kind}_retry_exhausted` : null,
|
|
451
|
-
providerErrors: provider ? attempts :
|
|
445
|
+
providerErrors: provider ? attempts : snapshot.providerErrors,
|
|
452
446
|
modelErrors: provider ? snapshot.modelErrors : attempts, retryNotBefore: exhausted ? 0 : now + delay,
|
|
453
447
|
messages: provider ? snapshot.messages : [...snapshot.messages, { role: 'user', kind: responseContinuationPending(snapshot, config)
|
|
454
448
|
? 'response_continuation_feedback' : 'model_feedback',
|
package/src/model-surface.mts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type { ArtifactRef, Message, RunConfiguration, VerificationReport } from './contracts.mjs';
|
|
2
2
|
import { canonical, copy, invariant } from './values.mjs';
|
|
3
3
|
|
|
4
|
-
export const NATIVE_LOCAL_RESOURCE_PROFILES = ['bounded/v1', 'local-development/v1', 'local-development/v2'] as const;
|
|
5
|
-
|
|
6
4
|
/** Facts are supplied by the execution owner, never inferred from prompt prose. */
|
|
7
5
|
export interface WorkspaceBrowserCapability {
|
|
8
6
|
contract: 'agentkit.workspace-browser-capability/v1'; toolName: 'browser_inspect_workspace';
|
|
@@ -18,7 +16,7 @@ export interface ModelSurface {
|
|
|
18
16
|
commandBackend: 'local_process' | 'e2b' | 'none';
|
|
19
17
|
commandCwd?: string; environmentNames?: string[];
|
|
20
18
|
commandResources?: {
|
|
21
|
-
contract: 'agentkit.local-resource-profile/v1'; profile:
|
|
19
|
+
contract: 'agentkit.local-resource-profile/v1'; profile: 'bounded/v1' | 'local-development/v1';
|
|
22
20
|
requestedLimits: { cpuSeconds: number; addressSpaceBytes: number; maxProcesses: number;
|
|
23
21
|
maxOpenFiles: number; maxFileBytes: number; wallSeconds: number };
|
|
24
22
|
};
|
|
@@ -60,7 +58,7 @@ export function validateModelSurface(surface: ModelSurface | undefined): void {
|
|
|
60
58
|
invariant(env.commandBackend === 'local_process' && resources
|
|
61
59
|
&& Object.keys(resources).sort().join(',') === 'contract,profile,requestedLimits'
|
|
62
60
|
&& resources.contract === 'agentkit.local-resource-profile/v1'
|
|
63
|
-
&&
|
|
61
|
+
&& ['bounded/v1', 'local-development/v1'].includes(resources.profile)
|
|
64
62
|
&& resources.requestedLimits && Object.keys(resources.requestedLimits).sort().join(',') === [...keys].sort().join(',')
|
|
65
63
|
&& Object.values(resources.requestedLimits).every(value => Number.isSafeInteger(value) && value > 0),
|
|
66
64
|
'invalid_model_command_resources');
|
package/src/transitions.mts
CHANGED
|
@@ -143,8 +143,7 @@ export function reduceCommand(snapshot: RunSnapshot, command: RunCommand, pendin
|
|
|
143
143
|
break;
|
|
144
144
|
case 'resume':
|
|
145
145
|
if (snapshot.phase !== 'paused') reason = 'not_paused';
|
|
146
|
-
else changes = { phase: snapshot.resumePhase ?? 'preparing_context', resumePhase: null
|
|
147
|
-
...(['provider_unavailable', 'context_summary_unavailable'].includes(snapshot.reason ?? '') ? { reason: null } : {}) };
|
|
146
|
+
else changes = { phase: snapshot.resumePhase ?? 'preparing_context', resumePhase: null };
|
|
148
147
|
break;
|
|
149
148
|
case 'submit_interaction': {
|
|
150
149
|
const pending = snapshot.pendingInteraction;
|