Entrypoints

Entrypoints are typed API endpoints that define your agent's capabilities. Each entrypoint has input/output schemas, a handler, and optional pricing.

Defining an Entrypoint

Use addEntrypoint() from your framework adapter:

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

const agent = await createAgent({
  name: 'my-agent',
  version: '1.0.0',
})
  .use(http())
  .build();

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

addEntrypoint({
  key: 'greet',
  description: 'Greets a user by name',
  input: z.object({
    name: z.string(),
  }),
  output: z.object({
    message: z.string(),
  }),
  async handler({ input }) {
    return {
      output: {
        message: `Hello, ${input.name}!`,
      },
    };
  },
});

EntrypointDef Type

Input and Output Schemas

Schemas are defined with Zod and provide:

  • Runtime validation - Invalid inputs return 400 errors

  • TypeScript inference - Full type safety in handlers

  • JSON Schema generation - Automatic schema in Agent Card

Handler Function

Handler Signature

AgentContext

The context object passed to handlers:

Handler Example

Streaming Entrypoints

For long-running operations or LLM responses, use streaming:

Stream Handler Signature

Stream Envelope Types

The emit() function accepts these envelope types:

Full StreamEnvelope Union

Invoking Entrypoints

Non-Streaming (invoke)

Response:

Streaming (stream)

Response (SSE):

Adding Pricing

Entrypoints can require payment via the x402 protocol:

Or with separate invoke/stream pricing:

With payments configured, requests without valid payment headers return 402 Payment Required.

Usage Tracking

Return usage from handlers to track resource consumption:

Listing Entrypoints

Response:

Validation Errors

Invalid input returns a 400 error with details:

Best Practices

  1. Use descriptive keys - The key appears in URLs and the Agent Card

  2. Always add descriptions - They help with discovery and documentation

  3. Validate thoroughly - Use Zod's built-in validators (.min(), .max(), .email(), etc.)

  4. Stream when appropriate - Use streaming for LLM responses or long operations

  5. Track usage - Return usage for billing and analytics

  6. Handle errors gracefully - Throw errors with clear messages; they're returned as JSON

Next Steps

Last updated