Core

Complete example of building a full-featured agent.

Basic Agent

import { createAgent } from '@regent/core';
import { http } from '@regent/http';
import { createAgentApp } from '@regent/hono';
import { z } from 'zod';

// Define input/output schemas
const EchoInput = z.object({
  text: z.string().min(1).max(1000),
});

const EchoOutput = z.object({
  echoed: z.string(),
  timestamp: z.string(),
});

// Create agent
const agent = await createAgent({
  name: 'example-agent',
  version: '1.0.0',
  description: 'A full-featured example agent',
})
  .use(http())
  .addEntrypoint({
    key: 'echo',
    description: 'Echo input text with timestamp',
    input: EchoInput,
    output: EchoOutput,
    handler: async ({ input }) => ({
      output: {
        echoed: input.text,
        timestamp: new Date().toISOString(),
      },
    }),
  })
  .build();

// Create HTTP app
const { app, addEntrypoint } = await createAgentApp(agent);

// Start server
Bun.serve({
  fetch: app.fetch,
  port: 3000,
});

console.log('Agent running at http://localhost:3000');

Streaming Handler

Multiple Entrypoints

Dynamic Entrypoints

Custom Middleware

Usage Tracking

Testing the Agent

Last updated