feat(kernel): add run-scoped host context - #1538
Closed
vishaltandale00 wants to merge 1 commit into
Closed
Conversation
|
Hi @vishaltandale00, thanks for your interest in contributing! This project requires that pull request authors are vouched, and you are not in the list of vouched users. This PR will be closed automatically. See https://github.com/PrimeIntellect-ai/prime-agent/blob/main/CONTRIBUTING.md for more details. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
Prime Agent already has authenticated per-call host-request contracts from #1238, while the broader dispatcher work in the closed #1243 branch was not merged. Embedders still need a generic way to attach host-owned authority or request state to one admitted prompt execution without changing tool definitions, exposing that state to model-generated Python, or storing it in session artifacts.
Changes
AgentSession/createAgentSession; the handler table is copied once and remains stable for the session lifetime.runContextto in-processprompt()/promptAndWait()options. An opaque execution ID flows through agent tool invocation metadata, while the actual object stays in a private execution-keyed map rather than a process-global or session-global current-context field.runContextobjects are consciously not added to the remote daemon/RPC prompt wire format; callers should attach them at the in-processAgentSessionhost boundary.Concurrency semantics
Each admitted root action owns a distinct execution scope. Sequential turns in one persistent session therefore resolve different contexts, and parallel sessions use separate keyed maps. Tool calls correlate by opaque execution ID and Jupyter parent message ID; missing correlation yields no run context instead of falling back to another active cell.
Validation
No paid inference was used. Validation used faux provider responses plus local IPython kernels.
npm run check(Biome with warnings as errors, TypeScript, installer render, browser smoke)npx tsx ../../node_modules/vitest/dist/cli.js --run test/suite/agent-session-run-context.test.ts(4 passed)npx tsx ../../node_modules/vitest/dist/cli.js --run test/agent-session-recursion.test.ts(98 passed)npx tsx ../../node_modules/vitest/dist/cli.js --run test/host-request-contract.test.ts(3 passed)npx tsx ../../node_modules/vitest/dist/cli.js --run test/kernel-goal-skill.test.ts test/kernel-agent-message-skill.test.ts(7 passed, 3 environment-gated skipped)npx tsx ../../node_modules/vitest/dist/cli.js --run test/suite/agent-session-compaction.test.ts(32 passed)npx tsx ../../node_modules/vitest/dist/cli.js --run test/agent.test.tsfrompackages/agent(25 passed)Note
Add run-scoped host context to kernel host request handlers in agent sessions
hostRequestHandlersregistration API onAgentSession(andcreateAgentSession/daemon) so callers can bind typed, session-lifetime kernel host handlers using a newcreateHostRequestHandlerfactory.AgentRunScopecarrying arunContext(caller-supplied, opaque) and anAbortSignal; this scope is correlated to kernel executions via anexecutionIdand exposed to host handlers through a dispatcher-mintedHostRequestContext.HostRequestContextnow includessessionId,recursionDepth, andrunContextfields; contexts are cryptographically provenance-checked (WeakSet-based) so structurally similar forgeries are rejected.rlm.runinherit the parentrunContextandhostRequestHandlers, withrecursionDepthincremented;runContextis memory-only and never serialized to disk or recovery snapshots.executionIdflows fromAgent.prompt/Agent.continuethroughAgentLoopConfiginto each tool'sexecutecall via a newAgentToolExecutionContextparameter.Macroscope summarized 65e7d31.