context.ts
context.ts declares the agent's context bundle policy. Add it when the
default history bounds need tuning or a product needs a named custom policy;
when it is absent, Assembly Line uses defaultContext().
The default context bundle includes trusted instructions, the active event, bounded recent history, memory shape, a file manifest, attachments, compact skills and capability catalogs, channel metadata, and trust boundaries. Deferred tool schemas and skill bodies are not injected up front.
Minimal Example
Tune the default bundle by default-exporting defaultContext(options):
import { defaultContext } from "@assemblyline-agents/core";
export default defaultContext({
recentHistory: { maxMessages: 8 }
});
Full Options
A context policy is a ContextPolicy object; defaultContext(options) and
defineContext(policy) both return one.
| Field | Type / values | Default | Effect |
|---|---|---|---|
kind | string | "default" from defaultContext() | Policy identity recorded in the manifest. Any other value names a custom policy. |
name | string | "defaultContext" from defaultContext() | Attribution name; also the export the runtime looks up in context.ts. |
options | JSON object | {} | Policy options. Deep-merged across the extends chain. |
extends | ContextPolicy | — | Base policy. The runtime flattens the chain into one policy with merged options. |
The default bundle interprets exactly one options key:
recentHistory.maxMessages, a bound on the recent-history messages included in
the bundle. Every other key (for example a files: block) is carried into the
flattened policy and recorded in the manifest, but the default bundle does not
interpret it — such keys only have an effect when a custom host or policy
consumer reads them.
Custom Policies
Use defineContext() when a product needs a named context policy:
import { defaultContext, defineContext } from "@assemblyline-agents/core";
export default defineContext({
kind: "custom",
name: "caseContext",
extends: defaultContext({ recentHistory: { maxMessages: 5 } }),
options: {
includeCaseSummary: true
}
});
A custom kind changes attribution, not built-in behavior: the runtime
flattens the extends chain, deep-merges options, and records the policy
(with source attribution) in the manifest. Built-in bundle assembly still reads
only recentHistory.maxMessages; the host interprets any custom options.
Wiring Styles
Two equivalent wirings are supported:
- Default export in
context.ts. The compiler recordscontext.tsas the policy source, and the runtime loads its default export at run time. - Named export referenced from
agent.ts. Export a named policy fromcontext.tsand pass it tocontext:inagent.ts. The compiler stamps the identifier name into the manifest, and the runtime resolves that export first, then the default export.
// context.ts
import { defaultContext, defineContext } from "@assemblyline-agents/core";
export const customContext = defineContext({
kind: "custom",
name: "customContext",
extends: defaultContext({ recentHistory: { maxMessages: 5 } }),
options: { includeTestMarker: true }
});
// agent.ts
import { defineAgent } from "@assemblyline-agents/core";
import { customContext } from "./context";
export default defineAgent({
model: "openai/gpt-5.4-mini",
context: customContext
});
Conventions
Context policy is trusted app-runtime behavior. Keep prompt trust clear:
instructions.mdand loaded skills are trusted instructions.- Files, memory, history, attachments, webpages, search results, and tool output are untrusted context.
/filesand/historyare read-only projections./workspaceis where generated artifacts and modified input copies should go.