tygent
v0.5.0
Published
Transform LLM agents plans into structure for lower cost, faster execution and more.
Maintainers
Readme
Tygent (JavaScript / TypeScript)
Tygent restructures unorganised LLM agent plans into explicit execution artefacts so you can orchestrate steps deterministically and fetch the right context at the right time. Directed execution graphs[^dag] are the default structure the TypeScript runtime produces, pairing node metadata with prefetch directives that the scheduler and tooling understand.
Highlights
- Structured planner – parse natural-language or JSON payloads into typed steps with dependencies, tags, and link metadata (
PlanParser,ServicePlanBuilder). - Context-aware scheduler –
Schedulerconsumes the structured plan to prioritise nodes, respect latency models, honour token budgets, and emit audit hooks;executeParalleladds batched concurrency. - Drop-in acceleration –
accelerate()wraps callables, framework objects, or service payloads and returns an executor backed by the structured representation. - Adaptive executor –
AdaptiveExecutorand rewrite rules adjust the plan mid-flight for fallbacks, branching, or resource-aware behaviour while preserving metadata. - Multi-agent orchestration –
MultiAgentManagerandCommunicationBuscoordinate agents using the shared structured context; the legacyMultiAgentOrchestratorcontinues to emit conversation graphs[^dag] for demos. - Service & CLI – the bundled CLI manages tenant state, ingestors, and API keys, and can host a simple HTTP service (
tygent serve) that surfaces structured plan conversions and catalogue endpoints. - Structured logging –
getLogger()provides namespace-scoped JSON logging with level control via theTYGENT_LOG_LEVELenvironment variable.
Installation
npm install tygent
# or
yarn add tygentThe package targets Node.js 16+ and ships compiled JavaScript (dist/) and type definitions.
Quick tour
These examples follow the journey from unstructured ideas to structured plans that expose dependencies, metadata, and context-prefetch hints to the runtime.
1. Accelerate a plan dictionary
import { accelerate } from 'tygent';
const plan = {
steps: [
{ id: 'collect', type: 'tool', action: (inputs: any) => ({ sources: inputs.query }) },
{
id: 'summarise',
type: 'tool',
action: (inputs: any) => `Summary: ${inputs.collect.sources}`,
dependencies: ['collect'],
critical: true,
},
],
};
const executePlan = accelerate(plan);
async function run() {
const result = await executePlan({ query: 'AI funding' });
console.log(result.summarise);
}
run().catch(console.error);accelerate detects plan-like payloads (including the service bridge format) and builds a structured graph[^dag]/scheduler pair automatically.
2. Wrap existing functions
import { accelerate } from 'tygent';
const fetchProfile = accelerate(async (userId: string) => {
// Existing implementation
return { user: userId };
});
async function run() {
const profile = await fetchProfile('acct_42');
console.log(profile);
}
run().catch(console.error);When passed a framework object (LangChain agent, OpenAI Assistant, LlamaIndex index, etc.), accelerate looks for plan, getPlan, or workflow attributes, converts them into structured graphs[^dag], and returns a thin wrapper that proxies the original API.
3. Build and run the structured graph
import { DAG, ToolNode, Scheduler } from 'tygent';
const dag = new DAG('content');
dag.addNode(new ToolNode('search', () => ({ hits: ['url'] })));
dag.addNode(new ToolNode('summarise', (inputs) => `Summary of ${inputs.search.hits}`));
dag.addEdge('search', 'summarise');
async function run() {
const scheduler = new Scheduler(dag, { priorityNodes: ['summarise'] });
const results = await scheduler.execute({ query: 'latest research' });
console.log(results.summarise);
}
run().catch(console.error);The scheduler supports sequential execution via execute and batched parallel execution with executeParallel, respecting token budgets, rate limits, and latency hints provided on nodes.
4. Adaptive executor
import { AdaptiveExecutor, createFallbackRule, DAG, ToolNode } from 'tygent';
const base = new DAG('workflow');
base.addNode(
new ToolNode('primary', (inputs) => {
if (!inputs.ok) {
return { status: 'error' };
}
return { status: 'ok', value: 1 / (inputs.divisor ?? 1) };
}),
);
const executor = new AdaptiveExecutor(base, [
createFallbackRule(
(state) => state.primary?.status === 'error',
(dag) => {
const patched = dag.copy();
const fallback = new ToolNode('fallback', () => ({ status: 'ok', value: 1 }));
patched.addNode(fallback);
patched.addEdge('primary', 'fallback');
return patched;
},
'fallback_on_error',
),
]);
async function run() {
const outputs = await executor.execute({ ok: false });
console.log(outputs.fallback);
}
run().catch(console.error);Rewrite rules can also branch conditionally (createConditionalBranchRule) or adapt to resource signals (createResourceAdaptationRule).
5. Multi-agent coordination
import { MultiAgentManager } from 'tygent';
const manager = new MultiAgentManager('support');
manager.addAgent('analyser', {
async execute(inputs) {
return { keywords: inputs.question.split(' ') };
},
});
manager.addAgent('retrieval', {
async execute() {
return { docs: ['reset-guide.md'] };
},
});
async function run() {
const result = await manager.execute({ question: 'How do I reset my password?' });
console.log(result);
}
run().catch(console.error);CommunicationBus provides a shared mailbox when agents want to exchange messages; the orchestrator helper (MultiAgentOrchestrator) constructs conversation graphs[^dag] for legacy demos.
Service plans, CLI, and logging
- ServicePlanBuilder – converts SaaS payloads into
PlanParser-ready structures, applies prompt templating, merges link metadata, and registers optional LLM runtimes viaLLMRuntimeRegistry. - Prefetch –
prefetchManyis a stub that records URLs; override it or wrapServicePlan.prefetch()to integrate a real cache/downloader. - CLI – invoke with
npx tygent <command>:
State is written tonpx tygent register --name "Acme" --email [email protected] npx tygent list-accounts npx tygent generate-key --account acct_123 --label demo npx tygent configure-ingestor --account acct_123 --name langchain npx tygent serve --port 8080service_state.json(override with--stateorTYGENT_SERVICE_STATE). The HTTP service currently exposes/health,/catalog, and/accountsendpoints as building blocks for demos. - Logging – create namespace loggers with
getLogger('scheduler'). SetTYGENT_LOG_LEVELtotrace|debug|info|warn|errorto tune verbosity. All internal components log structured JSON to stdout.
Planner adapters
Tygent can ingest plans emitted by other tooling and normalise them into scheduler-ready service plans. The integration bundle now includes adapters for the most common CLI planners:
GeminiCLIPlanAdapterwithpatchGeminiCLI()to attachtoTygentServicePlanonto the optionalgemini-cliruntimeClaudeCodePlanAdapterwithpatchClaudeCode()for Anthropic's Claude Code editor payloadsOpenAICodexPlanAdapterwithpatchOpenAICodex()for legacy Codex workflow payloads
Each adapter accepts the raw payload and returns a ServicePlan, so you can execute the converted steps via the standard runtime:
import { GeminiCLIPlanAdapter, accelerate } from 'tygent';
const adapter = new GeminiCLIPlanAdapter(geminiPayload);
const servicePlan = adapter.toServicePlan();
const executePlan = accelerate(servicePlan.plan);
const outputs = await executePlan({ topic: 'structured planning' });Call the corresponding patch* helper if you would like the third-party planner to expose toTygentServicePlan directly when the optional dependency is installed.
Examples
TypeScript examples live under examples/; run them after a build:
npm run build
node dist/examples/multi-agent.jsHighlighted samples:
examples/advanced-customer-support.ts– incremental structured graph[^dag] creation and schedulingexamples/dynamic-adaptive.ts– AdaptiveExecutor rewrite rules in actionexamples/langchain-integration.ts– accelerating a LangChain workflowexamples/service-plan.ts– building and executing service plans end-to-end
Editor extensions
- VS Code (
vscode-extension/) – exposes a Tygent: Enable Agent command that injectstygent.install()(and missing imports) into the active Python or TypeScript agent so you can adopt the structured planner in-place. - Cursor (
cursor-extension/) – ships the equivalent Tygent: Enable Agent (Cursor) command for Cursor’s command palette, enabling one-click upgrades inside Cursor workspaces.
Both extensions are TypeScript projects; run npm run compile in the respective folder to build, then load the generated package via VS Code’s Extension Development Host or Cursor’s extension loader.
Testing
npm install
npm run build
npm testjest drives the unit tests under tests/. Use npm test -- --coverage for coverage reports or npx jest tests/dag.test.ts to run the structured graph[^dag] suite. The repository also includes an integration smoke test (test-multi-agent.js).
Project layout
src/
├── accelerate.ts # drop-in wrappers for functions & frameworks
├── scheduler.ts # structured graph execution engine[^dag] + hooks
├── adaptive-executor.ts
├── multi-agent.ts
├── service-bridge.ts # service plan builder & runtime registry
├── service/ # CLI state manager and HTTP server
└── integrations/ # optional framework helpersCompiled artefacts land in dist/; coverage/ is produced by Jest when coverage is enabled.
[^dag]: Tygent materialises plans as typed directed acyclic graphs (DAGs) so dependencies, prefetch hints, and context fabric descriptors remain explicit for the execution engine and integrations.
Questions or ideas? Open a GitHub issue or email [email protected].
