
Security News
Feross on TBPN: Socket's Series C and the State of Software Supply Chain Security
Feross Aboukhadijeh joins TBPN to discuss Socket's $60M Series C, 500%+ ARR growth, AI's impact on open source, and the rise in supply chain attacks.
@agentuity/runtime
Advanced tools
Server runtime for building Agentuity applications with Bun and Hono.
bun add @agentuity/runtime
@agentuity/runtime provides the server-side runtime for Agentuity applications. Built on Hono and optimized for Bun, it enables you to create type-safe agents with automatic routing, validation, and observability.
import { createApp } from '@agentuity/runtime';
const { server, logger } = await createApp();
logger.info('Server running on %s', server.url);
import { createAgent } from '@agentuity/runtime';
import { s } from '@agentuity/schema';
const agent = createAgent('greeting', {
description: 'A simple greeting agent',
schema: {
input: s.object({
message: s.string(),
}),
output: s.object({
response: s.string(),
}),
},
handler: async (ctx, input) => {
ctx.logger.info('Processing message:', input.message);
return { response: `You said: ${input.message}` };
},
});
export default agent;
import { createRouter } from '@agentuity/runtime';
import greetingAgent from './agent/greeting';
const router = createRouter();
router.get('/hello', (c) => {
return c.json({ message: 'Hello, world!' });
});
// Route with agent validation
router.post('/greeting', greetingAgent.validator(), async (c) => {
const data = c.req.valid('json'); // Fully typed from agent schema!
const result = await greetingAgent.run(data);
return c.json(result);
});
export default router;
If you prefer using new Hono() directly instead of createRouter(), import the Env type to type Agentuity context variables (c.var.logger, c.var.thread, c.var.session, c.var.kv, etc.). These values are populated at runtime when the router is mounted through the Agentuity runtime (via createApp()):
import { type Env } from '@agentuity/runtime';
import { Hono } from 'hono';
const router = new Hono<Env>();
router.get('/hello', (c) => {
// All Agentuity context variables are fully typed
c.var.logger.info('Request from thread %s', c.var.thread.id);
return c.json({ sessionId: c.var.sessionId });
});
export default router;
With custom application state:
import { type Env } from '@agentuity/runtime';
import { Hono } from 'hono';
interface MyAppState {
db: Database;
}
const router = new Hono<Env<MyAppState>>();
router.get('/data', (c) => {
const db = c.var.app.db; // typed as Database
return c.json({ connected: true });
});
import { createRouter, stream } from '@agentuity/runtime';
const router = createRouter();
router.post(
'/events',
stream((c) => {
return new ReadableStream({
start(controller) {
controller.enqueue('Event 1\n');
controller.enqueue('Event 2\n');
controller.close();
},
});
})
);
import { createRouter, websocket } from '@agentuity/runtime';
const router = createRouter();
router.get(
'/chat',
websocket((c, ws) => {
ws.onOpen(() => {
console.log('Client connected');
});
ws.onMessage((event) => {
const data = JSON.parse(event.data);
ws.send(JSON.stringify({ echo: data }));
});
ws.onClose(() => {
console.log('Client disconnected');
});
})
);
import { createRouter, sse } from '@agentuity/runtime';
const router = createRouter();
router.get(
'/updates',
sse((c, stream) => {
for (let i = 0; i < 10; i++) {
stream.writeSSE({
data: JSON.stringify({ count: i }),
event: 'update',
});
}
})
);
Creates a new Agentuity application instance.
Returns:
router - Hono application instanceserver - Server instance with listen() methodlogger - Structured loggerCreates a type-safe agent with input/output validation.
Config:
schema.input? - Schema for input validation (Zod, Valibot, etc.)schema.output? - Schema for output validationhandler - Agent handler function (ctx, input) => outputCreates a new Hono router pre-typed with Env for Agentuity context variables. This is equivalent to new Hono<Env>() but is the recommended approach.
Methods:
get/post/put/delete/patch - HTTP method handlersMiddleware Functions:
Use these middleware functions with standard HTTP methods:
websocket((c, ws) => { ... }) - WebSocket connections (use with router.get())sse((c, stream) => { ... }) - Server-Sent Events (use with router.get())stream((c) => ReadableStream) - Streaming responses (use with router.post())cron(schedule, (c) => { ... }) - Scheduled tasks (use with router.post())The Hono environment type that provides typed access to Agentuity context variables in route handlers. Use this when creating a plain new Hono() instance instead of createRouter().
import { type Env } from '@agentuity/runtime';
import { Hono } from 'hono';
const router = new Hono<Env>();
// c.var.logger, c.var.thread, c.var.session, c.var.kv, etc. are typed
Variables provided by Env:
| Variable | Type | Description |
|---|---|---|
logger | Logger | Structured logger |
tracer | Tracer | OpenTelemetry tracer |
meter | Meter | OpenTelemetry meter |
sessionId | string | Current session ID |
thread | Thread | Thread information and state |
session | Session | Session information and state |
kv | KeyValueStorage | Key-value storage |
stream | StreamStorage | Stream storage |
vector | VectorStorage | Vector storage |
sandbox | SandboxService | Sandbox service |
queue | QueueService | Queue service |
email | EmailService | Email service |
schedule | ScheduleService | Schedule service |
task | TaskStorage | Task storage |
app | TAppState | Custom application state |
Context object available in agent handlers:
interface AgentContext {
logger: Logger; // Structured logger
tracer: Tracer; // OpenTelemetry tracer
sessionId: string; // Unique session ID
kv: KeyValueStorage; // Key-value storage
stream: StreamStorage; // Stream storage
vector: VectorStorage; // Vector storage
state: Map<string, unknown>; // Request-scoped state
thread: Thread; // Thread information
session: Session; // Session information
config: TConfig; // Agent-specific config from setup
app: TAppState; // Application state from createApp
waitUntil: (promise) => void; // Defer cleanup tasks
}
Agentuity provides built-in storage abstractions:
Access these via the agent context:
const agent = createAgent('storage-example', {
schema: {
output: s.object({ value: s.string().optional() }),
},
handler: async (ctx, input) => {
await ctx.kv.set('key', 'value');
const value = await ctx.kv.get('key');
return { value };
},
});
Built-in OpenTelemetry support for logging, tracing, and metrics:
const agent = createAgent('observability-example', {
schema: {
output: s.object({ success: s.boolean() }),
},
handler: async (ctx, input) => {
ctx.logger.info('Processing request');
const span = ctx.tracer.startSpan('custom-operation');
// ... do work ...
span.end();
return { success: true };
},
});
Fully typed with TypeScript. Input and output types are automatically inferred from your schemas.
Apache 2.0
FAQs
Unknown package
The npm package @agentuity/runtime receives a total of 1,213 weekly downloads. As such, @agentuity/runtime popularity was classified as popular.
We found that @agentuity/runtime demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Feross Aboukhadijeh joins TBPN to discuss Socket's $60M Series C, 500%+ ARR growth, AI's impact on open source, and the rise in supply chain attacks.

Security News
OSV withdrew 157 OSV malware reports after automated false positives incorrectly flagged trusted npm and PyPI packages, sending bad records into tools that rely on OSV data.

Research
/Security News
TrapDoor crypto stealer hits 36 malicious packages across npm, PyPI, and Crates.io, targeting crypto, DeFi, AI, and security developers.