# TypeScript Agent Runtime

A production-minded, dependency-free server-side agent runtime in TypeScript that handles streaming chat, tool calling and knowledge-base retrieval with explicit, tested handling of edge cases like aborted runs and token-limit cutoffs.

This is a server-side AI agent runtime written in plain TypeScript, with no LangChain, LangGraph or workflow engine. It handles edge cases most agent tutorials skip: a model requesting two tools at once, tool arguments cut off by a token limit, a user closing the tab mid-run, and a late retried result trying to overwrite an already-finished run.

Each run is committed as a single transaction covering the message, its steps and final state, so only one outcome wins a race; when the commit result is uncertain the system reports that instead of assuming success. Each run is stored as a sequence of steps, visible in an admin console timeline with token usage, latency and failure causes.

Each run gets its own token budget, estimated with a local tokenizer, with oldest-first history trimming. It supports DeepSeek's API directly and OpenAI-compatible relays for GPT, Grok and Gemini, with provider API keys encrypted at rest. It ships with a web app and an admin console.

Website: https://github.com/mufeiyu-ayu/agent
