@openai/agents-core 0.8.5 → 0.9.1
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/agentToolRunConfig.js +3 -0
- package/dist/agentToolRunConfig.js.map +1 -1
- package/dist/agentToolRunConfig.mjs +3 -0
- package/dist/agentToolRunConfig.mjs.map +1 -1
- package/dist/errors.d.ts +10 -0
- package/dist/errors.js +15 -1
- package/dist/errors.js.map +1 -1
- package/dist/errors.mjs +13 -0
- package/dist/errors.mjs.map +1 -1
- package/dist/handoff.js +1 -1
- package/dist/handoff.js.map +1 -1
- package/dist/handoff.mjs +1 -1
- package/dist/handoff.mjs.map +1 -1
- package/dist/index.d.ts +5 -4
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3 -2
- package/dist/index.mjs.map +1 -1
- package/dist/items.d.ts +13 -0
- package/dist/items.js +15 -0
- package/dist/items.js.map +1 -1
- package/dist/items.mjs +15 -0
- package/dist/items.mjs.map +1 -1
- package/dist/memory/historyMutations.d.ts +6 -0
- package/dist/memory/historyMutations.js +32 -0
- package/dist/memory/historyMutations.js.map +1 -0
- package/dist/memory/historyMutations.mjs +29 -0
- package/dist/memory/historyMutations.mjs.map +1 -0
- package/dist/memory/memorySession.d.ts +3 -2
- package/dist/memory/memorySession.js +7 -0
- package/dist/memory/memorySession.js.map +1 -1
- package/dist/memory/memorySession.mjs +7 -0
- package/dist/memory/memorySession.mjs.map +1 -1
- package/dist/memory/session.d.ts +22 -0
- package/dist/memory/session.js +6 -0
- package/dist/memory/session.js.map +1 -1
- package/dist/memory/session.mjs +5 -0
- package/dist/memory/session.mjs.map +1 -1
- package/dist/metadata.js +2 -2
- package/dist/metadata.mjs +2 -2
- package/dist/model.d.ts +21 -0
- package/dist/run.d.ts +7 -1
- package/dist/run.js +152 -57
- package/dist/run.js.map +1 -1
- package/dist/run.mjs +153 -58
- package/dist/run.mjs.map +1 -1
- package/dist/runState.d.ts +110 -3
- package/dist/runState.js +414 -53
- package/dist/runState.js.map +1 -1
- package/dist/runState.mjs +412 -53
- package/dist/runState.mjs.map +1 -1
- package/dist/runner/errorHandlers.d.ts +13 -4
- package/dist/runner/errorHandlers.js +22 -4
- package/dist/runner/errorHandlers.js.map +1 -1
- package/dist/runner/errorHandlers.mjs +21 -4
- package/dist/runner/errorHandlers.mjs.map +1 -1
- package/dist/runner/items.js +11 -1
- package/dist/runner/items.js.map +1 -1
- package/dist/runner/items.mjs +11 -1
- package/dist/runner/items.mjs.map +1 -1
- package/dist/runner/modelPreparation.d.ts +1 -1
- package/dist/runner/modelPreparation.js +7 -7
- package/dist/runner/modelPreparation.js.map +1 -1
- package/dist/runner/modelPreparation.mjs +7 -7
- package/dist/runner/modelPreparation.mjs.map +1 -1
- package/dist/runner/runLoop.d.ts +2 -1
- package/dist/runner/runLoop.js +2 -2
- package/dist/runner/runLoop.js.map +1 -1
- package/dist/runner/runLoop.mjs +2 -2
- package/dist/runner/runLoop.mjs.map +1 -1
- package/dist/runner/sandbox.d.ts +33 -0
- package/dist/runner/sandbox.js +92 -0
- package/dist/runner/sandbox.js.map +1 -0
- package/dist/runner/sandbox.mjs +83 -0
- package/dist/runner/sandbox.mjs.map +1 -0
- package/dist/runner/sessionPersistence.js +33 -12
- package/dist/runner/sessionPersistence.js.map +1 -1
- package/dist/runner/sessionPersistence.mjs +33 -12
- package/dist/runner/sessionPersistence.mjs.map +1 -1
- package/dist/runner/streamReconciliation.d.ts +14 -0
- package/dist/runner/streamReconciliation.js +80 -0
- package/dist/runner/streamReconciliation.js.map +1 -0
- package/dist/runner/streamReconciliation.mjs +72 -0
- package/dist/runner/streamReconciliation.mjs.map +1 -0
- package/dist/runner/toolExecution.js +25 -13
- package/dist/runner/toolExecution.js.map +1 -1
- package/dist/runner/toolExecution.mjs +25 -13
- package/dist/runner/toolExecution.mjs.map +1 -1
- package/dist/runner/toolUseTracker.d.ts +3 -1
- package/dist/runner/toolUseTracker.js +2 -2
- package/dist/runner/toolUseTracker.js.map +1 -1
- package/dist/runner/toolUseTracker.mjs +2 -2
- package/dist/runner/toolUseTracker.mjs.map +1 -1
- package/dist/runner/tracing.js +1 -0
- package/dist/runner/tracing.js.map +1 -1
- package/dist/runner/tracing.mjs +1 -0
- package/dist/runner/tracing.mjs.map +1 -1
- package/dist/runner/turnPreparation.d.ts +2 -4
- package/dist/runner/turnPreparation.js +7 -3
- package/dist/runner/turnPreparation.js.map +1 -1
- package/dist/runner/turnPreparation.mjs +7 -3
- package/dist/runner/turnPreparation.mjs.map +1 -1
- package/dist/runner/turnResolution.js +158 -31
- package/dist/runner/turnResolution.js.map +1 -1
- package/dist/runner/turnResolution.mjs +160 -33
- package/dist/runner/turnResolution.mjs.map +1 -1
- package/dist/runner/types.d.ts +8 -8
- package/dist/sandbox/agent.d.ts +24 -0
- package/dist/sandbox/agent.js +68 -0
- package/dist/sandbox/agent.js.map +1 -0
- package/dist/sandbox/agent.mjs +64 -0
- package/dist/sandbox/agent.mjs.map +1 -0
- package/dist/sandbox/brand.d.ts +1 -0
- package/dist/sandbox/brand.js +5 -0
- package/dist/sandbox/brand.js.map +1 -0
- package/dist/sandbox/brand.mjs +2 -0
- package/dist/sandbox/brand.mjs.map +1 -0
- package/dist/sandbox/capabilities/base.d.ts +25 -0
- package/dist/sandbox/capabilities/base.js +89 -0
- package/dist/sandbox/capabilities/base.js.map +1 -0
- package/dist/sandbox/capabilities/base.mjs +84 -0
- package/dist/sandbox/capabilities/base.mjs.map +1 -0
- package/dist/sandbox/capabilities/compaction.d.ts +33 -0
- package/dist/sandbox/capabilities/compaction.js +172 -0
- package/dist/sandbox/capabilities/compaction.js.map +1 -0
- package/dist/sandbox/capabilities/compaction.mjs +164 -0
- package/dist/sandbox/capabilities/compaction.mjs.map +1 -0
- package/dist/sandbox/capabilities/filesystem.d.ts +14 -0
- package/dist/sandbox/capabilities/filesystem.js +447 -0
- package/dist/sandbox/capabilities/filesystem.js.map +1 -0
- package/dist/sandbox/capabilities/filesystem.mjs +444 -0
- package/dist/sandbox/capabilities/filesystem.mjs.map +1 -0
- package/dist/sandbox/capabilities/index.d.ts +19 -0
- package/dist/sandbox/capabilities/index.js +31 -0
- package/dist/sandbox/capabilities/index.js.map +1 -0
- package/dist/sandbox/capabilities/index.mjs +17 -0
- package/dist/sandbox/capabilities/index.mjs.map +1 -0
- package/dist/sandbox/capabilities/memory.d.ts +52 -0
- package/dist/sandbox/capabilities/memory.js +290 -0
- package/dist/sandbox/capabilities/memory.js.map +1 -0
- package/dist/sandbox/capabilities/memory.mjs +286 -0
- package/dist/sandbox/capabilities/memory.mjs.map +1 -0
- package/dist/sandbox/capabilities/shell.d.ts +15 -0
- package/dist/sandbox/capabilities/shell.js +130 -0
- package/dist/sandbox/capabilities/shell.js.map +1 -0
- package/dist/sandbox/capabilities/shell.mjs +127 -0
- package/dist/sandbox/capabilities/shell.mjs.map +1 -0
- package/dist/sandbox/capabilities/skills.d.ts +47 -0
- package/dist/sandbox/capabilities/skills.js +453 -0
- package/dist/sandbox/capabilities/skills.js.map +1 -0
- package/dist/sandbox/capabilities/skills.mjs +449 -0
- package/dist/sandbox/capabilities/skills.mjs.map +1 -0
- package/dist/sandbox/capabilities/transport.d.ts +3 -0
- package/dist/sandbox/capabilities/transport.js +33 -0
- package/dist/sandbox/capabilities/transport.js.map +1 -0
- package/dist/sandbox/capabilities/transport.mjs +28 -0
- package/dist/sandbox/capabilities/transport.mjs.map +1 -0
- package/dist/sandbox/client.d.ts +53 -0
- package/dist/sandbox/client.js +34 -0
- package/dist/sandbox/client.js.map +1 -0
- package/dist/sandbox/client.mjs +31 -0
- package/dist/sandbox/client.mjs.map +1 -0
- package/dist/sandbox/entries/factories.d.ts +17 -0
- package/dist/sandbox/entries/factories.js +112 -0
- package/dist/sandbox/entries/factories.js.map +1 -0
- package/dist/sandbox/entries/factories.mjs +94 -0
- package/dist/sandbox/entries/factories.mjs.map +1 -0
- package/dist/sandbox/entries/guards.d.ts +5 -0
- package/dist/sandbox/entries/guards.js +19 -0
- package/dist/sandbox/entries/guards.js.map +1 -0
- package/dist/sandbox/entries/guards.mjs +13 -0
- package/dist/sandbox/entries/guards.mjs.map +1 -0
- package/dist/sandbox/entries/index.d.ts +3 -0
- package/dist/sandbox/entries/index.js +26 -0
- package/dist/sandbox/entries/index.js.map +1 -0
- package/dist/sandbox/entries/index.mjs +3 -0
- package/dist/sandbox/entries/index.mjs.map +1 -0
- package/dist/sandbox/entries/types.d.ts +177 -0
- package/dist/sandbox/entries/types.js +3 -0
- package/dist/sandbox/entries/types.js.map +1 -0
- package/dist/sandbox/entries/types.mjs +2 -0
- package/dist/sandbox/entries/types.mjs.map +1 -0
- package/dist/sandbox/errors.d.ts +151 -0
- package/dist/sandbox/errors.js +303 -0
- package/dist/sandbox/errors.js.map +1 -0
- package/dist/sandbox/errors.mjs +251 -0
- package/dist/sandbox/errors.mjs.map +1 -0
- package/dist/sandbox/events.d.ts +51 -0
- package/dist/sandbox/events.js +104 -0
- package/dist/sandbox/events.js.map +1 -0
- package/dist/sandbox/events.mjs +95 -0
- package/dist/sandbox/events.mjs.map +1 -0
- package/dist/sandbox/index.d.ts +14 -0
- package/dist/sandbox/index.js +31 -0
- package/dist/sandbox/index.js.map +1 -0
- package/dist/sandbox/index.mjs +15 -0
- package/dist/sandbox/index.mjs.map +1 -0
- package/dist/sandbox/internal.d.ts +7 -0
- package/dist/sandbox/internal.js +46 -0
- package/dist/sandbox/internal.js.map +1 -0
- package/dist/sandbox/internal.mjs +8 -0
- package/dist/sandbox/internal.mjs.map +1 -0
- package/dist/sandbox/local.d.ts +3 -0
- package/dist/sandbox/local.js +20 -0
- package/dist/sandbox/local.js.map +1 -0
- package/dist/sandbox/local.mjs +4 -0
- package/dist/sandbox/local.mjs.map +1 -0
- package/dist/sandbox/localSkills.d.ts +13 -0
- package/dist/sandbox/localSkills.js +62 -0
- package/dist/sandbox/localSkills.js.map +1 -0
- package/dist/sandbox/localSkills.mjs +59 -0
- package/dist/sandbox/localSkills.mjs.map +1 -0
- package/dist/sandbox/manifest.d.ts +86 -0
- package/dist/sandbox/manifest.js +553 -0
- package/dist/sandbox/manifest.js.map +1 -0
- package/dist/sandbox/manifest.mjs +545 -0
- package/dist/sandbox/manifest.mjs.map +1 -0
- package/dist/sandbox/memory/generation.d.ts +56 -0
- package/dist/sandbox/memory/generation.js +426 -0
- package/dist/sandbox/memory/generation.js.map +1 -0
- package/dist/sandbox/memory/generation.mjs +385 -0
- package/dist/sandbox/memory/generation.mjs.map +1 -0
- package/dist/sandbox/memory/prompts.d.ts +16 -0
- package/dist/sandbox/memory/prompts.js +1685 -0
- package/dist/sandbox/memory/prompts.js.map +1 -0
- package/dist/sandbox/memory/prompts.mjs +1679 -0
- package/dist/sandbox/memory/prompts.mjs.map +1 -0
- package/dist/sandbox/memory/rollouts.d.ts +33 -0
- package/dist/sandbox/memory/rollouts.js +228 -0
- package/dist/sandbox/memory/rollouts.js.map +1 -0
- package/dist/sandbox/memory/rollouts.mjs +221 -0
- package/dist/sandbox/memory/rollouts.mjs.map +1 -0
- package/dist/sandbox/memory/storage.d.ts +70 -0
- package/dist/sandbox/memory/storage.js +543 -0
- package/dist/sandbox/memory/storage.js.map +1 -0
- package/dist/sandbox/memory/storage.mjs +537 -0
- package/dist/sandbox/memory/storage.mjs.map +1 -0
- package/dist/sandbox/pathGrants.d.ts +11 -0
- package/dist/sandbox/pathGrants.js +28 -0
- package/dist/sandbox/pathGrants.js.map +1 -0
- package/dist/sandbox/pathGrants.mjs +25 -0
- package/dist/sandbox/pathGrants.mjs.map +1 -0
- package/dist/sandbox/permissions.d.ts +29 -0
- package/dist/sandbox/permissions.js +140 -0
- package/dist/sandbox/permissions.js.map +1 -0
- package/dist/sandbox/permissions.mjs +134 -0
- package/dist/sandbox/permissions.mjs.map +1 -0
- package/dist/sandbox/runtime/agentKeys.d.ts +7 -0
- package/dist/sandbox/runtime/agentKeys.js +76 -0
- package/dist/sandbox/runtime/agentKeys.js.map +1 -0
- package/dist/sandbox/runtime/agentKeys.mjs +69 -0
- package/dist/sandbox/runtime/agentKeys.mjs.map +1 -0
- package/dist/sandbox/runtime/agentPreparation.d.ts +20 -0
- package/dist/sandbox/runtime/agentPreparation.js +178 -0
- package/dist/sandbox/runtime/agentPreparation.js.map +1 -0
- package/dist/sandbox/runtime/agentPreparation.mjs +172 -0
- package/dist/sandbox/runtime/agentPreparation.mjs.map +1 -0
- package/dist/sandbox/runtime/index.d.ts +5 -0
- package/dist/sandbox/runtime/index.js +22 -0
- package/dist/sandbox/runtime/index.js.map +1 -0
- package/dist/sandbox/runtime/index.mjs +6 -0
- package/dist/sandbox/runtime/index.mjs.map +1 -0
- package/dist/sandbox/runtime/livePreservedSessions.d.ts +25 -0
- package/dist/sandbox/runtime/livePreservedSessions.js +58 -0
- package/dist/sandbox/runtime/livePreservedSessions.js.map +1 -0
- package/dist/sandbox/runtime/livePreservedSessions.mjs +51 -0
- package/dist/sandbox/runtime/livePreservedSessions.mjs.map +1 -0
- package/dist/sandbox/runtime/manager.d.ts +68 -0
- package/dist/sandbox/runtime/manager.js +704 -0
- package/dist/sandbox/runtime/manager.js.map +1 -0
- package/dist/sandbox/runtime/manager.mjs +697 -0
- package/dist/sandbox/runtime/manager.mjs.map +1 -0
- package/dist/sandbox/runtime/prompts.d.ts +6 -0
- package/dist/sandbox/runtime/prompts.js +108 -0
- package/dist/sandbox/runtime/prompts.js.map +1 -0
- package/dist/sandbox/runtime/prompts.mjs +101 -0
- package/dist/sandbox/runtime/prompts.mjs.map +1 -0
- package/dist/sandbox/runtime/providedSessionManifest.d.ts +3 -0
- package/dist/sandbox/runtime/providedSessionManifest.js +175 -0
- package/dist/sandbox/runtime/providedSessionManifest.js.map +1 -0
- package/dist/sandbox/runtime/providedSessionManifest.mjs +172 -0
- package/dist/sandbox/runtime/providedSessionManifest.mjs.map +1 -0
- package/dist/sandbox/runtime/runAsManifest.d.ts +4 -0
- package/dist/sandbox/runtime/runAsManifest.js +40 -0
- package/dist/sandbox/runtime/runAsManifest.js.map +1 -0
- package/dist/sandbox/runtime/runAsManifest.mjs +36 -0
- package/dist/sandbox/runtime/runAsManifest.mjs.map +1 -0
- package/dist/sandbox/runtime/sessionLifecycle.d.ts +6 -0
- package/dist/sandbox/runtime/sessionLifecycle.js +222 -0
- package/dist/sandbox/runtime/sessionLifecycle.js.map +1 -0
- package/dist/sandbox/runtime/sessionLifecycle.mjs +215 -0
- package/dist/sandbox/runtime/sessionLifecycle.mjs.map +1 -0
- package/dist/sandbox/runtime/sessionSerialization.d.ts +12 -0
- package/dist/sandbox/runtime/sessionSerialization.js +74 -0
- package/dist/sandbox/runtime/sessionSerialization.js.map +1 -0
- package/dist/sandbox/runtime/sessionSerialization.mjs +71 -0
- package/dist/sandbox/runtime/sessionSerialization.mjs.map +1 -0
- package/dist/sandbox/runtime/sessionState.d.ts +26 -0
- package/dist/sandbox/runtime/sessionState.js +113 -0
- package/dist/sandbox/runtime/sessionState.js.map +1 -0
- package/dist/sandbox/runtime/sessionState.mjs +104 -0
- package/dist/sandbox/runtime/sessionState.mjs.map +1 -0
- package/dist/sandbox/runtime/spans.d.ts +1 -0
- package/dist/sandbox/runtime/spans.js +51 -0
- package/dist/sandbox/runtime/spans.js.map +1 -0
- package/dist/sandbox/runtime/spans.mjs +48 -0
- package/dist/sandbox/runtime/spans.mjs.map +1 -0
- package/dist/sandbox/runtime/toolRehydration.d.ts +34 -0
- package/dist/sandbox/runtime/toolRehydration.js +207 -0
- package/dist/sandbox/runtime/toolRehydration.js.map +1 -0
- package/dist/sandbox/runtime/toolRehydration.mjs +200 -0
- package/dist/sandbox/runtime/toolRehydration.mjs.map +1 -0
- package/dist/sandbox/sandboxes/docker.d.ts +75 -0
- package/dist/sandbox/sandboxes/docker.js +2015 -0
- package/dist/sandbox/sandboxes/docker.js.map +1 -0
- package/dist/sandbox/sandboxes/docker.mjs +2010 -0
- package/dist/sandbox/sandboxes/docker.mjs.map +1 -0
- package/dist/sandbox/sandboxes/index.d.ts +3 -0
- package/dist/sandbox/sandboxes/index.js +20 -0
- package/dist/sandbox/sandboxes/index.js.map +1 -0
- package/dist/sandbox/sandboxes/index.mjs +4 -0
- package/dist/sandbox/sandboxes/index.mjs.map +1 -0
- package/dist/sandbox/sandboxes/shared/localSnapshotPaths.d.ts +1 -0
- package/dist/sandbox/sandboxes/shared/localSnapshotPaths.js +22 -0
- package/dist/sandbox/sandboxes/shared/localSnapshotPaths.js.map +1 -0
- package/dist/sandbox/sandboxes/shared/localSnapshotPaths.mjs +19 -0
- package/dist/sandbox/sandboxes/shared/localSnapshotPaths.mjs.map +1 -0
- package/dist/sandbox/sandboxes/shared/localSnapshots.d.ts +34 -0
- package/dist/sandbox/sandboxes/shared/localSnapshots.js +525 -0
- package/dist/sandbox/sandboxes/shared/localSnapshots.js.map +1 -0
- package/dist/sandbox/sandboxes/shared/localSnapshots.mjs +508 -0
- package/dist/sandbox/sandboxes/shared/localSnapshots.mjs.map +1 -0
- package/dist/sandbox/sandboxes/shared/localWorkspace.d.ts +27 -0
- package/dist/sandbox/sandboxes/shared/localWorkspace.js +693 -0
- package/dist/sandbox/sandboxes/shared/localWorkspace.js.map +1 -0
- package/dist/sandbox/sandboxes/shared/localWorkspace.mjs +684 -0
- package/dist/sandbox/sandboxes/shared/localWorkspace.mjs.map +1 -0
- package/dist/sandbox/sandboxes/shared/manifestPersistence.d.ts +15 -0
- package/dist/sandbox/sandboxes/shared/manifestPersistence.js +191 -0
- package/dist/sandbox/sandboxes/shared/manifestPersistence.js.map +1 -0
- package/dist/sandbox/sandboxes/shared/manifestPersistence.mjs +182 -0
- package/dist/sandbox/sandboxes/shared/manifestPersistence.mjs.map +1 -0
- package/dist/sandbox/sandboxes/shared/pty.d.ts +9 -0
- package/dist/sandbox/sandboxes/shared/pty.js +151 -0
- package/dist/sandbox/sandboxes/shared/pty.js.map +1 -0
- package/dist/sandbox/sandboxes/shared/pty.mjs +148 -0
- package/dist/sandbox/sandboxes/shared/pty.mjs.map +1 -0
- package/dist/sandbox/sandboxes/shared/runProcess.d.ts +16 -0
- package/dist/sandbox/sandboxes/shared/runProcess.js +90 -0
- package/dist/sandbox/sandboxes/shared/runProcess.js.map +1 -0
- package/dist/sandbox/sandboxes/shared/runProcess.mjs +86 -0
- package/dist/sandbox/sandboxes/shared/runProcess.mjs.map +1 -0
- package/dist/sandbox/sandboxes/shared/sessionStateValues.d.ts +18 -0
- package/dist/sandbox/sandboxes/shared/sessionStateValues.js +40 -0
- package/dist/sandbox/sandboxes/shared/sessionStateValues.js.map +1 -0
- package/dist/sandbox/sandboxes/shared/sessionStateValues.mjs +35 -0
- package/dist/sandbox/sandboxes/shared/sessionStateValues.mjs.map +1 -0
- package/dist/sandbox/sandboxes/shared/shellCommand.d.ts +17 -0
- package/dist/sandbox/sandboxes/shared/shellCommand.js +38 -0
- package/dist/sandbox/sandboxes/shared/shellCommand.js.map +1 -0
- package/dist/sandbox/sandboxes/shared/shellCommand.mjs +34 -0
- package/dist/sandbox/sandboxes/shared/shellCommand.mjs.map +1 -0
- package/dist/sandbox/sandboxes/types.d.ts +11 -0
- package/dist/sandbox/sandboxes/types.js +3 -0
- package/dist/sandbox/sandboxes/types.js.map +1 -0
- package/dist/sandbox/sandboxes/types.mjs +2 -0
- package/dist/sandbox/sandboxes/types.mjs.map +1 -0
- package/dist/sandbox/sandboxes/unixLocal.d.ts +95 -0
- package/dist/sandbox/sandboxes/unixLocal.js +863 -0
- package/dist/sandbox/sandboxes/unixLocal.js.map +1 -0
- package/dist/sandbox/sandboxes/unixLocal.mjs +858 -0
- package/dist/sandbox/sandboxes/unixLocal.mjs.map +1 -0
- package/dist/sandbox/session.d.ts +123 -0
- package/dist/sandbox/session.js +58 -0
- package/dist/sandbox/session.js.map +1 -0
- package/dist/sandbox/session.mjs +50 -0
- package/dist/sandbox/session.mjs.map +1 -0
- package/dist/sandbox/shared/compare.d.ts +2 -0
- package/dist/sandbox/shared/compare.js +13 -0
- package/dist/sandbox/shared/compare.js.map +1 -0
- package/dist/sandbox/shared/compare.mjs +9 -0
- package/dist/sandbox/shared/compare.mjs.map +1 -0
- package/dist/sandbox/shared/environment.d.ts +14 -0
- package/dist/sandbox/shared/environment.js +69 -0
- package/dist/sandbox/shared/environment.js.map +1 -0
- package/dist/sandbox/shared/environment.mjs +59 -0
- package/dist/sandbox/shared/environment.mjs.map +1 -0
- package/dist/sandbox/shared/hostPath.d.ts +4 -0
- package/dist/sandbox/shared/hostPath.js +22 -0
- package/dist/sandbox/shared/hostPath.js.map +1 -0
- package/dist/sandbox/shared/hostPath.mjs +16 -0
- package/dist/sandbox/shared/hostPath.mjs.map +1 -0
- package/dist/sandbox/shared/manifestCollections.d.ts +12 -0
- package/dist/sandbox/shared/manifestCollections.js +40 -0
- package/dist/sandbox/shared/manifestCollections.js.map +1 -0
- package/dist/sandbox/shared/manifestCollections.mjs +34 -0
- package/dist/sandbox/shared/manifestCollections.mjs.map +1 -0
- package/dist/sandbox/shared/media.d.ts +6 -0
- package/dist/sandbox/shared/media.js +126 -0
- package/dist/sandbox/shared/media.js.map +1 -0
- package/dist/sandbox/shared/media.mjs +119 -0
- package/dist/sandbox/shared/media.mjs.map +1 -0
- package/dist/sandbox/shared/output.d.ts +12 -0
- package/dist/sandbox/shared/output.js +108 -0
- package/dist/sandbox/shared/output.js.map +1 -0
- package/dist/sandbox/shared/output.mjs +103 -0
- package/dist/sandbox/shared/output.mjs.map +1 -0
- package/dist/sandbox/shared/posixPath.d.ts +7 -0
- package/dist/sandbox/shared/posixPath.js +90 -0
- package/dist/sandbox/shared/posixPath.js.map +1 -0
- package/dist/sandbox/shared/posixPath.mjs +81 -0
- package/dist/sandbox/shared/posixPath.mjs.map +1 -0
- package/dist/sandbox/shared/remoteMountCommandAllowlist.d.ts +3 -0
- package/dist/sandbox/shared/remoteMountCommandAllowlist.js +33 -0
- package/dist/sandbox/shared/remoteMountCommandAllowlist.js.map +1 -0
- package/dist/sandbox/shared/remoteMountCommandAllowlist.mjs +28 -0
- package/dist/sandbox/shared/remoteMountCommandAllowlist.mjs.map +1 -0
- package/dist/sandbox/shared/shell.d.ts +1 -0
- package/dist/sandbox/shared/shell.js +7 -0
- package/dist/sandbox/shared/shell.js.map +1 -0
- package/dist/sandbox/shared/shell.mjs +4 -0
- package/dist/sandbox/shared/shell.mjs.map +1 -0
- package/dist/sandbox/shared/stableJson.d.ts +12 -0
- package/dist/sandbox/shared/stableJson.js +40 -0
- package/dist/sandbox/shared/stableJson.js.map +1 -0
- package/dist/sandbox/shared/stableJson.mjs +35 -0
- package/dist/sandbox/shared/stableJson.mjs.map +1 -0
- package/dist/sandbox/shared/typeGuards.d.ts +6 -0
- package/dist/sandbox/shared/typeGuards.js +34 -0
- package/dist/sandbox/shared/typeGuards.js.map +1 -0
- package/dist/sandbox/shared/typeGuards.mjs +26 -0
- package/dist/sandbox/shared/typeGuards.mjs.map +1 -0
- package/dist/sandbox/snapshot.d.ts +60 -0
- package/dist/sandbox/snapshot.js +45 -0
- package/dist/sandbox/snapshot.js.map +1 -0
- package/dist/sandbox/snapshot.mjs +39 -0
- package/dist/sandbox/snapshot.mjs.map +1 -0
- package/dist/sandbox/users.d.ts +11 -0
- package/dist/sandbox/users.js +31 -0
- package/dist/sandbox/users.js.map +1 -0
- package/dist/sandbox/users.mjs +26 -0
- package/dist/sandbox/users.mjs.map +1 -0
- package/dist/sandbox/workspacePaths.d.ts +20 -0
- package/dist/sandbox/workspacePaths.js +73 -0
- package/dist/sandbox/workspacePaths.js.map +1 -0
- package/dist/sandbox/workspacePaths.mjs +69 -0
- package/dist/sandbox/workspacePaths.mjs.map +1 -0
- package/dist/tool.js +1 -1
- package/dist/tool.js.map +1 -1
- package/dist/tool.mjs +1 -1
- package/dist/tool.mjs.map +1 -1
- package/dist/types/protocol.d.ts +8 -0
- package/dist/types/protocol.js +1 -0
- package/dist/types/protocol.js.map +1 -1
- package/dist/types/protocol.mjs +1 -0
- package/dist/types/protocol.mjs.map +1 -1
- package/dist/utils/messages.d.ts +6 -0
- package/dist/utils/messages.js +21 -0
- package/dist/utils/messages.js.map +1 -1
- package/dist/utils/messages.mjs +20 -0
- package/dist/utils/messages.mjs.map +1 -1
- package/dist/utils/strictToolSchema.d.ts +4 -0
- package/dist/utils/strictToolSchema.js +358 -0
- package/dist/utils/strictToolSchema.js.map +1 -0
- package/dist/utils/strictToolSchema.mjs +353 -0
- package/dist/utils/strictToolSchema.mjs.map +1 -0
- package/dist/utils/tools.d.ts +3 -1
- package/dist/utils/tools.js +18 -7
- package/dist/utils/tools.js.map +1 -1
- package/dist/utils/tools.mjs +18 -7
- package/dist/utils/tools.mjs.map +1 -1
- package/dist/utils/zodJsonSchemaCompat.js +18 -16
- package/dist/utils/zodJsonSchemaCompat.js.map +1 -1
- package/dist/utils/zodJsonSchemaCompat.mjs +18 -16
- package/dist/utils/zodJsonSchemaCompat.mjs.map +1 -1
- package/package.json +25 -1
package/dist/runState.mjs
CHANGED
|
@@ -13,11 +13,13 @@ import { getCurrentTrace } from "./tracing/index.mjs";
|
|
|
13
13
|
import logger from "./logger.mjs";
|
|
14
14
|
import { handoff } from "./handoff.mjs";
|
|
15
15
|
import * as protocol from "./types/protocol.mjs";
|
|
16
|
+
import { SANDBOX_SESSION_STATE_VERSION } from "./sandbox/session.mjs";
|
|
16
17
|
import { safeExecute } from "./utils/safeExecute.mjs";
|
|
17
18
|
import { getClientToolSearchExecutor, getToolSearchRuntimeToolKey, } from "./tool.mjs";
|
|
18
19
|
import { getFunctionToolQualifiedName, toolQualifiedName, resolveFunctionToolCallName, } from "./toolIdentity.mjs";
|
|
19
20
|
import { getToolSearchExecution, getToolSearchOutputReplacementKey, resolveToolSearchCallId, } from "./utils/toolSearch.mjs";
|
|
20
21
|
import { executeCustomClientToolSearch, getClientToolSearchHelper, } from "./runner/toolSearch.mjs";
|
|
22
|
+
import { getSerializedApplyPatchToolPlaceholder, getSerializedComputerToolPlaceholder, getSerializedFunctionToolPlaceholder, getSerializedShellToolPlaceholder, } from "./sandbox/runtime/toolRehydration.mjs";
|
|
21
23
|
/**
|
|
22
24
|
* The schema version of the serialized run state. This is used to ensure that the serialized
|
|
23
25
|
* run state is compatible with the current version of the SDK.
|
|
@@ -36,8 +38,12 @@ import { executeCustomClientToolSearch, getClientToolSearchHelper, } from "./run
|
|
|
36
38
|
* - 1.7: Adds optional approval rejection messages.
|
|
37
39
|
* - 1.8: Adds tool search item variants, batched computer actions, and GA computer tool
|
|
38
40
|
* aliasing to serialized run state payloads.
|
|
41
|
+
* - 1.9: Adds optional sandbox session persistence with a versioned session-state
|
|
42
|
+
* envelope for sandbox-agent resume.
|
|
43
|
+
* - 1.10: Adds optional stable agent identity keys so duplicate-name agent graphs can
|
|
44
|
+
* serialize and resume without ambiguous name resolution.
|
|
39
45
|
*/
|
|
40
|
-
export const CURRENT_SCHEMA_VERSION = '1.
|
|
46
|
+
export const CURRENT_SCHEMA_VERSION = '1.10';
|
|
41
47
|
const SUPPORTED_SCHEMA_VERSIONS = [
|
|
42
48
|
'1.0',
|
|
43
49
|
'1.1',
|
|
@@ -47,11 +53,14 @@ const SUPPORTED_SCHEMA_VERSIONS = [
|
|
|
47
53
|
'1.5',
|
|
48
54
|
'1.6',
|
|
49
55
|
'1.7',
|
|
56
|
+
'1.8',
|
|
57
|
+
'1.9',
|
|
50
58
|
CURRENT_SCHEMA_VERSION,
|
|
51
59
|
];
|
|
52
60
|
const $schemaVersion = z.enum(SUPPORTED_SCHEMA_VERSIONS);
|
|
53
61
|
const serializedAgentSchema = z.object({
|
|
54
62
|
name: z.string(),
|
|
63
|
+
identity: z.string().optional(),
|
|
55
64
|
});
|
|
56
65
|
const serializedSpanBase = z.object({
|
|
57
66
|
object: z.literal('trace.span'),
|
|
@@ -160,6 +169,32 @@ const serializedTraceSchema = z.object({
|
|
|
160
169
|
// and serialization opts in to include it. By default this is omitted to avoid persisting secrets.
|
|
161
170
|
tracing_api_key: z.string().optional().nullable(),
|
|
162
171
|
});
|
|
172
|
+
const sandboxSessionStateEnvelopeSchema = z.object({
|
|
173
|
+
version: z.literal(SANDBOX_SESSION_STATE_VERSION),
|
|
174
|
+
backendId: z.string(),
|
|
175
|
+
manifest: z.record(z.string(), z.any()),
|
|
176
|
+
snapshot: z.record(z.string(), z.any()).nullable().optional(),
|
|
177
|
+
snapshotFingerprint: z.string().nullable().optional(),
|
|
178
|
+
snapshotFingerprintVersion: z.string().nullable().optional(),
|
|
179
|
+
workspaceReady: z.boolean(),
|
|
180
|
+
exposedPorts: z.record(z.string(), z.any()).optional(),
|
|
181
|
+
providerState: z.record(z.string(), z.any()),
|
|
182
|
+
});
|
|
183
|
+
const sandboxSessionEntrySchema = z.object({
|
|
184
|
+
backendId: z.string(),
|
|
185
|
+
currentAgentKey: z.string(),
|
|
186
|
+
currentAgentName: z.string(),
|
|
187
|
+
sessionState: sandboxSessionStateEnvelopeSchema,
|
|
188
|
+
preservedOwnedSession: z.boolean().optional(),
|
|
189
|
+
reuseLiveSession: z.boolean().optional(),
|
|
190
|
+
});
|
|
191
|
+
const sandboxStateSchema = z.object({
|
|
192
|
+
backendId: z.string(),
|
|
193
|
+
currentAgentKey: z.string(),
|
|
194
|
+
currentAgentName: z.string(),
|
|
195
|
+
sessionState: sandboxSessionStateEnvelopeSchema,
|
|
196
|
+
sessionsByAgent: z.record(z.string(), sandboxSessionEntrySchema),
|
|
197
|
+
});
|
|
163
198
|
const serializedProcessedResponseSchema = z.object({
|
|
164
199
|
newItems: z.array(itemSchema),
|
|
165
200
|
toolsUsed: z.array(z.string()),
|
|
@@ -300,6 +335,7 @@ export const SerializedRunState = z.object({
|
|
|
300
335
|
previousResponseId: z.string().optional(),
|
|
301
336
|
reasoningItemIdPolicy: z.enum(['preserve', 'omit']).optional(),
|
|
302
337
|
trace: serializedTraceSchema.nullable(),
|
|
338
|
+
sandbox: sandboxStateSchema.optional(),
|
|
303
339
|
});
|
|
304
340
|
/**
|
|
305
341
|
* Serializable snapshot of an agent's run, including context, usage and trace.
|
|
@@ -438,10 +474,14 @@ export class RunState {
|
|
|
438
474
|
*/
|
|
439
475
|
_trace = null;
|
|
440
476
|
/**
|
|
441
|
-
* Runtime-only tool_search-loaded tools, scoped by agent
|
|
477
|
+
* Runtime-only tool_search-loaded tools, scoped by agent object and preserved across turns for
|
|
442
478
|
* the lifetime of this in-memory run.
|
|
443
479
|
*/
|
|
444
|
-
|
|
480
|
+
_toolSearchRuntimeToolsByAgent = new Map();
|
|
481
|
+
/**
|
|
482
|
+
* Persisted sandbox session metadata for sandbox-agent resume.
|
|
483
|
+
*/
|
|
484
|
+
_sandbox = undefined;
|
|
445
485
|
constructor(context, originalInput, startingAgent, maxTurns) {
|
|
446
486
|
this._context = context;
|
|
447
487
|
this._agentToolInvocation = undefined;
|
|
@@ -481,20 +521,20 @@ export class RunState {
|
|
|
481
521
|
setCurrentAgentSpan(span) {
|
|
482
522
|
this._currentAgentSpan = span;
|
|
483
523
|
}
|
|
484
|
-
getOrCreateToolSearchRuntimeToolState(
|
|
485
|
-
let state = this.
|
|
524
|
+
getOrCreateToolSearchRuntimeToolState(agent) {
|
|
525
|
+
let state = this._toolSearchRuntimeToolsByAgent.get(agent);
|
|
486
526
|
if (!state) {
|
|
487
527
|
state = {
|
|
488
528
|
anonymousEntries: [],
|
|
489
529
|
keyedEntries: new Map(),
|
|
490
530
|
nextOrder: 0,
|
|
491
531
|
};
|
|
492
|
-
this.
|
|
532
|
+
this._toolSearchRuntimeToolsByAgent.set(agent, state);
|
|
493
533
|
}
|
|
494
534
|
return state;
|
|
495
535
|
}
|
|
496
536
|
recordToolSearchRuntimeTools(agent, toolSearchOutput, tools) {
|
|
497
|
-
const runtimeState = this.getOrCreateToolSearchRuntimeToolState(agent
|
|
537
|
+
const runtimeState = this.getOrCreateToolSearchRuntimeToolState(agent);
|
|
498
538
|
const entry = {
|
|
499
539
|
order: runtimeState.nextOrder++,
|
|
500
540
|
tools,
|
|
@@ -507,7 +547,7 @@ export class RunState {
|
|
|
507
547
|
runtimeState.anonymousEntries.push(entry);
|
|
508
548
|
}
|
|
509
549
|
getToolSearchRuntimeTools(agent) {
|
|
510
|
-
const runtimeState = this.
|
|
550
|
+
const runtimeState = this._toolSearchRuntimeToolsByAgent.get(agent);
|
|
511
551
|
if (!runtimeState) {
|
|
512
552
|
return [];
|
|
513
553
|
}
|
|
@@ -644,15 +684,13 @@ export class RunState {
|
|
|
644
684
|
* rehydrate in a separate process that lacks the original environment variables).
|
|
645
685
|
*/
|
|
646
686
|
toJSON(options = {}) {
|
|
647
|
-
|
|
687
|
+
const agentIdentity = buildAgentIdentityMap(this.#startingAgent);
|
|
648
688
|
const includeTracingApiKey = options.includeTracingApiKey === true;
|
|
649
689
|
const contextJson = this._context.toJSON();
|
|
650
690
|
const output = {
|
|
651
691
|
$schemaVersion: CURRENT_SCHEMA_VERSION,
|
|
652
692
|
currentTurn: this._currentTurn,
|
|
653
|
-
currentAgent:
|
|
654
|
-
name: this._currentAgent.name,
|
|
655
|
-
},
|
|
693
|
+
currentAgent: serializeAgentReference(this._currentAgent, agentIdentity.byAgent),
|
|
656
694
|
originalInput: this._originalInput,
|
|
657
695
|
modelResponses: this._modelResponses.map((response) => {
|
|
658
696
|
return {
|
|
@@ -684,7 +722,9 @@ export class RunState {
|
|
|
684
722
|
};
|
|
685
723
|
}),
|
|
686
724
|
context: contextJson,
|
|
687
|
-
toolUseTracker: this._toolUseTracker.toJSON(
|
|
725
|
+
toolUseTracker: this._toolUseTracker.toJSON({
|
|
726
|
+
agentIdentityKeys: agentIdentity.byAgent,
|
|
727
|
+
}),
|
|
688
728
|
maxTurns: this._maxTurns,
|
|
689
729
|
currentAgentSpan: this._currentAgentSpan?.toJSON(),
|
|
690
730
|
noActiveAgentRun: this._noActiveAgentRun,
|
|
@@ -692,22 +732,25 @@ export class RunState {
|
|
|
692
732
|
inputGuardrailResults: this._inputGuardrailResults,
|
|
693
733
|
outputGuardrailResults: this._outputGuardrailResults.map((r) => ({
|
|
694
734
|
...r,
|
|
695
|
-
agent: r.agent.
|
|
735
|
+
agent: serializeAgentReference(r.agent, agentIdentity.byAgent),
|
|
696
736
|
})),
|
|
697
737
|
toolInputGuardrailResults: this._toolInputGuardrailResults,
|
|
698
738
|
toolOutputGuardrailResults: this._toolOutputGuardrailResults,
|
|
699
|
-
currentStep: this._currentStep,
|
|
739
|
+
currentStep: serializeCurrentStep(this._currentStep, agentIdentity.byAgent),
|
|
700
740
|
lastModelResponse: this._lastTurnResponse,
|
|
701
|
-
generatedItems: this._generatedItems.map((item) => item.
|
|
741
|
+
generatedItems: this._generatedItems.map((item) => serializeRunItem(item, agentIdentity.byAgent)),
|
|
702
742
|
pendingAgentToolRuns: Object.fromEntries(this._pendingAgentToolRuns.entries()),
|
|
703
743
|
currentTurnPersistedItemCount: this._currentTurnPersistedItemCount,
|
|
704
|
-
lastProcessedResponse: this._lastProcessedResponse
|
|
744
|
+
lastProcessedResponse: this._lastProcessedResponse
|
|
745
|
+
? serializeProcessedResponse(this._lastProcessedResponse, agentIdentity.byAgent)
|
|
746
|
+
: undefined,
|
|
705
747
|
conversationId: this._conversationId,
|
|
706
748
|
previousResponseId: this._previousResponseId,
|
|
707
749
|
reasoningItemIdPolicy: this._reasoningItemIdPolicy,
|
|
708
750
|
trace: this._trace
|
|
709
751
|
? this._trace.toJSON({ includeTracingApiKey })
|
|
710
752
|
: null,
|
|
753
|
+
sandbox: this._sandbox,
|
|
711
754
|
};
|
|
712
755
|
// parsing the schema to ensure the output is valid for reparsing
|
|
713
756
|
const parsed = SerializedRunState.safeParse(output);
|
|
@@ -760,7 +803,9 @@ async function buildRunStateFromString(initialAgent, str, options = {}) {
|
|
|
760
803
|
return buildRunStateFromJson(initialAgent, stateJson, options);
|
|
761
804
|
}
|
|
762
805
|
function assertSchemaVersionSupportsToolSearch(schemaVersion, stateJson) {
|
|
763
|
-
if (schemaVersion === '1.8'
|
|
806
|
+
if (schemaVersion === '1.8' ||
|
|
807
|
+
schemaVersion === '1.9' ||
|
|
808
|
+
schemaVersion === CURRENT_SCHEMA_VERSION) {
|
|
764
809
|
return;
|
|
765
810
|
}
|
|
766
811
|
if (!containsSerializedToolSearchState(stateJson)) {
|
|
@@ -768,6 +813,9 @@ function assertSchemaVersionSupportsToolSearch(schemaVersion, stateJson) {
|
|
|
768
813
|
}
|
|
769
814
|
throw new UserError(`Run state schema version ${schemaVersion} does not support tool_search items. Please reserialize the run state with schema ${CURRENT_SCHEMA_VERSION}.`);
|
|
770
815
|
}
|
|
816
|
+
function schemaVersionSupportsAgentIdentity(schemaVersion) {
|
|
817
|
+
return schemaVersion === CURRENT_SCHEMA_VERSION;
|
|
818
|
+
}
|
|
771
819
|
function containsSerializedToolSearchState(stateJson) {
|
|
772
820
|
return (containsToolSearchProtocolItems(stateJson.originalInput) ||
|
|
773
821
|
containsToolSearchInModelResponses(stateJson.modelResponses) ||
|
|
@@ -871,17 +919,17 @@ function assertRuntimeToolKeysMatch(args) {
|
|
|
871
919
|
throw new UserError(`RunState cannot resume custom client tool_search call ${callId} for agent ${agent.name} because the registered execute callback returned runtime tools [${formatRuntimeToolKeys(actualRuntimeToolKeys)}] but the serialized state expects [${formatRuntimeToolKeys(expectedRuntimeToolKeys)}].`);
|
|
872
920
|
}
|
|
873
921
|
async function getConfiguredAgentTools(args) {
|
|
874
|
-
const { agent, context,
|
|
875
|
-
const existing =
|
|
922
|
+
const { agent, context, configuredToolsByAgent } = args;
|
|
923
|
+
const existing = configuredToolsByAgent.get(agent);
|
|
876
924
|
if (existing) {
|
|
877
925
|
return existing;
|
|
878
926
|
}
|
|
879
927
|
const configuredTools = (await agent.getAllTools(context));
|
|
880
|
-
|
|
928
|
+
configuredToolsByAgent.set(agent, configuredTools);
|
|
881
929
|
return configuredTools;
|
|
882
930
|
}
|
|
883
931
|
async function rehydrateToolSearchRuntimeTools(state) {
|
|
884
|
-
const
|
|
932
|
+
const configuredToolsByAgent = new Map();
|
|
885
933
|
const pendingToolSearchCalls = new Map();
|
|
886
934
|
for (const item of state._generatedItems) {
|
|
887
935
|
if (item instanceof RunToolSearchCallItem) {
|
|
@@ -889,10 +937,14 @@ async function rehydrateToolSearchRuntimeTools(state) {
|
|
|
889
937
|
continue;
|
|
890
938
|
}
|
|
891
939
|
const callId = resolveToolSearchCallId(item.rawItem);
|
|
892
|
-
|
|
940
|
+
const agent = item.agent;
|
|
941
|
+
const pendingCallsById = pendingToolSearchCalls.get(agent) ??
|
|
942
|
+
new Map();
|
|
943
|
+
pendingCallsById.set(callId, {
|
|
893
944
|
agent: item.agent,
|
|
894
945
|
toolSearchCall: item.rawItem,
|
|
895
946
|
});
|
|
947
|
+
pendingToolSearchCalls.set(agent, pendingCallsById);
|
|
896
948
|
continue;
|
|
897
949
|
}
|
|
898
950
|
if (!(item instanceof RunToolSearchOutputItem)) {
|
|
@@ -904,7 +956,7 @@ async function rehydrateToolSearchRuntimeTools(state) {
|
|
|
904
956
|
const configuredTools = await getConfiguredAgentTools({
|
|
905
957
|
agent: item.agent,
|
|
906
958
|
context: state._context,
|
|
907
|
-
|
|
959
|
+
configuredToolsByAgent,
|
|
908
960
|
});
|
|
909
961
|
const configuredToolKeys = getRuntimeToolKeys(configuredTools, {
|
|
910
962
|
allowUnsupported: true,
|
|
@@ -914,7 +966,9 @@ async function rehydrateToolSearchRuntimeTools(state) {
|
|
|
914
966
|
continue;
|
|
915
967
|
}
|
|
916
968
|
const callId = resolveToolSearchCallId(item.rawItem);
|
|
917
|
-
const pendingCall = pendingToolSearchCalls
|
|
969
|
+
const pendingCall = pendingToolSearchCalls
|
|
970
|
+
.get(item.agent)
|
|
971
|
+
?.get(callId);
|
|
918
972
|
if (!pendingCall) {
|
|
919
973
|
throw new UserError(`RunState cannot resume custom client tool_search output ${callId} for agent ${item.agent.name} because the serialized state is missing the matching tool_search call item.`);
|
|
920
974
|
}
|
|
@@ -957,7 +1011,9 @@ async function rehydrateToolSearchRuntimeTools(state) {
|
|
|
957
1011
|
}
|
|
958
1012
|
}
|
|
959
1013
|
async function buildRunStateFromJson(initialAgent, stateJson, options = {}) {
|
|
960
|
-
const agentMap =
|
|
1014
|
+
const agentMap = schemaVersionSupportsAgentIdentity(stateJson.$schemaVersion)
|
|
1015
|
+
? buildAgentIdentityMap(initialAgent).byIdentity
|
|
1016
|
+
: buildAgentMap(initialAgent);
|
|
961
1017
|
const contextOverride = options.contextOverride;
|
|
962
1018
|
const contextStrategy = options.contextStrategy ?? 'merge';
|
|
963
1019
|
//
|
|
@@ -982,10 +1038,7 @@ async function buildRunStateFromJson(initialAgent, stateJson, options = {}) {
|
|
|
982
1038
|
//
|
|
983
1039
|
// Find the current agent from the initial agent
|
|
984
1040
|
//
|
|
985
|
-
const currentAgent =
|
|
986
|
-
if (!currentAgent) {
|
|
987
|
-
throw new UserError(`Agent ${stateJson.currentAgent.name} not found`);
|
|
988
|
-
}
|
|
1041
|
+
const currentAgent = resolveSerializedAgent(stateJson.currentAgent, agentMap);
|
|
989
1042
|
const state = new RunState(context, '', initialAgent, stateJson.maxTurns);
|
|
990
1043
|
state._currentAgent = currentAgent;
|
|
991
1044
|
state._currentTurn = stateJson.currentTurn;
|
|
@@ -996,7 +1049,13 @@ async function buildRunStateFromJson(initialAgent, stateJson, options = {}) {
|
|
|
996
1049
|
// rebuild tool use tracker
|
|
997
1050
|
state._toolUseTracker = new AgentToolUseTracker();
|
|
998
1051
|
for (const [agentName, toolNames] of Object.entries(stateJson.toolUseTracker)) {
|
|
999
|
-
|
|
1052
|
+
const agent = agentMap.get(agentName);
|
|
1053
|
+
if (!agent) {
|
|
1054
|
+
throw new UserError(`Agent ${agentName} not found`);
|
|
1055
|
+
}
|
|
1056
|
+
state._toolUseTracker.addToolUse(agent, toolNames, {
|
|
1057
|
+
allowEmpty: true,
|
|
1058
|
+
});
|
|
1000
1059
|
}
|
|
1001
1060
|
state._pendingAgentToolRuns = new Map(Object.entries(stateJson.pendingAgentToolRuns ?? {}));
|
|
1002
1061
|
// rebuild current agent span
|
|
@@ -1019,7 +1078,7 @@ async function buildRunStateFromJson(initialAgent, stateJson, options = {}) {
|
|
|
1019
1078
|
stateJson.inputGuardrailResults;
|
|
1020
1079
|
state._outputGuardrailResults = stateJson.outputGuardrailResults.map((r) => ({
|
|
1021
1080
|
...r,
|
|
1022
|
-
agent:
|
|
1081
|
+
agent: resolveSerializedAgent(r.agent, agentMap),
|
|
1023
1082
|
}));
|
|
1024
1083
|
state._toolInputGuardrailResults =
|
|
1025
1084
|
stateJson.toolInputGuardrailResults;
|
|
@@ -1034,6 +1093,7 @@ async function buildRunStateFromJson(initialAgent, stateJson, options = {}) {
|
|
|
1034
1093
|
state._generatedItems = stateJson.generatedItems.map((item) => deserializeItem(item, agentMap));
|
|
1035
1094
|
state._currentTurnPersistedItemCount =
|
|
1036
1095
|
stateJson.currentTurnPersistedItemCount ?? 0;
|
|
1096
|
+
state._sandbox = stateJson.sandbox ?? undefined;
|
|
1037
1097
|
await rehydrateToolSearchRuntimeTools(state);
|
|
1038
1098
|
state._lastProcessedResponse = stateJson.lastProcessedResponse
|
|
1039
1099
|
? await deserializeProcessedResponse(agentMap, state, stateJson.lastProcessedResponse)
|
|
@@ -1041,7 +1101,7 @@ async function buildRunStateFromJson(initialAgent, stateJson, options = {}) {
|
|
|
1041
1101
|
if (stateJson.currentStep?.type === 'next_step_handoff') {
|
|
1042
1102
|
state._currentStep = {
|
|
1043
1103
|
type: 'next_step_handoff',
|
|
1044
|
-
newAgent:
|
|
1104
|
+
newAgent: resolveSerializedAgent(stateJson.currentStep.newAgent, agentMap),
|
|
1045
1105
|
};
|
|
1046
1106
|
}
|
|
1047
1107
|
else if (stateJson.currentStep?.type === 'next_step_interruption') {
|
|
@@ -1055,6 +1115,20 @@ async function buildRunStateFromJson(initialAgent, stateJson, options = {}) {
|
|
|
1055
1115
|
}
|
|
1056
1116
|
return state;
|
|
1057
1117
|
}
|
|
1118
|
+
/**
|
|
1119
|
+
* @internal
|
|
1120
|
+
*/
|
|
1121
|
+
export async function rehydrateProcessedResponseTools(initialAgent, state, executionTools) {
|
|
1122
|
+
if (!state._lastProcessedResponse) {
|
|
1123
|
+
return;
|
|
1124
|
+
}
|
|
1125
|
+
const agentIdentity = buildAgentIdentityMap(initialAgent);
|
|
1126
|
+
const serializedProcessedResponse = serializeProcessedResponse(state._lastProcessedResponse, agentIdentity.byAgent);
|
|
1127
|
+
state._lastProcessedResponse = await deserializeProcessedResponse(agentIdentity.byIdentity, state, serializedProcessedResponse, {
|
|
1128
|
+
executionTools,
|
|
1129
|
+
allowSerializedExecutionToolPlaceholder: false,
|
|
1130
|
+
});
|
|
1131
|
+
}
|
|
1058
1132
|
/**
|
|
1059
1133
|
* @internal
|
|
1060
1134
|
*/
|
|
@@ -1090,6 +1164,249 @@ export function buildAgentMap(initialAgent) {
|
|
|
1090
1164
|
}
|
|
1091
1165
|
return map;
|
|
1092
1166
|
}
|
|
1167
|
+
/**
|
|
1168
|
+
* @internal
|
|
1169
|
+
*/
|
|
1170
|
+
export function buildAgentIdentityMap(initialAgent) {
|
|
1171
|
+
const agents = collectAgentGraph(initialAgent);
|
|
1172
|
+
const groups = new Map();
|
|
1173
|
+
const literalNames = new Set();
|
|
1174
|
+
for (const entry of agents) {
|
|
1175
|
+
literalNames.add(entry.agent.name);
|
|
1176
|
+
const group = groups.get(entry.agent.name) ?? [];
|
|
1177
|
+
group.push(entry);
|
|
1178
|
+
groups.set(entry.agent.name, group);
|
|
1179
|
+
}
|
|
1180
|
+
const byIdentity = new Map();
|
|
1181
|
+
const byAgent = new Map();
|
|
1182
|
+
const usedIdentities = new Set();
|
|
1183
|
+
for (const [agentName, group] of groups) {
|
|
1184
|
+
const sortedGroup = group.length === 1
|
|
1185
|
+
? group
|
|
1186
|
+
: [...group].sort((left, right) => {
|
|
1187
|
+
if (left.agent === initialAgent) {
|
|
1188
|
+
return -1;
|
|
1189
|
+
}
|
|
1190
|
+
if (right.agent === initialAgent) {
|
|
1191
|
+
return 1;
|
|
1192
|
+
}
|
|
1193
|
+
const leftSignature = getAgentIdentitySignature(left.agent);
|
|
1194
|
+
const rightSignature = getAgentIdentitySignature(right.agent);
|
|
1195
|
+
if (leftSignature !== rightSignature) {
|
|
1196
|
+
return leftSignature < rightSignature ? -1 : 1;
|
|
1197
|
+
}
|
|
1198
|
+
return left.index - right.index;
|
|
1199
|
+
});
|
|
1200
|
+
let nextSuffix = 0;
|
|
1201
|
+
for (const { agent } of sortedGroup) {
|
|
1202
|
+
let identity;
|
|
1203
|
+
do {
|
|
1204
|
+
identity =
|
|
1205
|
+
nextSuffix === 0 ? agentName : `${agentName}#${nextSuffix + 1}`;
|
|
1206
|
+
nextSuffix += 1;
|
|
1207
|
+
} while (usedIdentities.has(identity) ||
|
|
1208
|
+
(identity !== agent.name && literalNames.has(identity)));
|
|
1209
|
+
usedIdentities.add(identity);
|
|
1210
|
+
byIdentity.set(identity, agent);
|
|
1211
|
+
byAgent.set(agent, identity);
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
return { byIdentity, byAgent };
|
|
1215
|
+
}
|
|
1216
|
+
function collectAgentGraph(initialAgent) {
|
|
1217
|
+
const agents = [];
|
|
1218
|
+
const visitedAgents = new Set();
|
|
1219
|
+
const queue = [initialAgent];
|
|
1220
|
+
while (queue.length > 0) {
|
|
1221
|
+
const currentAgent = queue.shift();
|
|
1222
|
+
if (visitedAgents.has(currentAgent)) {
|
|
1223
|
+
continue;
|
|
1224
|
+
}
|
|
1225
|
+
visitedAgents.add(currentAgent);
|
|
1226
|
+
agents.push({ agent: currentAgent, index: agents.length });
|
|
1227
|
+
for (const handoff of currentAgent.handoffs) {
|
|
1228
|
+
if (handoff instanceof Agent) {
|
|
1229
|
+
queue.push(handoff);
|
|
1230
|
+
}
|
|
1231
|
+
else if (handoff.agent) {
|
|
1232
|
+
queue.push(handoff.agent);
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
for (const tool of currentAgent.tools) {
|
|
1236
|
+
const sourceAgent = getAgentToolSourceAgent(tool);
|
|
1237
|
+
if (sourceAgent) {
|
|
1238
|
+
queue.push(sourceAgent);
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
return agents;
|
|
1243
|
+
}
|
|
1244
|
+
function getAgentIdentitySignature(agent) {
|
|
1245
|
+
const sandboxAgent = agent;
|
|
1246
|
+
const signature = {
|
|
1247
|
+
type: agent.constructor?.name,
|
|
1248
|
+
name: agent.name,
|
|
1249
|
+
handoffDescription: agent.handoffDescription,
|
|
1250
|
+
instructions: summarizeIdentityValue(agent.instructions),
|
|
1251
|
+
prompt: summarizeIdentityValue(agent.prompt),
|
|
1252
|
+
model: summarizeIdentityValue(agent.model),
|
|
1253
|
+
modelSettings: summarizeIdentityValue(agent.modelSettings),
|
|
1254
|
+
tools: agent.tools.map(summarizeToolIdentity),
|
|
1255
|
+
handoffs: agent.handoffs.map((entry) => entry instanceof Agent
|
|
1256
|
+
? { type: 'agent', name: entry.name }
|
|
1257
|
+
: {
|
|
1258
|
+
type: 'handoff',
|
|
1259
|
+
toolName: entry.toolName,
|
|
1260
|
+
agentName: entry.agentName,
|
|
1261
|
+
targetName: entry.agent?.name,
|
|
1262
|
+
}),
|
|
1263
|
+
mcpServers: agent.mcpServers.map(summarizeIdentityValue),
|
|
1264
|
+
inputGuardrails: agent.inputGuardrails.map(summarizeIdentityValue),
|
|
1265
|
+
outputGuardrails: agent.outputGuardrails.map(summarizeIdentityValue),
|
|
1266
|
+
outputType: summarizeIdentityValue(agent.outputType),
|
|
1267
|
+
toolUseBehavior: summarizeIdentityValue(agent.toolUseBehavior),
|
|
1268
|
+
resetToolChoice: agent.resetToolChoice,
|
|
1269
|
+
defaultManifest: summarizeIdentityValue(sandboxAgent.defaultManifest),
|
|
1270
|
+
baseInstructions: summarizeIdentityValue(sandboxAgent.baseInstructions),
|
|
1271
|
+
capabilities: sandboxAgent.capabilities?.map(summarizeIdentityValue),
|
|
1272
|
+
runAs: summarizeIdentityValue(sandboxAgent.runAs),
|
|
1273
|
+
};
|
|
1274
|
+
return stableStringify(signature);
|
|
1275
|
+
}
|
|
1276
|
+
function summarizeToolIdentity(tool) {
|
|
1277
|
+
return {
|
|
1278
|
+
type: tool.type,
|
|
1279
|
+
name: tool.name,
|
|
1280
|
+
namespace: tool.namespace,
|
|
1281
|
+
strict: tool.strict,
|
|
1282
|
+
parameters: summarizeIdentityValue(tool.parameters),
|
|
1283
|
+
};
|
|
1284
|
+
}
|
|
1285
|
+
function summarizeIdentityValue(value) {
|
|
1286
|
+
return normalizeForIdentity(value, new WeakSet(), 0);
|
|
1287
|
+
}
|
|
1288
|
+
function normalizeForIdentity(value, seen, depth) {
|
|
1289
|
+
if (value === null || typeof value === 'undefined') {
|
|
1290
|
+
return value;
|
|
1291
|
+
}
|
|
1292
|
+
if (typeof value === 'string' ||
|
|
1293
|
+
typeof value === 'number' ||
|
|
1294
|
+
typeof value === 'boolean') {
|
|
1295
|
+
return value;
|
|
1296
|
+
}
|
|
1297
|
+
if (typeof value === 'function') {
|
|
1298
|
+
return `[function:${value.name || 'anonymous'}]`;
|
|
1299
|
+
}
|
|
1300
|
+
if (typeof value !== 'object') {
|
|
1301
|
+
return String(value);
|
|
1302
|
+
}
|
|
1303
|
+
if (seen.has(value)) {
|
|
1304
|
+
return '[circular]';
|
|
1305
|
+
}
|
|
1306
|
+
if (depth >= 4) {
|
|
1307
|
+
return `[${value.constructor?.name ?? 'Object'}]`;
|
|
1308
|
+
}
|
|
1309
|
+
seen.add(value);
|
|
1310
|
+
if (Array.isArray(value)) {
|
|
1311
|
+
return value.map((item) => normalizeForIdentity(item, seen, depth + 1));
|
|
1312
|
+
}
|
|
1313
|
+
if (value instanceof Map) {
|
|
1314
|
+
return [...value.entries()]
|
|
1315
|
+
.map(([key, entryValue]) => [
|
|
1316
|
+
normalizeForIdentity(key, seen, depth + 1),
|
|
1317
|
+
normalizeForIdentity(entryValue, seen, depth + 1),
|
|
1318
|
+
])
|
|
1319
|
+
.sort((left, right) => stableStringify(left).localeCompare(stableStringify(right)));
|
|
1320
|
+
}
|
|
1321
|
+
if (value instanceof Set) {
|
|
1322
|
+
return [...value.values()]
|
|
1323
|
+
.map((entry) => normalizeForIdentity(entry, seen, depth + 1))
|
|
1324
|
+
.sort((left, right) => stableStringify(left).localeCompare(stableStringify(right)));
|
|
1325
|
+
}
|
|
1326
|
+
const record = value;
|
|
1327
|
+
const normalized = {
|
|
1328
|
+
constructor: value.constructor?.name,
|
|
1329
|
+
};
|
|
1330
|
+
for (const key of Object.keys(record).sort()) {
|
|
1331
|
+
normalized[key] = normalizeForIdentity(record[key], seen, depth + 1);
|
|
1332
|
+
}
|
|
1333
|
+
return normalized;
|
|
1334
|
+
}
|
|
1335
|
+
function stableStringify(value) {
|
|
1336
|
+
return JSON.stringify(value, (_key, currentValue) => {
|
|
1337
|
+
if (!currentValue ||
|
|
1338
|
+
typeof currentValue !== 'object' ||
|
|
1339
|
+
Array.isArray(currentValue)) {
|
|
1340
|
+
return currentValue;
|
|
1341
|
+
}
|
|
1342
|
+
return Object.fromEntries(Object.entries(currentValue).sort(([left], [right]) => left.localeCompare(right)));
|
|
1343
|
+
});
|
|
1344
|
+
}
|
|
1345
|
+
function serializeAgentReference(agent, agentIdentityKeys) {
|
|
1346
|
+
const identity = agentIdentityKeys.get(agent);
|
|
1347
|
+
if (!identity || identity === agent.name) {
|
|
1348
|
+
return { name: agent.name };
|
|
1349
|
+
}
|
|
1350
|
+
return { name: agent.name, identity };
|
|
1351
|
+
}
|
|
1352
|
+
function resolveSerializedAgent(serializedAgent, agentMap, fallbackAgent) {
|
|
1353
|
+
const identity = serializedAgent.identity ?? serializedAgent.name;
|
|
1354
|
+
const agent = agentMap.get(identity);
|
|
1355
|
+
if (agent) {
|
|
1356
|
+
return agent;
|
|
1357
|
+
}
|
|
1358
|
+
if (!serializedAgent.identity && fallbackAgent) {
|
|
1359
|
+
return fallbackAgent;
|
|
1360
|
+
}
|
|
1361
|
+
if (serializedAgent.identity) {
|
|
1362
|
+
throw new UserError(`Agent identity ${serializedAgent.identity} not found`);
|
|
1363
|
+
}
|
|
1364
|
+
throw new UserError(`Agent ${serializedAgent.name} not found`);
|
|
1365
|
+
}
|
|
1366
|
+
function serializeRunItem(item, agentIdentityKeys) {
|
|
1367
|
+
const serialized = item.toJSON();
|
|
1368
|
+
switch (item.type) {
|
|
1369
|
+
case 'handoff_output_item':
|
|
1370
|
+
serialized.sourceAgent = serializeAgentReference(item.sourceAgent, agentIdentityKeys);
|
|
1371
|
+
serialized.targetAgent = serializeAgentReference(item.targetAgent, agentIdentityKeys);
|
|
1372
|
+
return serialized;
|
|
1373
|
+
default:
|
|
1374
|
+
serialized.agent = serializeAgentReference(item.agent, agentIdentityKeys);
|
|
1375
|
+
return serialized;
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
function serializeCurrentStep(currentStep, agentIdentityKeys) {
|
|
1379
|
+
if (!currentStep) {
|
|
1380
|
+
return undefined;
|
|
1381
|
+
}
|
|
1382
|
+
if (currentStep.type === 'next_step_handoff') {
|
|
1383
|
+
return {
|
|
1384
|
+
...currentStep,
|
|
1385
|
+
newAgent: serializeAgentReference(currentStep.newAgent, agentIdentityKeys),
|
|
1386
|
+
};
|
|
1387
|
+
}
|
|
1388
|
+
if (currentStep.type === 'next_step_interruption') {
|
|
1389
|
+
const interruptions = Array.isArray(currentStep.data?.interruptions)
|
|
1390
|
+
? currentStep.data.interruptions.map((item) => item instanceof RunToolApprovalItem
|
|
1391
|
+
? serializeRunItem(item, agentIdentityKeys)
|
|
1392
|
+
: item)
|
|
1393
|
+
: currentStep.data?.interruptions;
|
|
1394
|
+
return {
|
|
1395
|
+
...currentStep,
|
|
1396
|
+
data: {
|
|
1397
|
+
...currentStep.data,
|
|
1398
|
+
interruptions,
|
|
1399
|
+
},
|
|
1400
|
+
};
|
|
1401
|
+
}
|
|
1402
|
+
return currentStep;
|
|
1403
|
+
}
|
|
1404
|
+
function serializeProcessedResponse(processedResponse, agentIdentityKeys) {
|
|
1405
|
+
return {
|
|
1406
|
+
...processedResponse,
|
|
1407
|
+
newItems: processedResponse.newItems.map((item) => serializeRunItem(item, agentIdentityKeys)),
|
|
1408
|
+
};
|
|
1409
|
+
}
|
|
1093
1410
|
/**
|
|
1094
1411
|
* @internal
|
|
1095
1412
|
*/
|
|
@@ -1128,23 +1445,23 @@ export function deserializeModelResponse(serializedModelResponse) {
|
|
|
1128
1445
|
export function deserializeItem(serializedItem, agentMap) {
|
|
1129
1446
|
switch (serializedItem.type) {
|
|
1130
1447
|
case 'message_output_item':
|
|
1131
|
-
return new RunMessageOutputItem(serializedItem.rawItem,
|
|
1448
|
+
return new RunMessageOutputItem(serializedItem.rawItem, resolveSerializedAgent(serializedItem.agent, agentMap));
|
|
1132
1449
|
case 'tool_search_call_item':
|
|
1133
|
-
return new RunToolSearchCallItem(serializedItem.rawItem,
|
|
1450
|
+
return new RunToolSearchCallItem(serializedItem.rawItem, resolveSerializedAgent(serializedItem.agent, agentMap));
|
|
1134
1451
|
case 'tool_search_output_item':
|
|
1135
|
-
return new RunToolSearchOutputItem(serializedItem.rawItem,
|
|
1452
|
+
return new RunToolSearchOutputItem(serializedItem.rawItem, resolveSerializedAgent(serializedItem.agent, agentMap));
|
|
1136
1453
|
case 'tool_call_item':
|
|
1137
|
-
return new RunToolCallItem(serializedItem.rawItem,
|
|
1454
|
+
return new RunToolCallItem(serializedItem.rawItem, resolveSerializedAgent(serializedItem.agent, agentMap));
|
|
1138
1455
|
case 'tool_call_output_item':
|
|
1139
|
-
return new RunToolCallOutputItem(serializedItem.rawItem,
|
|
1456
|
+
return new RunToolCallOutputItem(serializedItem.rawItem, resolveSerializedAgent(serializedItem.agent, agentMap), serializedItem.output);
|
|
1140
1457
|
case 'reasoning_item':
|
|
1141
|
-
return new RunReasoningItem(serializedItem.rawItem,
|
|
1458
|
+
return new RunReasoningItem(serializedItem.rawItem, resolveSerializedAgent(serializedItem.agent, agentMap));
|
|
1142
1459
|
case 'handoff_call_item':
|
|
1143
|
-
return new RunHandoffCallItem(serializedItem.rawItem,
|
|
1460
|
+
return new RunHandoffCallItem(serializedItem.rawItem, resolveSerializedAgent(serializedItem.agent, agentMap));
|
|
1144
1461
|
case 'handoff_output_item':
|
|
1145
|
-
return new RunHandoffOutputItem(serializedItem.rawItem,
|
|
1462
|
+
return new RunHandoffOutputItem(serializedItem.rawItem, resolveSerializedAgent(serializedItem.sourceAgent, agentMap), resolveSerializedAgent(serializedItem.targetAgent, agentMap));
|
|
1146
1463
|
case 'tool_approval_item':
|
|
1147
|
-
return new RunToolApprovalItem(serializedItem.rawItem,
|
|
1464
|
+
return new RunToolApprovalItem(serializedItem.rawItem, resolveSerializedAgent(serializedItem.agent, agentMap), serializedItem.toolName);
|
|
1148
1465
|
}
|
|
1149
1466
|
}
|
|
1150
1467
|
function deserializeInterruptionItem(serializedItem, agentMap, currentAgent) {
|
|
@@ -1154,7 +1471,7 @@ function deserializeInterruptionItem(serializedItem, agentMap, currentAgent) {
|
|
|
1154
1471
|
const parsed = itemSchema.safeParse(serializedItem);
|
|
1155
1472
|
if (parsed.success) {
|
|
1156
1473
|
if (parsed.data.type === 'tool_approval_item') {
|
|
1157
|
-
const mappedAgent =
|
|
1474
|
+
const mappedAgent = resolveSerializedAgent(parsed.data.agent, agentMap, currentAgent);
|
|
1158
1475
|
return new RunToolApprovalItem(parsed.data.rawItem, mappedAgent, parsed.data.toolName);
|
|
1159
1476
|
}
|
|
1160
1477
|
const item = deserializeItem(parsed.data, agentMap);
|
|
@@ -1178,7 +1495,15 @@ function deserializeInterruptionItem(serializedItem, agentMap, currentAgent) {
|
|
|
1178
1495
|
const agentName = value.agent && typeof value.agent.name === 'string'
|
|
1179
1496
|
? value.agent.name
|
|
1180
1497
|
: undefined;
|
|
1181
|
-
const
|
|
1498
|
+
const agentIdentity = value.agent && typeof value.agent.identity === 'string'
|
|
1499
|
+
? value.agent.identity
|
|
1500
|
+
: undefined;
|
|
1501
|
+
const mappedAgent = agentName || agentIdentity
|
|
1502
|
+
? resolveSerializedAgent({
|
|
1503
|
+
name: agentName ?? currentAgent.name,
|
|
1504
|
+
identity: agentIdentity,
|
|
1505
|
+
}, agentMap, currentAgent)
|
|
1506
|
+
: currentAgent;
|
|
1182
1507
|
const toolName = typeof value.toolName === 'string'
|
|
1183
1508
|
? value.toolName
|
|
1184
1509
|
: typeof rawItem.name === 'string'
|
|
@@ -1197,13 +1522,15 @@ function deserializeInterruptions(serializedInterruptions, agentMap, currentAgen
|
|
|
1197
1522
|
/**
|
|
1198
1523
|
* @internal
|
|
1199
1524
|
*/
|
|
1200
|
-
async function deserializeProcessedResponse(agentMap, state, serializedProcessedResponse) {
|
|
1525
|
+
async function deserializeProcessedResponse(agentMap, state, serializedProcessedResponse, options = {}) {
|
|
1201
1526
|
const currentAgent = state._currentAgent;
|
|
1202
|
-
const configuredTools = await currentAgent.getAllTools(state._context);
|
|
1527
|
+
const configuredTools = options.executionTools ?? (await currentAgent.getAllTools(state._context));
|
|
1203
1528
|
const allTools = [
|
|
1204
1529
|
...configuredTools,
|
|
1205
1530
|
...state.getToolSearchRuntimeTools(currentAgent),
|
|
1206
1531
|
];
|
|
1532
|
+
const baseAgentTools = currentAgent.tools;
|
|
1533
|
+
const allowSerializedExecutionToolPlaceholder = options.allowSerializedExecutionToolPlaceholder ?? true;
|
|
1207
1534
|
const tools = new Map(allTools
|
|
1208
1535
|
.filter((tool) => tool.type === 'function')
|
|
1209
1536
|
.map((tool) => [getFunctionToolQualifiedName(tool) ?? tool.name, tool]));
|
|
@@ -1250,17 +1577,33 @@ async function deserializeProcessedResponse(agentMap, state, serializedProcessed
|
|
|
1250
1577
|
functions: await Promise.all(serializedProcessedResponse.functions.map(async (functionCall) => {
|
|
1251
1578
|
const toolIdentity = resolveFunctionToolCallName(functionCall.toolCall, tools) ??
|
|
1252
1579
|
functionCall.tool.name;
|
|
1253
|
-
|
|
1580
|
+
const resolvedTool = tools.get(toolIdentity) ??
|
|
1581
|
+
getSerializedFunctionToolPlaceholder({
|
|
1582
|
+
agent: currentAgent,
|
|
1583
|
+
baseAgentTools,
|
|
1584
|
+
serializedTool: functionCall.tool,
|
|
1585
|
+
toolCall: functionCall.toolCall,
|
|
1586
|
+
toolIdentity,
|
|
1587
|
+
allowSerializedExecutionToolPlaceholder,
|
|
1588
|
+
});
|
|
1589
|
+
if (!resolvedTool) {
|
|
1254
1590
|
throw new UserError(`Tool ${toolIdentity} not found`);
|
|
1255
1591
|
}
|
|
1256
1592
|
return {
|
|
1257
1593
|
toolCall: functionCall.toolCall,
|
|
1258
|
-
tool:
|
|
1594
|
+
tool: resolvedTool,
|
|
1259
1595
|
};
|
|
1260
1596
|
})),
|
|
1261
1597
|
computerActions: serializedProcessedResponse.computerActions.map((computerAction) => {
|
|
1262
1598
|
const toolName = computerAction.computer.name;
|
|
1263
|
-
const computerTool = resolveComputerTool(toolName)
|
|
1599
|
+
const computerTool = resolveComputerTool(toolName) ??
|
|
1600
|
+
getSerializedComputerToolPlaceholder({
|
|
1601
|
+
agent: currentAgent,
|
|
1602
|
+
baseAgentTools,
|
|
1603
|
+
serializedTool: computerAction.computer,
|
|
1604
|
+
toolName,
|
|
1605
|
+
allowSerializedExecutionToolPlaceholder,
|
|
1606
|
+
});
|
|
1264
1607
|
if (!computerTool) {
|
|
1265
1608
|
throw new UserError(`Computer tool ${toolName} not found`);
|
|
1266
1609
|
}
|
|
@@ -1271,22 +1614,38 @@ async function deserializeProcessedResponse(agentMap, state, serializedProcessed
|
|
|
1271
1614
|
}),
|
|
1272
1615
|
shellActions: (serializedProcessedResponse.shellActions ?? []).map((shellAction) => {
|
|
1273
1616
|
const toolName = shellAction.shell.name;
|
|
1274
|
-
|
|
1617
|
+
const shellTool = shellTools.get(toolName) ??
|
|
1618
|
+
getSerializedShellToolPlaceholder({
|
|
1619
|
+
agent: currentAgent,
|
|
1620
|
+
baseAgentTools,
|
|
1621
|
+
serializedTool: shellAction.shell,
|
|
1622
|
+
toolName,
|
|
1623
|
+
allowSerializedExecutionToolPlaceholder,
|
|
1624
|
+
});
|
|
1625
|
+
if (!shellTool) {
|
|
1275
1626
|
throw new UserError(`Shell tool ${toolName} not found`);
|
|
1276
1627
|
}
|
|
1277
1628
|
return {
|
|
1278
1629
|
toolCall: shellAction.toolCall,
|
|
1279
|
-
shell:
|
|
1630
|
+
shell: shellTool,
|
|
1280
1631
|
};
|
|
1281
1632
|
}),
|
|
1282
1633
|
applyPatchActions: (serializedProcessedResponse.applyPatchActions ?? []).map((applyPatchAction) => {
|
|
1283
1634
|
const toolName = applyPatchAction.applyPatch.name;
|
|
1284
|
-
|
|
1635
|
+
const applyPatchTool = applyPatchTools.get(toolName) ??
|
|
1636
|
+
getSerializedApplyPatchToolPlaceholder({
|
|
1637
|
+
agent: currentAgent,
|
|
1638
|
+
baseAgentTools,
|
|
1639
|
+
serializedTool: applyPatchAction.applyPatch,
|
|
1640
|
+
toolName,
|
|
1641
|
+
allowSerializedExecutionToolPlaceholder,
|
|
1642
|
+
});
|
|
1643
|
+
if (!applyPatchTool) {
|
|
1285
1644
|
throw new UserError(`Apply patch tool ${toolName} not found`);
|
|
1286
1645
|
}
|
|
1287
1646
|
return {
|
|
1288
1647
|
toolCall: applyPatchAction.toolCall,
|
|
1289
|
-
applyPatch:
|
|
1648
|
+
applyPatch: applyPatchTool,
|
|
1290
1649
|
};
|
|
1291
1650
|
}),
|
|
1292
1651
|
mcpApprovalRequests: (serializedProcessedResponse.mcpApprovalRequests ?? []).map((approvalRequest) => ({
|