@morphixai/agent-core
v1.0.0
Published
Context Flow Protocol + composable primitives for server-side AI agents (scope, runtime, toolkit, thread-state).
Maintainers
Readme
@morphixai/agent-core
Framework-v2 core primitives — deliberately small. Two things, nothing else:
- RunContext + Lineage — the frozen, construction-time business context of an agent instance, with spawn genealogy derived automatically.
- Tool-middleware onion —
(ctx, args, next) => resultcomposition for tool execution.
The assembly layer (instances, loop, HITL, spawn) lives in
@morphixai/agent-framework.
v2 is a ground-up rewrite. The v1 surface (
ScopeResolver/AgentRuntime/ToolRegistry/defineTool/ thread-state / tracer) was removed in 1.0.0. Pin<1.0.0if you still depend on v1.
Install
npm install @morphixai/agent-coreRunContext + Lineage
import { createRunContext, rootLineage, childLineage, isChildContext } from '@morphixai/agent-core';
// business half is generic — your shape (userId/appId/tenant/…)
const root = createRunContext(
{ userId, appId, conversationId },
rootLineage('dashboard', runId, conversationId),
);
const child = createRunContext(
{ userId, appId },
childLineage(root.lineage, 'media'),
);
child.lineage.path; // ['dashboard', 'media']
child.lineage.depth; // 2
child.lineage.rootRunId; // constant across the spawn tree
isChildContext(child); // trueContexts are frozen — rebinding a conversation means constructing a new instance. There is no ambient/mutable runtime state.
Tool-middleware onion
import { composeToolMiddleware, type ToolMiddleware } from '@morphixai/agent-core';
const audit: ToolMiddleware<Ctx> = async (ctx, args, next) => {
const result = await next(args); // pre → handler → post
emit({ type: 'tool_done', result }); // side effects live here, not in services
return result;
};
const guard: ToolMiddleware<Ctx> = async (ctx, args, next) =>
allowed(ctx) ? next(args) : { error: 'denied', hint: 'fix and resend' }; // short-circuit
const run = composeToolMiddleware([guard, audit], handler);Supports pre (rewrite args), short-circuit (deny without running the handler),
post (side effects), and wrap (timing/retry). @morphixai/agent-framework
composes three levels — global → agent → tool — around every tool handler.
Versioning
≥ 1.0.0 is the framework-v2 stable line, released in lockstep with
agent-framework / agent-bus / agent-workspace.
License
MIT © MorphixAI
