@framers/agentos 0.10.22 → 0.10.23
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 +1 -1
- package/dist/api/generateText.d.ts +14 -1
- package/dist/api/generateText.d.ts.map +1 -1
- package/dist/api/generateText.js +165 -20
- package/dist/api/generateText.js.map +1 -1
- package/dist/api/model.d.ts +25 -1
- package/dist/api/model.d.ts.map +1 -1
- package/dist/api/model.js +105 -3
- package/dist/api/model.js.map +1 -1
- package/dist/api/runtime/global-default.d.ts +9 -1
- package/dist/api/runtime/global-default.d.ts.map +1 -1
- package/dist/api/runtime/global-default.js.map +1 -1
- package/dist/api/runtime/provider-defaults.d.ts.map +1 -1
- package/dist/api/runtime/provider-defaults.js +5 -2
- package/dist/api/runtime/provider-defaults.js.map +1 -1
- package/dist/api/runtime/tool-emulation/history.d.ts +16 -0
- package/dist/api/runtime/tool-emulation/history.d.ts.map +1 -0
- package/dist/api/runtime/tool-emulation/history.js +89 -0
- package/dist/api/runtime/tool-emulation/history.js.map +1 -0
- package/dist/api/runtime/tool-emulation/index.d.ts +1 -0
- package/dist/api/runtime/tool-emulation/index.d.ts.map +1 -1
- package/dist/api/runtime/tool-emulation/index.js +1 -0
- package/dist/api/runtime/tool-emulation/index.js.map +1 -1
- package/dist/api/runtime/tool-emulation/loop.d.ts +6 -0
- package/dist/api/runtime/tool-emulation/loop.d.ts.map +1 -1
- package/dist/api/runtime/tool-emulation/loop.js +1 -0
- package/dist/api/runtime/tool-emulation/loop.js.map +1 -1
- package/dist/api/sessionTranscript.d.ts +34 -0
- package/dist/api/sessionTranscript.d.ts.map +1 -1
- package/dist/api/sessionTranscript.js +61 -1
- package/dist/api/sessionTranscript.js.map +1 -1
- package/dist/api/streamText.d.ts.map +1 -1
- package/dist/api/streamText.js +27 -7
- package/dist/api/streamText.js.map +1 -1
- package/dist/core/llm/providers/AIModelProviderManager.d.ts +20 -0
- package/dist/core/llm/providers/AIModelProviderManager.d.ts.map +1 -1
- package/dist/core/llm/providers/AIModelProviderManager.js +35 -5
- package/dist/core/llm/providers/AIModelProviderManager.js.map +1 -1
- package/dist/core/llm/providers/implementations/AnthropicProvider.d.ts.map +1 -1
- package/dist/core/llm/providers/implementations/AnthropicProvider.js +29 -4
- package/dist/core/llm/providers/implementations/AnthropicProvider.js.map +1 -1
- package/dist/core/llm/providers/implementations/GeminiProvider.d.ts +6 -0
- package/dist/core/llm/providers/implementations/GeminiProvider.d.ts.map +1 -1
- package/dist/core/llm/providers/implementations/GeminiProvider.js +46 -66
- package/dist/core/llm/providers/implementations/GeminiProvider.js.map +1 -1
- package/dist/core/llm/providers/implementations/MistralProvider.d.ts +11 -0
- package/dist/core/llm/providers/implementations/MistralProvider.d.ts.map +1 -1
- package/dist/core/llm/providers/implementations/MistralProvider.js +32 -2
- package/dist/core/llm/providers/implementations/MistralProvider.js.map +1 -1
- package/dist/core/llm/providers/implementations/OllamaProvider.js +7 -7
- package/dist/core/llm/providers/implementations/OllamaProvider.js.map +1 -1
- package/dist/core/llm/providers/implementations/OpenAIProvider.js +7 -7
- package/dist/core/llm/providers/implementations/OpenAIProvider.js.map +1 -1
- package/dist/core/llm/providers/implementations/OpenRouterProvider.d.ts.map +1 -1
- package/dist/core/llm/providers/implementations/OpenRouterProvider.js +8 -3
- package/dist/core/llm/providers/implementations/OpenRouterProvider.js.map +1 -1
- package/dist/core/llm/providers/implementations/TogetherProvider.d.ts +3 -3
- package/dist/core/llm/providers/implementations/TogetherProvider.d.ts.map +1 -1
- package/dist/core/llm/providers/implementations/TogetherProvider.js +25 -13
- package/dist/core/llm/providers/implementations/TogetherProvider.js.map +1 -1
- package/dist/core/llm/providers/openrouter-only-params.d.ts +26 -7
- package/dist/core/llm/providers/openrouter-only-params.d.ts.map +1 -1
- package/dist/core/llm/providers/openrouter-only-params.js +58 -9
- package/dist/core/llm/providers/openrouter-only-params.js.map +1 -1
- package/dist/core/llm/providers/url-secrets.d.ts +42 -0
- package/dist/core/llm/providers/url-secrets.d.ts.map +1 -0
- package/dist/core/llm/providers/url-secrets.js +64 -0
- package/dist/core/llm/providers/url-secrets.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/orchestration/pipeline/query/types.js +2 -2
- package/dist/orchestration/pipeline/query/types.js.map +1 -1
- package/dist/orchestration/planning/ProviderAssignmentEngine.js +2 -2
- package/dist/orchestration/planning/ProviderAssignmentEngine.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -78,7 +78,7 @@ await session.send('Can you expand on that?'); // remembers context
|
|
|
78
78
|
|
|
79
79
|
[Full quickstart](https://docs.agentos.sh/getting-started) * [Examples cookbook](https://docs.agentos.sh/getting-started/examples) * [API reference](https://docs.agentos.sh/api)
|
|
80
80
|
|
|
81
|
-
**Sessions.** A session keeps the whole conversation
|
|
81
|
+
**Sessions.** A session keeps the whole conversation whether memory is on or off: each `send()` records its tool calls, their results and the model's signed thinking, and every later request replays them. `stream()` records its turn as the prompt and the final text. History is capped at about 120K tokens by default. Set `history: false` for a stateless session, set `history: { maxTokens }` to change the cap, and call `reseed()` to replace the history with a shorter set of messages you build yourself.
|
|
82
82
|
|
|
83
83
|
```ts
|
|
84
84
|
const stateless = agent({ model, memory: false, history: false }).session('job-1');
|
|
@@ -5,7 +5,7 @@ import type { AgentOSUsageLedgerOptions } from './runtime/usageLedger.js';
|
|
|
5
5
|
import type { ITool } from '../core/tools/ITool.js';
|
|
6
6
|
import type { AgentCallRecord, AgencyTraceEvent } from './types.js';
|
|
7
7
|
import type { IModelRouter, ModelRouteParams } from '../core/llm/routing/IModelRouter.js';
|
|
8
|
-
import type
|
|
8
|
+
import { type SessionTranscriptMessage } from './sessionTranscript.js';
|
|
9
9
|
import type { MessageContent, MessageContentPart, CacheDiagnostics } from '../core/llm/providers/IProvider.js';
|
|
10
10
|
export type { MessageContent, MessageContentPart };
|
|
11
11
|
export type { HostLLMPolicy } from './runtime/hostPolicy.js';
|
|
@@ -643,6 +643,19 @@ export interface GenerateTextOptions {
|
|
|
643
643
|
* captured positionally). Not part of the public API.
|
|
644
644
|
*/
|
|
645
645
|
_transcriptIncludeTrailingCallerMessages?: number;
|
|
646
|
+
/**
|
|
647
|
+
* INTERNAL (failover): the call a fallback leg continues. The leg keeps
|
|
648
|
+
* the call's tool run id, so tool execution contexts carry the same
|
|
649
|
+
* session, numbers its steps from `stepOffset` in hooks, synthetic tool
|
|
650
|
+
* call ids and tool contexts, and reports the call's original `prompt` to
|
|
651
|
+
* hooks (a leg that continues after tool rounds receives it inside
|
|
652
|
+
* `messages` instead). Not part of the public API.
|
|
653
|
+
*/
|
|
654
|
+
_continuation?: {
|
|
655
|
+
helperToolRunId: string;
|
|
656
|
+
stepOffset: number;
|
|
657
|
+
prompt?: string;
|
|
658
|
+
};
|
|
646
659
|
}
|
|
647
660
|
/**
|
|
648
661
|
* The completed result returned by {@link generateText}.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateText.d.ts","sourceRoot":"","sources":["../../src/api/generateText.ts"],"names":[],"mappings":"AAiBA,OAAO,EAGL,KAAK,aAAa,EACnB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAc,KAAK,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC/E,OAAO,
|
|
1
|
+
{"version":3,"file":"generateText.d.ts","sourceRoot":"","sources":["../../src/api/generateText.ts"],"names":[],"mappings":"AAiBA,OAAO,EAGL,KAAK,aAAa,EACnB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAc,KAAK,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC/E,OAAO,EAAuC,KAAK,QAAQ,EAAE,MAAM,mCAAmC,CAAC;AACvG,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AAE1E,OAAO,KAAK,EAAE,KAAK,EAAwB,MAAM,wBAAwB,CAAC;AAG1E,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AAG,SAAS,CAAC;IAC3B,KAAK,EAAE;QAAE,GAAG,CAAC,EAAE,IAAI,GAAG,IAAI,CAAA;KAAE,GAAG,KAAK,GAAG,SAAS,CAAC;IACjD,SAAS,EAAE,eAAe,CAAC;CAC5B,CAgBA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,QAAQ,GAAG,eAAe,GAAG,SAAS,EAClE,eAAe,CAAC,EAAE,MAAM,GACvB,qBAAqB,EAAE,CA0CzB;AAwBD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAsB,YAAY,CAAC,IAAI,EAAE,mBAAmB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAkmCzF"}
|
package/dist/api/generateText.js
CHANGED
|
@@ -17,7 +17,7 @@ import { attachGenAiAttributes, attachUsageAttributes, toTurnMetricUsage } from
|
|
|
17
17
|
import { fireLlmUsageObserver } from './observers.js';
|
|
18
18
|
import { hostPolicyToRouteParams, mergeRequiredCapabilities, } from './runtime/hostPolicy.js';
|
|
19
19
|
import { adaptTools } from './runtime/toolAdapter.js';
|
|
20
|
-
import { runEmulatedToolLoop } from './runtime/tool-emulation/index.js';
|
|
20
|
+
import { runEmulatedToolLoop, toShimMessages } from './runtime/tool-emulation/index.js';
|
|
21
21
|
import { resolveDynamicToolCalls } from './runtime/dynamicToolCalling.js';
|
|
22
22
|
import { recordAgentOSTurnMetrics, withAgentOSSpan } from '../safety/evaluation/observability/otel.js';
|
|
23
23
|
import { createLogger } from '../core/logging/loggerFactory.js';
|
|
@@ -66,6 +66,7 @@ class LLMProviderCircuitOpenError extends Error {
|
|
|
66
66
|
this.name = 'LLMProviderCircuitOpenError';
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
+
import { toProviderReplayMessage } from './sessionTranscript.js';
|
|
69
70
|
async function recordAgentOSUsageLazy(input) {
|
|
70
71
|
const { recordAgentOSUsage } = await import('./runtime/usageLedger.js');
|
|
71
72
|
return recordAgentOSUsage(input);
|
|
@@ -252,6 +253,60 @@ function formatPlanForPrompt(plan) {
|
|
|
252
253
|
* @internal
|
|
253
254
|
*/
|
|
254
255
|
const RETRYABLE_HTTP_STATUSES = new Set([401, 402, 403, 429, 500, 502, 503, 504]);
|
|
256
|
+
/**
|
|
257
|
+
* Whether the tool round a continuation answers was requested without
|
|
258
|
+
* thinking blocks, as it is when another provider's model ran it.
|
|
259
|
+
*/
|
|
260
|
+
function toolTurnLacksThinking(messages) {
|
|
261
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
262
|
+
const message = messages[i];
|
|
263
|
+
if (message.role !== 'assistant' || !Array.isArray(message.tool_calls) || message.tool_calls.length === 0) {
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
return !Array.isArray(message.thinkingBlocks) || message.thinkingBlocks.length === 0;
|
|
267
|
+
}
|
|
268
|
+
return false;
|
|
269
|
+
}
|
|
270
|
+
/** Property key that marks an error thrown after the call's tools ran. */
|
|
271
|
+
const TOOLS_RAN = Symbol.for('agentos.generateText.toolsRan');
|
|
272
|
+
/**
|
|
273
|
+
* Marks `error` as thrown after the call's tools ran, so a fallback walker
|
|
274
|
+
* that called this call as a leg stops instead of restarting on another
|
|
275
|
+
* provider, which would run the tools again. A non-object is wrapped in an
|
|
276
|
+
* Error first.
|
|
277
|
+
*
|
|
278
|
+
* @returns The marked error.
|
|
279
|
+
*/
|
|
280
|
+
function markToolsRan(error) {
|
|
281
|
+
const target = error !== null && typeof error === 'object' ? error : new Error(String(error));
|
|
282
|
+
try {
|
|
283
|
+
Object.defineProperty(target, TOOLS_RAN, { value: true, configurable: true });
|
|
284
|
+
}
|
|
285
|
+
catch {
|
|
286
|
+
// A frozen error cannot carry the mark.
|
|
287
|
+
}
|
|
288
|
+
return target;
|
|
289
|
+
}
|
|
290
|
+
/** Whether `error` was marked by {@link markToolsRan}. */
|
|
291
|
+
function toolsRanBefore(error) {
|
|
292
|
+
return (error !== null &&
|
|
293
|
+
typeof error === 'object' &&
|
|
294
|
+
error[TOOLS_RAN] === true);
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Provider error codes for request-level failures that another provider may
|
|
298
|
+
* not share: unreachable endpoints, request timeouts, and retries exhausted
|
|
299
|
+
* inside the provider. Mid-stream codes (STREAM_IDLE_TIMEOUT,
|
|
300
|
+
* STREAM_INCOMPLETE) are left out, because a stream that already delivered
|
|
301
|
+
* text must not be restarted on another provider.
|
|
302
|
+
*/
|
|
303
|
+
const RETRYABLE_PROVIDER_ERROR_CODES = new Set([
|
|
304
|
+
'NETWORK_ERROR',
|
|
305
|
+
'REQUEST_TIMEOUT',
|
|
306
|
+
'REQUEST_HARD_TIMEOUT',
|
|
307
|
+
'TIMEOUT',
|
|
308
|
+
'MAX_RETRIES_REACHED',
|
|
309
|
+
]);
|
|
255
310
|
/**
|
|
256
311
|
* Detect content-policy refusals across providers so the fallback chain
|
|
257
312
|
* can route them to a more permissive model (typically uncensored
|
|
@@ -325,19 +380,29 @@ export function isContentPolicyRefusal(error) {
|
|
|
325
380
|
export function isRetryableError(error) {
|
|
326
381
|
if (!(error instanceof Error))
|
|
327
382
|
return false;
|
|
383
|
+
// A primary that cannot initialize (rejected key, unreachable endpoint)
|
|
384
|
+
// is unusable for this call whatever the cause; the next provider may not be.
|
|
385
|
+
if (error.name === 'ProviderInitializationError')
|
|
386
|
+
return true;
|
|
328
387
|
// Typed provider errors carry the HTTP status as a numeric field. Prefer that
|
|
329
388
|
// over message-grepping, since providers often substitute the body description
|
|
330
389
|
// (e.g. "This request requires more credits...") for the status code.
|
|
331
390
|
const status = error.httpStatus;
|
|
332
391
|
if (typeof status === 'number' && RETRYABLE_HTTP_STATUSES.has(status))
|
|
333
392
|
return true;
|
|
393
|
+
// Typed provider errors name request-level network failures and timeouts
|
|
394
|
+
// by code; their messages vary by provider (OpenAIProvider rewrites an
|
|
395
|
+
// exhausted network failure as "Network error: unable to reach ...").
|
|
396
|
+
const code = error.code;
|
|
397
|
+
if (typeof code === 'string' && RETRYABLE_PROVIDER_ERROR_CODES.has(code))
|
|
398
|
+
return true;
|
|
334
399
|
const msg = error.message;
|
|
335
400
|
// HTTP status codes that warrant a provider switch (string-grepped fallback
|
|
336
401
|
// when the error type is not a typed provider error).
|
|
337
402
|
if (/\b(402|429|500|502|503|504|401|403)\b/.test(msg))
|
|
338
403
|
return true;
|
|
339
404
|
// Network-level failures
|
|
340
|
-
if (/fetch failed|ECONNREFUSED|ETIMEDOUT|ENOTFOUND/i.test(msg))
|
|
405
|
+
if (/fetch failed|ECONNREFUSED|ECONNRESET|ETIMEDOUT|ENOTFOUND|EAI_AGAIN|socket hang up|network error/i.test(msg))
|
|
341
406
|
return true;
|
|
342
407
|
// Provider-specific phrases that always imply a retryable condition.
|
|
343
408
|
// `credit balance` covers Anthropic's billing message ("Your credit
|
|
@@ -597,6 +662,15 @@ export async function generateText(opts) {
|
|
|
597
662
|
let metricUsage;
|
|
598
663
|
let metricProviderId;
|
|
599
664
|
let metricModelId;
|
|
665
|
+
// What this attempt did that a failover must not repeat. Written inside
|
|
666
|
+
// the span callback and read by the fallback walk below, so it lives on an
|
|
667
|
+
// object rather than in narrowed locals.
|
|
668
|
+
const toolProgress = { shimRanTool: false };
|
|
669
|
+
// The tool run this call's tool execution contexts belong to, and the
|
|
670
|
+
// step it starts at. A fallback leg that continues the call keeps both,
|
|
671
|
+
// so tools see one session across providers and steps keep counting.
|
|
672
|
+
const helperToolRunId = opts._continuation?.helperToolRunId ?? randomUUID();
|
|
673
|
+
const stepOffset = opts._continuation?.stepOffset ?? 0;
|
|
600
674
|
try {
|
|
601
675
|
const successResult = await withAgentOSSpan('agentos.api.generate_text', async (span) => {
|
|
602
676
|
let { providerId, modelId } = resolveModelOption(opts, 'text');
|
|
@@ -668,7 +742,6 @@ export async function generateText(opts) {
|
|
|
668
742
|
const toolMap = new Map();
|
|
669
743
|
for (const t of tools)
|
|
670
744
|
toolMap.set(t.name, t);
|
|
671
|
-
const helperToolRunId = randomUUID();
|
|
672
745
|
// Build messages
|
|
673
746
|
const messages = [];
|
|
674
747
|
// --- Chain-of-thought injection ---
|
|
@@ -705,15 +778,27 @@ export async function generateText(opts) {
|
|
|
705
778
|
}
|
|
706
779
|
messages.push({ role: 'system', content: parts });
|
|
707
780
|
}
|
|
781
|
+
// Everything above is built from opts (system prompt, chain-of-thought
|
|
782
|
+
// instruction); a failover continuation rebuilds it, so it is left out
|
|
783
|
+
// of the conversation a continuation carries.
|
|
784
|
+
const generatedSystemCount = messages.length;
|
|
708
785
|
if (opts.messages) {
|
|
786
|
+
// Session history replays through here, so keep the tool pairing
|
|
787
|
+
// and thinking fields (see toProviderReplayMessage).
|
|
709
788
|
for (const m of opts.messages)
|
|
710
|
-
messages.push(
|
|
789
|
+
messages.push(toProviderReplayMessage(m));
|
|
711
790
|
}
|
|
712
791
|
// Transcript delta capture (sessions, spec 2026-07-20 §1b): everything
|
|
713
792
|
// from here on is THIS call's contribution. Callers that carry their
|
|
714
793
|
// new user turn inside opts.messages mark how many trailing caller
|
|
715
794
|
// messages belong to the delta.
|
|
716
|
-
|
|
795
|
+
let transcriptDeltaStart = messages.length - (opts._transcriptIncludeTrailingCallerMessages ?? 0);
|
|
796
|
+
// Caller history (its system messages included) that precedes this
|
|
797
|
+
// call's contribution.
|
|
798
|
+
const callerHistoryCount = Math.max(0, transcriptDeltaStart - generatedSystemCount);
|
|
799
|
+
// The plan's system message, when planning adds one; a continuation
|
|
800
|
+
// leaves it out (the fallback plans again if planning is on).
|
|
801
|
+
let planMessage;
|
|
717
802
|
if (opts.prompt)
|
|
718
803
|
messages.push({ role: 'user', content: opts.prompt });
|
|
719
804
|
span?.setAttribute('agentos.api.tool_count', tools.length);
|
|
@@ -762,7 +847,12 @@ export async function generateText(opts) {
|
|
|
762
847
|
const planPrompt = formatPlanForPrompt(resolvedPlan);
|
|
763
848
|
const firstNonSystem = messages.findIndex((m) => m.role !== 'system');
|
|
764
849
|
const insertIdx = firstNonSystem === -1 ? messages.length : firstNonSystem;
|
|
765
|
-
|
|
850
|
+
planMessage = { role: 'system', content: planPrompt };
|
|
851
|
+
messages.splice(insertIdx, 0, planMessage);
|
|
852
|
+
// The plan lands ahead of this call's transcript delta; keep the
|
|
853
|
+
// delta starting at the same message.
|
|
854
|
+
if (insertIdx <= transcriptDeltaStart)
|
|
855
|
+
transcriptDeltaStart += 1;
|
|
766
856
|
span?.setAttribute('agentos.api.plan_steps', resolvedPlan.steps.length);
|
|
767
857
|
}
|
|
768
858
|
}
|
|
@@ -776,10 +866,12 @@ export async function generateText(opts) {
|
|
|
776
866
|
const runShim = async () => {
|
|
777
867
|
const loopResult = await runEmulatedToolLoop({
|
|
778
868
|
tools: Array.from(toolMap.values()),
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
869
|
+
onToolExecute: () => {
|
|
870
|
+
toolProgress.shimRanTool = true;
|
|
871
|
+
},
|
|
872
|
+
// Native tool turns (session history, a failover continuation)
|
|
873
|
+
// become the shim's own <tool_call> / <tool_response> text.
|
|
874
|
+
messages: toShimMessages(messages),
|
|
783
875
|
maxRoundtrips: shimMaxRoundtrips,
|
|
784
876
|
callModel: async (msgs) => {
|
|
785
877
|
const r = await provider.generateCompletion(resolved.modelId, msgs, {
|
|
@@ -917,6 +1009,9 @@ export async function generateText(opts) {
|
|
|
917
1009
|
let lastCacheDiagnostics;
|
|
918
1010
|
try {
|
|
919
1011
|
for (let step = 0; step < maxSteps; step++) {
|
|
1012
|
+
// The step's index in the whole call: a fallback leg that continues
|
|
1013
|
+
// after completed tool rounds numbers on from them.
|
|
1014
|
+
const runStep = stepOffset + step;
|
|
920
1015
|
// --- onBeforeGeneration hook ---
|
|
921
1016
|
let effectiveMessages = messages;
|
|
922
1017
|
if (opts.onBeforeGeneration) {
|
|
@@ -927,8 +1022,8 @@ export async function generateText(opts) {
|
|
|
927
1022
|
tools: Array.from(toolMap.values()),
|
|
928
1023
|
model: resolved.modelId,
|
|
929
1024
|
provider: resolved.providerId,
|
|
930
|
-
step,
|
|
931
|
-
prompt: opts.prompt,
|
|
1025
|
+
step: runStep,
|
|
1026
|
+
prompt: opts.prompt ?? opts._continuation?.prompt,
|
|
932
1027
|
};
|
|
933
1028
|
const modified = await opts.onBeforeGeneration(hookCtx);
|
|
934
1029
|
if (modified) {
|
|
@@ -942,7 +1037,7 @@ export async function generateText(opts) {
|
|
|
942
1037
|
const response = await withAgentOSSpan('agentos.api.generate_text.step', async (stepSpan) => {
|
|
943
1038
|
stepSpan?.setAttribute('llm.provider', resolved.providerId);
|
|
944
1039
|
stepSpan?.setAttribute('llm.model', resolved.modelId);
|
|
945
|
-
stepSpan?.setAttribute('agentos.api.step',
|
|
1040
|
+
stepSpan?.setAttribute('agentos.api.step', runStep + 1);
|
|
946
1041
|
stepSpan?.setAttribute('agentos.api.tool_count', tools.length);
|
|
947
1042
|
const stepResponse = await provider.generateCompletion(resolved.modelId, effectiveMessages, {
|
|
948
1043
|
tools: toolSchemas,
|
|
@@ -1069,7 +1164,7 @@ export async function generateText(opts) {
|
|
|
1069
1164
|
let textContent = typeof content === 'string' ? content : (content?.text ?? '');
|
|
1070
1165
|
let toolCallsInChoice = resolveDynamicToolCalls(choice.message?.tool_calls, {
|
|
1071
1166
|
text: textContent,
|
|
1072
|
-
step,
|
|
1167
|
+
step: runStep,
|
|
1073
1168
|
toolsAvailable: tools.length > 0,
|
|
1074
1169
|
});
|
|
1075
1170
|
// --- onAfterGeneration hook ---
|
|
@@ -1091,7 +1186,7 @@ export async function generateText(opts) {
|
|
|
1091
1186
|
text: textContent,
|
|
1092
1187
|
toolCalls: toolCallRecords,
|
|
1093
1188
|
usage: stepUsage,
|
|
1094
|
-
step,
|
|
1189
|
+
step: runStep,
|
|
1095
1190
|
...(response.cacheDiagnostics !== undefined
|
|
1096
1191
|
? { cacheDiagnostics: response.cacheDiagnostics }
|
|
1097
1192
|
: {}),
|
|
@@ -1139,6 +1234,9 @@ export async function generateText(opts) {
|
|
|
1139
1234
|
...((choice.message?.thinking) !== undefined
|
|
1140
1235
|
? { thinking: choice.message.thinking }
|
|
1141
1236
|
: {}),
|
|
1237
|
+
...(choice.message?.thinkingBlocks?.length
|
|
1238
|
+
? { thinkingBlocks: choice.message.thinkingBlocks }
|
|
1239
|
+
: {}),
|
|
1142
1240
|
});
|
|
1143
1241
|
return {
|
|
1144
1242
|
transcriptDelta: messages.slice(transcriptDeltaStart),
|
|
@@ -1208,7 +1306,7 @@ export async function generateText(opts) {
|
|
|
1208
1306
|
name: fnName,
|
|
1209
1307
|
args: parsedArgs,
|
|
1210
1308
|
id: tcId || '',
|
|
1211
|
-
step,
|
|
1309
|
+
step: runStep,
|
|
1212
1310
|
};
|
|
1213
1311
|
const hookResult = await opts.onBeforeToolExecution(hookInfo);
|
|
1214
1312
|
if (hookResult === null) {
|
|
@@ -1229,7 +1327,7 @@ export async function generateText(opts) {
|
|
|
1229
1327
|
}
|
|
1230
1328
|
if (tool) {
|
|
1231
1329
|
try {
|
|
1232
|
-
const result = await tool.execute(parsedArgs, buildHelperToolExecutionContext('generateText', helperToolRunId,
|
|
1330
|
+
const result = await tool.execute(parsedArgs, buildHelperToolExecutionContext('generateText', helperToolRunId, runStep, tcId || undefined));
|
|
1233
1331
|
record.result = result.output;
|
|
1234
1332
|
record.error = result.success ? undefined : result.error;
|
|
1235
1333
|
messages.push({
|
|
@@ -1257,6 +1355,12 @@ export async function generateText(opts) {
|
|
|
1257
1355
|
}
|
|
1258
1356
|
allToolCalls.push(record);
|
|
1259
1357
|
}
|
|
1358
|
+
toolProgress.completedToolRounds = {
|
|
1359
|
+
messages: messages.slice(generatedSystemCount).filter((m) => m !== planMessage),
|
|
1360
|
+
callerHistoryCount,
|
|
1361
|
+
toolCalls: [...allToolCalls],
|
|
1362
|
+
steps: step + 1,
|
|
1363
|
+
};
|
|
1260
1364
|
continue;
|
|
1261
1365
|
}
|
|
1262
1366
|
metricUsage = totalUsage;
|
|
@@ -1285,6 +1389,9 @@ export async function generateText(opts) {
|
|
|
1285
1389
|
...((choice.message?.thinking) !== undefined
|
|
1286
1390
|
? { thinking: choice.message.thinking }
|
|
1287
1391
|
: {}),
|
|
1392
|
+
...(choice.message?.thinkingBlocks?.length
|
|
1393
|
+
? { thinkingBlocks: choice.message.thinkingBlocks }
|
|
1394
|
+
: {}),
|
|
1288
1395
|
});
|
|
1289
1396
|
return {
|
|
1290
1397
|
transcriptDelta: messages.slice(transcriptDeltaStart),
|
|
@@ -1390,8 +1497,11 @@ export async function generateText(opts) {
|
|
|
1390
1497
|
const effectiveFallbacks = opts.fallbackProviders === undefined
|
|
1391
1498
|
? buildPolicyAwareFallbackChain(opts.policyTier, metricProviderId)
|
|
1392
1499
|
: opts.fallbackProviders;
|
|
1500
|
+
// A call whose prompt-shim tools already ran cannot be continued, and a
|
|
1501
|
+
// restart would run them again; it surfaces the error instead.
|
|
1393
1502
|
if (effectiveFallbacks.length &&
|
|
1394
|
-
isRetryableError(error)
|
|
1503
|
+
isRetryableError(error) &&
|
|
1504
|
+
!toolProgress.shimRanTool) {
|
|
1395
1505
|
let lastError = error;
|
|
1396
1506
|
let attempt = 0;
|
|
1397
1507
|
for (const fb of effectiveFallbacks) {
|
|
@@ -1482,6 +1592,33 @@ export async function generateText(opts) {
|
|
|
1482
1592
|
// end-to-end. The final entry passes [] -> explicit opt-out -> throw.
|
|
1483
1593
|
fallbackProviders: effectiveFallbacks.slice(attempt),
|
|
1484
1594
|
onFallback: undefined,
|
|
1595
|
+
// Continue after the tool rounds this attempt completed: the leg
|
|
1596
|
+
// receives the conversation so far (prompt included, so no new
|
|
1597
|
+
// prompt), counts all of it as this call's transcript delta, and
|
|
1598
|
+
// keeps the steps that remain.
|
|
1599
|
+
_continuation: {
|
|
1600
|
+
helperToolRunId,
|
|
1601
|
+
stepOffset: stepOffset + (toolProgress.completedToolRounds?.steps ?? 0),
|
|
1602
|
+
prompt: opts.prompt ?? opts._continuation?.prompt,
|
|
1603
|
+
},
|
|
1604
|
+
...(toolProgress.completedToolRounds
|
|
1605
|
+
? {
|
|
1606
|
+
messages: toolProgress.completedToolRounds.messages,
|
|
1607
|
+
prompt: undefined,
|
|
1608
|
+
_transcriptIncludeTrailingCallerMessages: toolProgress.completedToolRounds.messages.length - toolProgress.completedToolRounds.callerHistoryCount,
|
|
1609
|
+
maxSteps: Math.max(1, (opts.maxSteps ?? 1) - toolProgress.completedToolRounds.steps),
|
|
1610
|
+
// Claude's budgeted thinking requires the tool turn being
|
|
1611
|
+
// answered to open with its signed thinking, and a turn
|
|
1612
|
+
// another model ran has none, so the continuation runs
|
|
1613
|
+
// without a thinking budget. Adaptive thinking turns itself
|
|
1614
|
+
// off for such a turn.
|
|
1615
|
+
...(opts.thinking !== undefined &&
|
|
1616
|
+
(fb.provider === 'anthropic' || /claude/i.test(fb.model ?? '')) &&
|
|
1617
|
+
toolTurnLacksThinking(toolProgress.completedToolRounds.messages)
|
|
1618
|
+
? { thinking: undefined }
|
|
1619
|
+
: {}),
|
|
1620
|
+
}
|
|
1621
|
+
: {}),
|
|
1485
1622
|
});
|
|
1486
1623
|
fallbackLogger.info('provider fallback succeeded', {
|
|
1487
1624
|
event: 'fallback_succeeded',
|
|
@@ -1500,6 +1637,9 @@ export async function generateText(opts) {
|
|
|
1500
1637
|
]));
|
|
1501
1638
|
return {
|
|
1502
1639
|
...fallbackResult,
|
|
1640
|
+
...(toolProgress.completedToolRounds
|
|
1641
|
+
? { toolCalls: [...toolProgress.completedToolRounds.toolCalls, ...fallbackResult.toolCalls] }
|
|
1642
|
+
: {}),
|
|
1503
1643
|
fallback: {
|
|
1504
1644
|
fired: true,
|
|
1505
1645
|
finalProvider: fallbackResult.provider,
|
|
@@ -1511,6 +1651,10 @@ export async function generateText(opts) {
|
|
|
1511
1651
|
catch (fbError) {
|
|
1512
1652
|
lastError = fbError;
|
|
1513
1653
|
fallbackHops.push({ provider: fb.provider, model: fb.model, ok: false });
|
|
1654
|
+
// The leg ran tools before it failed. A later leg would start
|
|
1655
|
+
// from a conversation that does not show them and run them again.
|
|
1656
|
+
if (toolsRanBefore(fbError))
|
|
1657
|
+
break;
|
|
1514
1658
|
}
|
|
1515
1659
|
}
|
|
1516
1660
|
// All fallbacks exhausted: fall through to throw
|
|
@@ -1524,10 +1668,11 @@ export async function generateText(opts) {
|
|
|
1524
1668
|
errorMessage: lastErr.message.slice(0, 200),
|
|
1525
1669
|
});
|
|
1526
1670
|
metricStatus = 'error';
|
|
1527
|
-
throw lastError;
|
|
1671
|
+
throw toolProgress.shimRanTool || toolProgress.completedToolRounds ? markToolsRan(lastError) : lastError;
|
|
1528
1672
|
}
|
|
1529
1673
|
metricStatus = 'error';
|
|
1530
|
-
|
|
1674
|
+
// Marked so a walker that called this one as a fallback leg stops too.
|
|
1675
|
+
throw toolProgress.shimRanTool || toolProgress.completedToolRounds ? markToolsRan(error) : error;
|
|
1531
1676
|
}
|
|
1532
1677
|
finally {
|
|
1533
1678
|
try {
|