ExecutionContext
CORE · interface · Type contract
Required execution facts available inside a running call.
Import
ts
import type { ExecutionContext } from '@jangts/agent-core';js
/** @typedef {import('@jangts/agent-core').ExecutionContext} ExecutionContext */Other public entry points:@jangts/agent-core, @jangts/agent-core/types, @jangts/agent-core/structs.
Definition
ts
interface ExecutionContextField structure
| Field | Type | Required | Description |
|---|---|---|---|
logger | SubFlowLog | undefined | Optional | Read-only. Explicit optional recorder for this operation; never inferred from diagnostics. |
signal | AbortSignal | Required | Read-only. Non-optional cancellation signal; never undefined once execution has started. |
diagnostics | DiagnosticContext | undefined | Optional | Read-only. Diagnostic scope of the enclosing call, when recording is enabled. |
Examples
- Agent: run first, then bind tools and dependencies step by step: The Engine executes a bounded loop; after a Workflow is bound, each run only receives the data that changed in state.
- ModelRunner: input can be shortened while the output contract stays the same: Execute one model interaction through the real Provider port and return a value plus the invocation for this call.
- Actual request measurement and same-call preparation snapshot: Use prepare only when context must be handled ahead of time; multiple measurements and the final send reuse the same transport preparation.
- Child execution: isolated records, shared ancestor quota: A child Runner does not inherit conversation or the output receiver, but cannot bypass parent budget, cancellation, or deadlines.
- SSE, JSON frames, and bounded event streams: Reuse transport mechanics while preserving cancellation and backpressure; protocol parsing and business validation remain separate.
- Context policy: validate, reduce, and audit: Support provides replaceable policy implementations while Core keeps the final input contract and budget checks.
- Compressors and selectors: recommended implementations and custom algorithms: Bind prompts, output parsing, and algorithms as handlers; model I/O goes through callModel of the same request.
- Support: the aggregate entry for recommended usage: Support aggregates recommended construction, policies, and same-source configuration generation; Core execution does not depend on this namespace.
- Presentation: field ownership and final output: The model fills only the fields it is assigned; fixed text, bound values, and semantic keys are owned by the program.
- Reply events: text chunks and bubble boundaries: Turn an accepted reply into awaitable text/bubble events while preserving cancellation and delivery backpressure.
A single ordinary step is enough to run
Beginner · Node.js
ts
import { AgentCoreEngine } from '@jangts/agent-core/engine';
const agent = new AgentCoreEngine<string>();
const answer = await agent.run(() => ({ type: 'complete', value: '你好,Core' }));
console.log(answer);js
import { AgentCoreEngine } from '@jangts/agent-core/engine';
const agent = new AgentCoreEngine();
const answer = await agent.run(() => ({ type: 'complete', value: '你好,Core' }));
console.log(answer);Add an explicit Workflow and still call run
Configuration · Node.js
ts
import { AgentCoreEngine, defineWorkflow, route } from '@jangts/agent-core/engine';
type State = { name: string; answer?: string };
const workflow = defineWorkflow<State, string>({
id: 'greeting',
nodes: [{
id: 'greet', description: '根据本次姓名生成问候', startsRound: true,
run: state => ({ answer: '你好,' + state.name }),
routes: [route.deliver('answer')],
}],
});
const agent = new AgentCoreEngine({ workflow });
console.log(await agent.run({ name: 'Ivan' }));
console.log(await agent.run({ name: '访客' }));js
import { AgentCoreEngine, defineWorkflow, route } from '@jangts/agent-core/engine';
const workflow = defineWorkflow({
id: 'greeting',
nodes: [{
id: 'greet', description: '根据本次姓名生成问候', startsRound: true,
run: state => ({ answer: '你好,' + state.name }),
routes: [route.deliver('answer')],
}],
});
const agent = new AgentCoreEngine({ workflow });
console.log(await agent.run({ name: 'Ivan' }));
console.log(await agent.run({ name: '访客' }));Related policy source
- Execution implementation of the bounded loop, commit, and cancellation
- Core default budget values
- Same-call preparation and real input measurement
- Single-slot handoff and backpressure in event streams
- Real scheduling catalog for policies and reduction operations
- Default selection instruction and excerpt range
- Compression request and the real callModel contract
- Field ownership, model Schema, and composition
- Reply format declarations, shared checks, and bubble normalization
- Chunking, bubbles, and total duration limit