OSS-first docs

These docs teach the open system first: contracts, generated surfaces, runtimes, governance, and incremental adoption. Studio shows up as the operating layer on top, not as the source of truth.

AI index

@contractspec/lib.ai-agent

Define AI agents in TypeScript, run them with deterministic tool calling, capture working memory, and route low-confidence decisions to human reviewers.

Installation

bun add @contractspec/lib.ai-agent

Define & register

import { defineAgent, AgentRegistry } from '@contractspec/lib.contracts-spec/agent';

const SupportBot = defineAgent({
  meta: {
    key: 'support.bot',
    version: '1.0.0',
    description: 'Resolve tickets and escalate low-confidence decisions.',
    owners: ['support'],
    tags: ['support'],
    stability: 'experimental',
  },
  instructions: 'Resolve tickets. Escalate when confidence < 0.75.',
  tools: [{ name: 'support_resolve_ticket' }],
  policy: {
    confidence: { min: 0.7, default: 0.6 },
    escalation: { confidenceThreshold: 0.75 },
  },
});

const registry = new AgentRegistry().register(SupportBot);

Run with approvals

import { createUnifiedAgent, ApprovalWorkflow } from '@contractspec/lib.ai-agent';

const approvals = new ApprovalWorkflow();
const agent = createUnifiedAgent(SupportBot, {
  backend: 'ai-sdk',
  tools: new Map([['support_resolve_ticket', async (input) => resolveTicket(input)]]),
});

const result = await agent.run(ticket.body);
// Route low-confidence or manual-review flows through approvals when needed.

What's inside

  • createUnifiedAgent, ContractSpecAgent, UnifiedAgent
  • MCP, operation-backed, memory, and subagent tool adapters
  • InMemoryAgentMemory plus interfaces for custom stores
  • ApprovalWorkflow + ApprovalStore for human-in-the-loop reviews