OneRingAI examples
This directory contains runnable TypeScript programs covering agents, tools,
streaming, media, connectors, OAuth, search, and MCP. Most examples import the
repository source directly; the context-freshness example imports the built package
and requires npm run build. Run examples from the repository root after installing
dependencies.
Starting with v2: use the five-harness examples, the AMOS runtime cookbook, and the v2 capability map to choose an entry point. The package migration guide covers v1 users.
Most AI and search examples make real, billable API calls. Review the prompt, model, and enabled tools before running them with production credentials.
Setup
npm install
cp .env.example .env
npm run examples:check
Use Node.js 22.13+ or 24+. Add only the credentials needed by the program you want
to run, then use its command below. npm run examples:check type-checks every
example without making network calls.
Environment variables
| Capability | Variables |
|---|---|
| OpenAI | OPENAI_API_KEY |
| Anthropic | ANTHROPIC_API_KEY |
| Google AI | GOOGLE_API_KEY |
| Groq | GROQ_API_KEY |
| Together AI | TOGETHER_API_KEY |
| DeepSeek | DEEPSEEK_API_KEY; optional DEEPSEEK_HOST and DEEPSEEK_BASE_URL |
| xAI | XAI_API_KEY (legacy GROK_API_KEY is also accepted) |
| Search | SERPER_API_KEY or SERPER_KEY; optionally BRAVE_API_KEY, RAPIDAPI_KEY, and SERPER_API_KEY_BACKUP |
| OAuth demos | Provider-specific client IDs/secrets as noted in the program; OAUTH_ENCRYPTION_KEY is recommended for persistent production storage |
| Remote MCP | MCP_SERVER_URL, optional MCP_SERVER_TOKEN, plus OPENAI_API_KEY |
| Logging | Optional LOG_LEVEL, LOG_FILE, and LOG_PRETTY |
Agent Runtime
The Agent Runtime example executes either a native OneRingAI agent or an OpenAI Codex SDK agent through the same specification/session/run workflow. It demonstrates model and reasoning selection, observable autonomous execution, explicit local policy, capability-aware behavior, and teardown. Start with the detailed guide and use the design document for architecture and server plans.
For the separately opt-in, local Codex subscription test suite and the small direct OpenAI API sample, see the live validation record. Its test-only login bootstrap does not change authentication in the examples or AMOS.
| Program | What it shows | Requirements and how to run |
|---|---|---|
agent-runtime-local.ts |
Interchangeable local OneRingAI/Codex SDK drivers with generic model/reasoning controls, live autonomous reasoning/activity events, explicit policy, and Codex workspace sandboxing. | OPENAI_API_KEY; npx tsx examples/agent-runtime-local.ts oneringai or npx tsx examples/agent-runtime-local.ts codex |
Purpose-specific models and shared budgets (Stage 06)
Both programs use public package exports and require npm run build. Their default
mode is deterministic and offline; mock answers/usage establish plumbing, not model
quality or savings. See the recipe.
| Program | What it shows | Run and expected behavior |
|---|---|---|
purpose-specific-models.ts |
Explicit extract/main/verify with separate windows, a fixed main model and shared task. | npm run example:purpose-models: four records including a controlled schema repair that must retain ALPHA_6; main/verification then succeed. npm run example:purpose-models -- --live: billable gpt-4.1 main plus gpt-4o-mini helpers, OPENAI_API_KEY from .env. At least three model requests, repairs/retries may add requests. Cleans up owned connectors, agent and task even on failure. |
shared-run-budget.ts |
Concurrent reservation denial, known-usage refund, idempotent external usage and unknown-price admission failure. | npm run example:shared-budget: rejects an overlapping request before dispatch, reports known synthetic totals and explicit unknown cost; destroys tasks. No credentials or external effects. |
npm run test:models:live explicitly makes billable OpenAI/Anthropic/Google calls
using all three .env keys. It checks helper/main run and stream, cross-provider
explicit rollover and controlled structured repair, plus thinking-enabled Google
run/stream accounting and an Anthropic fixed-budget extended-thinking helper
(14 live cases, including three controlled evidence-preserving helper repairs). These are functional marker
checks, not a quality benchmark. AMOS command examples are in its
helper guide.
Text, agents, tools, and infrastructure
| Program | What it shows | Requirements and how to run |
|---|---|---|
simple-text.ts |
Plain text generation, per-call settings, and JSON Schema structured output through the connector-first API. | OPENAI_API_KEY; npx tsx examples/simple-text.ts |
simple-text-streaming.ts |
The same streaming pattern across every configured OpenAI, Anthropic, and Google connector. Missing providers are skipped. | At least one of OPENAI_API_KEY, ANTHROPIC_API_KEY, or GOOGLE_API_KEY; npx tsx examples/simple-text-streaming.ts |
basic-agent.ts |
An agent using custom weather and restricted arithmetic tools, including the agentic tool-call loop. | OPENAI_API_KEY; npm run example:agent |
multi-turn-conversation.ts |
Explicit conversation history with runDirect(), useful when the application—not AgentContextNextGen—owns the transcript. |
OPENAI_API_KEY; npm run example:conversation |
interactive-chat.ts |
Interactive multi-provider chat, streaming, vision URLs/files, clipboard images, provider switching, Microsoft Graph access when configured, and approval-gated JavaScript execution. Type /help for commands and /exit to quit. |
At least one supported provider key; npm run example:chat |
multi-provider-comparison.ts |
Sends one prompt through every configured OpenAI, Anthropic, Google, Groq, Together, DeepSeek, and xAI connector using one API shape. | At least one provider key; npm run example:providers |
deepseek-agent.ts |
Current V4 model, dedicated adapter, host preset selection, reasoning, and JSON Schema output. | DEEPSEEK_API_KEY; npx tsx examples/deepseek-agent.ts |
json-manipulation-tool.ts |
Agent-driven JSON add/replace/delete operations plus deterministic chaining of multiple json_manipulate calls. |
OPENAI_API_KEY; npm run example:json-tool |
agent-with-hooks.ts |
Execution hooks, simulated approval, tool-result caching, metrics, and pause/resume control. | OPENAI_API_KEY; npm run example:hooks |
logging-demo.ts |
Logger configuration and structured logs emitted by an agent and a custom calculation tool. | OPENAI_API_KEY; npm run example:logging |
custom-infrastructure.ts |
Skeleton implementations of ITextProvider, ITokenStorage, and IToolExecutor, plus injecting a custom provider into an agent. It uses local smoke tests rather than calling the hypothetical service. |
No credential required; npm run example:custom-infrastructure |
agentic-evaluation-baseline.ts |
Four Stage 00 workloads using the real Agent loop, strict offline replay, evidence-based completion, cancellation/checkpoint/continuation, correlated event reports, and optional actual LLM runs. See the evaluation guide. | Offline: no credentials, npm run example:agentic-baseline; held-out: append -- --held-out; real OpenAI calls: append -- --live. Other live providers require explicit vendor/model configuration. |
context-request-budget.ts |
Known JSON schema and custom provider window trigger one compaction; separate colliding spills recover both sources; an oversized protected error fails before dispatch. | Build first, then npm run example:context-budget. No credentials or network; expects one fitting model call, both recovered markers, and CONTEXT_OVERFLOW for the oversized error. Agents, contexts, and the fixture connector are destroyed/removed. |
provider-config-generator.ts |
An interactive AI assistant that asks business-level questions and generates an OAuth connector configuration. Choosing to save writes oauth-<name>-config.json in the current directory. |
OPENAI_API_KEY or ANTHROPIC_API_KEY; npm run example:provider-config |
provider-config-programmatic.ts |
Non-interactive ProviderConfigAgent use, including multi-turn generation of GitHub and Microsoft connector configurations. |
OPENAI_API_KEY; npx tsx examples/provider-config-programmatic.ts |
The interactive chat can execute JavaScript and read user-selected local images.
Its tool calls require approval. The focused Google tool tests below deliberately
use autoApproveAll to remain non-interactive; keep that setting confined to
trusted demo tools.
Streaming, vision, audio, and provider checks
| Program | What it shows | Requirements and how to run |
|---|---|---|
vision-image-input.ts |
Single-image analysis, image comparison, explicit multimodal history, and low-detail image input. It uses public Unsplash URLs. | OPENAI_API_KEY; npm run example:vision |
audio-demo.ts |
OpenAI TTS, STT with timestamps, capability inspection, and an STT → agent → TTS voice pipeline. It writes tts-output.mp3, user-input.mp3, and agent-response.mp3 in the current directory. |
OPENAI_API_KEY; npx tsx examples/audio-demo.ts |
openai-realtime.ts |
A server-side Realtime WebSocket session, streamed audio/transcript collection, and minting a short-lived browser client secret without printing the secret. | OPENAI_API_KEY; npm run example:realtime |
test-openai-streaming.ts |
OpenAI streaming event types and final usage accounting. | OPENAI_API_KEY; npx tsx examples/test-openai-streaming.ts |
test-anthropic-streaming.ts |
Anthropic streaming event types and final usage accounting. | ANTHROPIC_API_KEY; npx tsx examples/test-anthropic-streaming.ts |
debug-google-tools.ts |
A compact diagnostic that verifies Gemini can call and execute execute_javascript. |
GOOGLE_API_KEY; npx tsx examples/debug-google-tools.ts |
test-google-simple.ts |
Non-streaming Gemini tool-call, iteration, and completion events. | GOOGLE_API_KEY; npx tsx examples/test-google-simple.ts |
test-google-streaming.ts |
Gemini streaming across a complete tool lifecycle, with assertions for call, execution, and final usage events. | GOOGLE_API_KEY; npx tsx examples/test-google-streaming.ts |
test-google-weather.ts |
Automatic versus explicitly requested Gemini tool use with a deterministic custom weather tool. | GOOGLE_API_KEY; npx tsx examples/test-google-weather.ts |
Search, connectors, and OAuth
| Program | What it shows | Requirements and how to run |
|---|---|---|
search-connector-demo.ts |
Direct connector-backed search with correct vendor authentication headers, optional RapidAPI search, and named Serper-key failover. | At least one search key; npx tsx examples/search-connector-demo.ts |
web-research-agent.ts |
An agent combining connector-discovered web search, web_fetch, and JSON manipulation for a multi-source research task. |
OPENAI_API_KEY; a Serper key enables the search sections; npm run example:web |
oauth-demo.ts |
Real OAuthManager client-credentials caching, encrypted FileStorage, and authorization-code PKCE URL generation against a deterministic local token server. Temporary files are removed. |
No external credential required; npm run example:oauth |
oauth-registry-demo.ts |
Registering several OAuth connectors, inspecting the registry, discovering connector-bound tools, and wiring those tools to an agent. It does not complete browser OAuth or call the registered services. | Credentials are optional for the registry demo; OPENAI_API_KEY enables agent construction; npm run example:oauth-registry |
oauth-static-tokens.ts |
Mixing API-key and OAuth connectors, authenticated fetch, connector tool discovery, and agent wiring. With a real OpenAI key it verifies /models; placeholder connectors are not called. |
Credentials optional, though OPENAI_API_KEY enables live verification; npm run example:oauth-static |
oauth-multi-user.ts |
Multi-user token isolation, auth URL generation, storage patterns, and production architecture guidance. It uses a temporary encrypted token directory and does not launch a browser. | OAuth client values are optional for this pattern demo; npm run example:oauth-multi-user |
oauth-multi-user-fetch.ts |
Binding createAuthenticatedFetch() to individual users and applying that pattern in request handlers, jobs, and agents. It does not call GitHub without completed user OAuth. |
OAuth client values are optional for this pattern demo; npm run example:oauth-multi-user-fetch |
MCP
The stdio examples launch demo-server.ts, which exposes
only synthetic in-memory files, a resource, and a prompt. They do not grant a
child process access to the repository filesystem.
| Program | What it shows | Requirements and how to run |
|---|---|---|
mcp/basic-client.ts |
Connect to a local stdio MCP server, discover its tools, register them on an agent, and use one in an LLM turn. | OPENAI_API_KEY; npx tsx examples/mcp/basic-client.ts |
mcp/resources.ts |
List/read MCP resources and list/get prompt templates without an LLM call. | No credential required; npx tsx examples/mcp/resources.ts |
mcp/multi-server.ts |
Create two namespaced stdio clients from a typed MCPConfiguration, connect all, and expose both tool sets to one agent. |
OPENAI_API_KEY; npx tsx examples/mcp/multi-server.ts |
mcp/http-client.ts |
Connect to an existing Streamable HTTP MCP endpoint, inspect capabilities, register remote tools, and let an agent use them. It exits cleanly with setup guidance when no URL is configured. | OPENAI_API_KEY, MCP_SERVER_URL, optional MCP_SERVER_TOKEN; npx tsx examples/mcp/http-client.ts |
mcp/demo-server.ts |
The safe local stdio fixture used by the other MCP examples; accepts optional --label <name> to distinguish instances. Normally launch it through a client. |
No credential required; manual server command: node --import tsx examples/mcp/demo-server.ts --label demo |
Troubleshooting
- A missing variable causes most examples to fail early with the exact variable
name. Add it to
.envand rerun. - A provider can retire a model or reject an expired credential independently of the library. The comparison and focused provider checks identify which provider failed.
oauth-demo.tsbinds an ephemeral loopback port. Run it in an environment that permits local listeners.mcp/http-client.tsneeds a separately running Streamable HTTP MCP server; the repository only supplies the stdio demo server.- Delete the three generated MP3 files when you no longer need the audio demo output.
Context freshness (Stage 01)
The context example retrieves native evidence connected to a spilled message
result. npm run example:structured-budget runs
structured-output-budget.ts after the build,
using an injected offline provider: the fitting repair makes two calls and
returns { "value": "Done" }; the oversized repair raises CONTEXT_OVERFLOW
before a second call. It preserves the main prepared revision and cleans up its
agents/connectors. No keys, network, or external services are needed.
After npm run build, run npm run example:context-freshness for the offline
compaction demonstration. It shows a refreshed
working-memory index, retained pending tool dependencies, and the final estimated
budget. It also contrasts a keyless notes lookup (index metadata only) with a keyed
lookup that recovers the original source contents. npm run example:amos-context renders the real AMOS budget/breakdown commands
without credentials. See context preparation for
contracts, failure behavior, and the opt-in billable npm run test:context:live suite.
Tool outcomes and cancellation (Stage 02)
C1's outcome-aware-tools.ts uses the public
createOutcomeTool() helper. Build, then run npm run example:outcome-aware-tools;
expect the same frozen raw payload with declined_lookup succeeded and
unavailable_lookup failed. No keys, network or external effects are required;
the manager is destroyed in finally. npm run example:amos-outcome-tools renders
these actual outcomes through AMOS. The separately opt-in, billable
npm run test:outcome-tools:live uses OpenAI/Anthropic/Google .env keys for
run/stream with synthetic local tools. See the recipe.
After npm run build, run npm run example:tool-outcomes for
tool-outcomes-and-cancellation.ts. No keys
are required. It demonstrates preserved domain/failure payloads, cooperative and
noncooperative deadlines, a correctly correlated late success, and host cancellation
during a loopback HTTP body read. The server binds an ephemeral localhost port;
there are no external service calls or writes. Managers, connector, and server are
cleaned up. Expect unknown completion at the timeout and a separate late diagnostic.
npm run example:amos-tool-outcomes renders these real local outcomes through
AMOS, including an explicit warning that a timed-out operation may still finish.
npm run test:tools:live is a separate, billable opt-in check using .env OpenAI,
Anthropic, and Google credentials with local tools. Missing or rejected credentials
fail the selected provider check. See the guide
and corrective validation record.
Stage 02's tool-outcomes-and-cancellation.ts also demonstrates invocation selection:
an admitted call retains its original implementation during a plugin wait, and the next
call uses the replacement registration. Run after building; setup requires no keys.
The example destroys its manager and closes its local HTTP server.
With ANTHROPIC_API_KEY in .env, opt in to
npm run example:tool-outcomes -- --live-anthropic. After the offline demonstrations,
it makes billable Anthropic calls in both run() and stream() modes using a named
connector and in-place before:llm options. Expect domain_probe=succeeded followed
by failure_probe=failed in each mode, with both original markers recovered.
Agents and the example-owned connector are cleaned up. The library narrows explicit
Anthropic named-tool requests and rejects mismatched provider calls before local
execution; see the selection contract.
Durable evidence (Stage 03, development branch)
Build the library first. These examples need no credentials or network and clean all temporary resources:
npm run example:durable-evidence— durable-tool-evidence.ts projects a 92 KB synthetic result, preserves status/IDs, evicts scratch, rolls over history, restores a saved context, and verifies exact recovery in a separate Node process. Output labels ordinary-restart acknowledgement explicitly.npm run example:ambiguous-evidence— ambiguous-action-evidence.ts simulates one write whose response never arrives. Cancellation records unknown completion without repeating the action; storage is explicitly process-local.npm run example:evidence-recovery— evidence-recovery.ts retains a successful local action's observation during a storage outage, rejects receipt-only acknowledgement, repairs storage, and permits rollover after exact result recovery. Pending delivery-only results survive file session save/load; the optional outcome is omitted deliberately. The action executes once; a custom backend uses an explicit serialization budget and requires no new adapter methods.npm run example:evidence-interruption— evidence-stream-interruption.ts closes a synthetic stream at tool completion, saves the unstored observation, rejects receipt-only admission, then restores a checkpoint after acknowledgement and recovers exact data. One tool action and one synthetic model call; no keys or network. Temporary session files are cleaned; evidence is process-local.npm run example:amos-evidence— exercises the real AMOS runner and/context evidencecommand with a synthetic provider. Lists metadata and explicitly previews at most 1024 characters, showing the next offset.
npm run test:evidence:live is separately opt-in and billable, using .env
OpenAI/Anthropic/Google credentials with local synthetic tools. It verifies managed
run/stream source retrieval and raw fallback after a controlled storage failure.
Read setup, bounds, failure recovery and durability.
Context strategies (Stage 07)
After building, run npm run example:context-strategies or add -- --held-out
for the six retained synthetic regression variants sharing one lookup scaffold.
The CLI also demonstrates three fitting critical preparations with a full evidence
store, unchanged history and zero source writes/helper calls under each new policy.
Algorithmic, masking and summaries
use the same local read-only environment; a common bounded reader retrieves source
fields by evidence ID or exact working-memory key. Offline providers and usage are
scripted. Expected: exact answer/account/status, no repeated action, all completion
predicates pass. Owned agents/connectors are destroyed and evidence is process-local.
npm run example:context-strategies -- --live --held-out loads .env and makes
billable OpenAI gpt-4o main / gpt-4o-mini helper calls, two repetitions per task
and strategy in seeded shuffled order. Set CONTEXT_STRATEGY_REPORT_PATH to save
actual usage, helper/repair attempts, returned models, source reads, failures and
latency. No external writes. This is a bounded functional pilot, not statistical
proof of non-inferiority or general cost reduction. Both new strategies remain
experimental and opt-in; algorithmic stays the default.
npm run example:amos-context-strategies uses the actual AMOS runner/command with
synthetic responses, a local file evidence store and temporary persisted settings.
It demonstrates real masking, diagnostics and policy switching without recreating
the agent or repeating its original read. Actual ConfigManager also demonstrates
failed selection restoring an absent setting through a later unrelated save/reload.
Selection and rollback make no model call; files, agent and connector are cleaned up. No keys/network are required. Read the
complete recipe for setup and support boundaries.
Protected task-state workflow
After npm run build, run npm run example:task-state
(task-state-workflow.ts). No keys or network are needed.
It keeps a host correction and unconfirmed proposal distinct, records one simulated
accepted action, suspends through rollover/checkpoint/restart, verifies recovery
in a separate Node process, then records host-confirmed remote completion. Expected:
one submission, corrected 40 EUR constraint, preserved pending state, and no LLM calls.
Temporary session/evidence files are removed.
npm run example:amos-task-state uses the actual AMOS runner and /context task
commands with one synthetic provider call. It demonstrates validated edits, stale
revision rejection, session reload and model command text remaining data.
npm run test:task-state:live explicitly makes billable OpenAI/Anthropic/Google
synthetic run/stream/restart and extractor calls using .env. Read
Task State for host authority, capacities and limitations.
The Stage 04 corrective walkthrough also reclaims old notes, reuses a pruned ID and
checks a second file checkpoint without another submission. The actual AMOS
walkthrough fills 100 task records, displays an actionable capacity error, uses
resolve-prune, adds a constraint and verifies checkpoint recovery with one total
synthetic provider call. The live task-state probes additionally validate ID reuse
and explicit atomic host recovery after their model response, without additional
model/action calls. No real remote completion or fresh quality benchmark is claimed.
The second corrective pass preserves legacy resolved-feature and external-plugin
configuration types. After building, npm run test:agentic:compat compiles pinned
legacy consumers through the root and /types exports without spreading current
defaults. Both task-state walkthroughs remain applicable and pass unchanged.
Bounded recovery and completion (Stage 10)
Build the library first. These examples are offline and require no .env keys:
| Command | Behavior |
|---|---|
npm run example:feedback-agent |
Rejects premature completion, recovers one transient read failure, then verifies host artifact/receipt state within four synthetic calls and two shared recovery attempts. |
npm run example:loop-equivalence |
Compares run/stream semantic hook and blocking-tool traces, recovery and completion, then proves stopped calls/receipts survive new input, including run-only JSON formatting. |
npm run example:amos-loop |
Uses the actual AMOS runner and /context loop, a blocked checkpoint and fresh class-method/private-state host verification. |
All examples destroy agents/connectors; the AMOS example removes its temporary
session directory. examples/agent-loop/scripted-provider.ts is a deterministic
model simulation that throws if its script is exhausted, not a production provider.
Hard ModelTask bounds use its explicit single-attempt host attestation.
npm run test:loop:live explicitly opts into real billable OpenAI, Anthropic and
Google run/stream recovery/blocked and stopped-history/formatting checks using .env. Tools are synthetic reads;
there are no real external writes. Read Loop Policies
for defaults, uncertainty, persistence and intentional run/stream differences.
The offline purpose-specific-models.ts example now starts with a shape-valid
empty answer and uses optional validationSchema to require content. Its one
existing repair retains the exact source marker and shares task accounting.
The structured-compaction live gate additionally injects the recorded empty
Google summary after a real call, then requires a real Google repair, source
retrieval and exact final constraints without masking fallback. All fault
injection is labeled in the report and uses synthetic source data.
Stage 12: opt-in presets and capability inspection
Build first, then npm run example:agentic-presets runs
agentic-presets.ts without keys/network: plain Agent,
research/workflow compositions, explicit host evidence scope, workflow completion
override, resolved settings and unavailable-feature diagnostics. It verifies call
counts, accepts getter-backed host scopes, demonstrates a rejected shared resume
retaining blocked-tool authority/checkpoint A and JSON-converting plugin recovery,
and destroys all agents/contexts and temporary files. npm run example:amos-presets runs the AMOS
selection/persistence/inspection walkthrough, verifies rejected-load checkpoint
protection and removes temporary files.
npm run test:presets:live is a separate billable OpenAI/Anthropic/Google gate
using .env; it also verifies original-history continuation after the three session
recovery paths on every provider. No external writes. See the recipe.
The Stage 12 AMOS preset walkthrough also demonstrates candidate-first handoff, failed-candidate preservation, and title retention across named/unnamed saves. The actual app/session command and timer-backed autosave paths are covered by latest corrective validation.
Stage 05: selective context and cache-aware layout
Build first. npm run example:context-selection compares an overflowing legacy
whiteboard/source view with budgeted selection, retaining the exact stored entries
and printing selection reasons, exact omitted-source recovery and stale-account
admission rejection. npm run example:context-dispatch-safety demonstrates one
bounded refresh for hook-edited input, rejection of superseded-prompt JSON repair
and last-request wrap-up accounting using local scripted providers. It also
formats before a real default algorithmic spill and persists one coherent structured
suspension without repeating its local action. Its checkpoint is process-local and
its temporary correlation file is removed during cleanup; no restart durability is
implied. Expected output includes formattingBeforeSpill and structuredSuspension.
npm run example:cache-aware-context demonstrates
stable instruction prefixes with late dynamic data and unknown provider counters.
npm run example:amos-context-selection executes the real AMOS runner and breakdown,
including a forced local read/wrap-up, then destroys its Agent and removes temporary
files. All four default to offline and label synthetic usage explicitly.
npm run test:context-assembly:live explicitly bills OpenAI/Anthropic/Google calls
using .env, checks run/stream in both layouts with local reads, and reports actual
cache usage without requiring hits. It also checks final hook edits, ordinary/stale
JSON repair and actual per-request wrap-up accounting. STAGE05_PROVIDER=openai|anthropic|google npm run example:cache-aware-context -- --live runs a separate two-call provider observation.
No service writes or general cache/cost/quality claim. See setup and boundaries.
Plugin/native compaction (Stage 16A)
Build first; all five default programs are offline protocol fixtures, with cleanup of owned agents/connectors/tasks and temporary files. They do not measure LLM quality.
| Program | Run / expected behavior |
|---|---|
native-context-compaction.ts |
npm run example:native-compaction: independent targets, preserved plugins, counted native window, early server-token rejection without a model call/history swap, and main continuation. Optional -- --live=openai/anthropic uses .env, max eight generation attempts and main-only output caps. |
native-context-hooks.ts |
npm run example:native-hooks (automatic) or npm run example:native-hooks-manual (explicit with automatic disabled): preserve a critical whiteboard fact in beforeCompaction, refresh once, reduce history and continue. Offline default; add -- --live=openai/anthropic, with eight-attempt/150-second task bound and cleanup. Manual Anthropic mode uses an 8192-token fixed-thinking budget and a compatible main output cap. |
native-context-recovery.ts |
npm run example:native-recovery: repeat compaction, durable source/session files, separate-process streamed resume, rejected model change and trusted pre-native recovery. Same opt-in live flags; parent/child each have call/deadline bounds. |
native-context-comparison.ts |
npm run example:native-comparison: one fixed held-out task across algorithmic/masking/structured/native, exact answer/constraint/no-repeat predicates and known/unknown usage. -- --live uses OpenAI gpt-6-astra plus a gpt-4o-mini summary helper; six attempts per policy. |
AMOS native walkthrough |
npm run example:amos-native-compaction: real adapter/configuration/commands, protected/empty result and saved-session resume. No keys. |
Selected live native models are gpt-6-astra and claude-sonnet-4-6. Native
callability does not guarantee reduction. Sources stay scoped; never repeat a write
to repair context. See the native recipe for
limits and actual adoption guidance.
Managed model routing (Stage 14A)
Build first. These default programs are offline, require no credentials, assert their functional contracts and clean up owned agents/connectors/tasks/temp files.
| Example | Command and expected behavior |
|---|---|
| adaptive-model-routing.ts | npm run example:model-routing: host category selection, shared-task phase continuity, explicit default stream and opt-out; routes fast,fast,default,default,default. Prints decisions and actual/synthetic task accounting. |
| routing-with-context.ts | npm run example:routing-context: memory/evidence plus synthetic native history on an explicitly permitted alternative whose unused default has no native adapter; protected incompatible switch and compatible continuation. |
| routing-suspension-recovery.ts | npm run example:routing-suspension: synthetic wait, ordinary event resumption, inherited JSON format, bounded malformed-output repair and host completion on the original route/task. Four model calls, one wait, one resumed completion check. |
| Failed suspension finalization | npm run example:routing-suspension -- --failed-finalization: two-call cap denies formatting and two event retries under the original task; one registered wait, zero successful suspension events, saved failed-finalization receipt. Explicit host cancellation releases task authority without undoing the wait. |
| AMOS routing | npm run example:amos-routing: real /routing commands, persisted JSON rules/hints, actual run/stream decisions and opt-out. |
npm run example:model-routing -- --live=openai (or anthropic/google) loads
.env, requires that provider key and makes at most eight generation attempts
within 120 seconds. npm run test:model-routing:live bills the complete routing
contract suite and small fixed quality/cost pilot across all three providers.
Synthetic usage makes no quality/cost claim; the real pilot is not a general
benchmark. See the recipe for setup, model fixtures,
limits, native ownership, failure semantics and validation evidence.
The Google pilot explicitly disables thinking on supported Gemini 2.5 Flash GenerateContent models. The converter now sends the required zero budget; the original exact-answer and minimum savings checks are unchanged. This is a measured fixture comparison rather than a promise that every routed workload costs less.
Explicit shared accounting (C2)
After npm run build, run npm run example:composite-binding. This deterministic
offline recipe makes three synthetic managed/direct/helper calls on one ModelTask,
prints purposes and total usage, and cleans up all resources. No keys are needed.
Managed cancellation uses the task; direct/helper APIs also take explicit signals.
The verified routine facade and AMOS operation controls are delivered in C3.
Verified routines (C3)
After npm run build, run npm run example:routine-stores for an offline demonstration of actual unified store calls, map output and fold accumulation. Expected result: [2,3] becomes [4,6], then 10, with six deterministic model calls and complete agent/connector cleanup. No keys, network or live LLM are used. See the example and the routine guide.
After npm run build, run npm run example:verified-routines (offline, no credentials). It submits one synthetic action, waits for a host check, resumes the same cursor and verifies an artifact created by a post-step. All agents/tasks/connectors are cleaned up. See the recipe for source archival and live test opt-in.
Enhanced connectors (C4)
Build, then run npm run example:enhanced-connectors. It uses temporary local HTTP servers and an evidence directory, with zero LLM calls/external writes. Expected: two safe-read attempts, complete allowed source recovered after rollover, one synthetic mutation despite HTTP 503, no legacy aliases, same-origin redirects followed and cross-origin redirects blocked before credentials leave the configured origin. It cleans up all resources. See the connector recipe for explicitly opt-in live validation.
Connector collection pages (C5)
Build, then run npm run example:connector-pages. No credentials are needed. A local server over-returns, includes an empty intermediate page and ends with a partial page: expected 49 exact IDs across 14 logical pages/HTTP requests and zero LLM calls. The example verifies the stable ID hash, source recovery from a reopened FileEvidenceStorage, catalog reload/context rollover, rejection by a fresh manager, and cleanup. See the page recipe; opt-in live tests use real models and synthetic local provider pages only.
Complete factory orchestration
After building, npm run example:orchestrator-factory runs orchestrator-factory.ts offline. It asserts actual distinct root/worker requests, shared operation accounting across delegation/monitoring and cleanup; expected output includes passed: true and two shared-operation calls plus an independent root configuration probe. No keys or external writes. See the recipe for real connector setup and retained-source recovery.
-
Remote tool outcomes:
npm run example:remote-outcomes. Offline authenticated transport; exact chunked sources, business declines, uncertain synthetic write and receipt recovery with one submission. Concurrent receipt polls reuse the same acknowledged record without consuming more quota. No keys or network needed. Opt-in real-provider checks:npm run test:remote-outcomes:live. -
Composed meeting preparation:
npm run example:composition-evaluationruns six offline local/remote cases, host verification, exact source hashing and temporary artifact cleanup. -
npm run example:amos-compositionexercises actual AMOS routine inspection and same-process confirmation with a synthetic provider and no credentials. -
Endpoint capabilities:
npm run example:endpoint-capabilities. Offline root/shared metadata, documented constraints and explicit unknowns. -
Parameter policy:
npm run example:parameter-policy. Actual mocked Responses bodies, omission versus supported zero, raw strictness, bounded decisions and saved configuration preserved. No network or keys. -
Vendor presentation:
npm run example:vendor-presentation. Immutable browser-safe catalog, host label override, explicit unknown fallback and identity/presentation separation. No network or keys.
Agent runtime harness examples
Build the public package first. These examples import only documented public exports and subpaths. The defaults are offline: synthetic model/CLI/HTTP transports, actual adapters/SDK serialization, no provider account. Install both optional local SDK peers for the five-harness examples. MCP examples need an authenticated loopback socket.
| Command from repository root | Expected behavior and cleanup |
|---|---|
npm run example:agent-runtime-swappable |
Creates one logical agent; two ACK turns and one selected host-tool call per turn through all five bindings; one definition digest. Uses the canonical baseline reporter's JSON/usage helpers. Removes private native/workspace/control state. |
npm run example:agent-runtime-claude |
Real in-process MCP with scripted Claude queries, ACK twice and raw business-value handling. Removes private state. |
npm run example:agent-runtime-recovery |
Two actual processes in each scenario; inputs=1, externalWrites=1, foreignDenied=true, recovered=ACK. Stored-result redelivery plus deliberate child exit after a synthetic write; original receipt recovery, no replacement action. Removes temporary files. |
npm run example:agent-runtime-safety |
Offline host-policy denial, then a fresh authorized session. Simulates a storage acknowledgement lost after commit; repairs through getRun, restores the original result, and verifies exactly one authorized tool execution. Requires a current package build; no credentials/CLI/provider calls; removes temporary files. |
npm run example:agent-runtime-openai-managed |
Actual SDK plus fake HTTP/SSE; ACK, one input/tool action despite lost result response, paginated output and owned deletion. |
npm run example:agent-runtime-claude-managed |
Actual SDK plus fake HTTP/SSE; ACK after lost result response, then budget waiting and confirmed cancellation with zero actions. Owned cleanup. |
npm run example:agent-runtime-managed-restart |
Both real vendor SDKs use one external loopback mock service. Producer crashes after one accepted tool result; a second process recovers ACK with inputs=1/effects=1 and no cancellation/resubmission. Removes control/mock state. |
npm run example:agent-runtime-artifacts |
Explicit bounded upload/download on both managed drivers; exact bytes, foreign-reference denial and owned cleanup. |
npm run example:amos-runtime |
Complete AMOS workflow across five bindings: two actions each, request-ID deduplication/conflict denial, result/activity replay, both managed file transfers, supported idle detach/resume, explicit deletion and native-command rejection. |
npm run example:agent-runtime-run-options |
Actual native Agent loop with a synthetic provider: schema-validated JSON, model/reasoning override, immutable admitted input, pre-dispatch cancellation, context restore and original-request replay with exactly two provider calls. |
The existing agent-runtime-local.ts oneringai|codex commands preserve explicitly
selected real/billable behavior and are excluded from offline runs. The Claude and
managed examples' --live path additionally requires ONERINGAI_ALLOW_LIVE=1 and the
vendor API key (optional trusted Anthropic workspace). These gates are prepared but
unrun: live LLM/native agent testing remains paused. Managed example failure retains
its recovery reference/private control directory; keep these for repair rather than
submitting the task again. No subscription credentials are read. See the canonical
guide and delivery ledger.
For an interactive application, the AMOS cookbook
uses runtime-host.ts. It selects any of
five actual adapters using AMOS_RUNTIME_DRIVER, defaults to offline transports,
saves the current locator atomically, and isolates control/workspace/transfers. Real
provider mode requires both explicit live gates and named Connector credentials; it
remains unrun under the live-testing pause. The cookbook covers every command, per-run
endpoint restrictions, file setup, failed recovery/persistence and owned cleanup. Mock
managed service state does not survive a CLI restart; use the dedicated independent
mock-service restart example for that scenario. Prior local SDK history requires a
trusted native checkpoint verifier, which the sample does not replace with a no-op.