Skip to main content

Import

import {
  agent,
  AgentRuntime,
  registerAgent,
  getAgentsAsTools,
  createMemory,
  agentAsTool,
} from "veryfront/agent";

Examples

Basic agent

import { agent } from "veryfront/agent";

const assistant = agent({
  model: "openai/gpt-4o",
  system: "You are a helpful assistant.",
});

Agent with tools

import { agent } from "veryfront/agent";
import { tool } from "veryfront/tool";
import { z } from "zod";

const searchTool = tool({
  id: "search",
  description: "Search the knowledge base",
  inputSchema: z.object({ query: z.string() }),
  execute: async ({ query }) => ({ results: [] }),
});

const assistant = agent({
  model: "openai/gpt-4o",
  system: "You are a helpful assistant.",
  tools: [searchTool],
  memory: { type: "conversation", maxMessages: 50 },
});

Streaming API route

// app/api/chat/route.ts
import { agent } from "veryfront/agent";

const assistant = agent({
  model: "openai/gpt-4o",
  system: "You are a helpful assistant.",
});

export async function POST(req: Request) {
  const { messages } = await req.json();
  const result = await assistant.stream({ messages });
  return result.toDataStreamResponse();
}

Multi-agent composition

import { agent, registerAgent, getAgentsAsTools } from "veryfront/agent";

const researcher = agent({ model: "openai/gpt-4o", system: "Research topics thoroughly." });
const writer = agent({ model: "openai/gpt-4o", system: "Write clear prose." });

registerAgent(researcher);
registerAgent(writer);

const orchestrator = agent({
  model: "openai/gpt-4o",
  system: "Coordinate research and writing.",
  tools: getAgentsAsTools(["researcher", "writer"]),
});

API

agent(config)

Create an agent
PropertyTypeDescription
id?stringUnique identifier (auto-generated if omitted)
modelModelStringProvider and model (e.g. "openai/gpt-4o")
systemstring | (() => string) | (() => Promise<string>)System prompt. Accepts a string, function, or async function.
tools?true | Record<string, Tool | boolean>Tools available to the agent
maxSteps?numberMax tool-call iterations per request
streaming?booleanEnable streaming responses
memory?MemoryConfigConversation memory settings
middleware?AgentMiddleware[]Execution middleware pipeline
edge?EdgeConfigEdge runtime configuration
multimodal?{ vision?: boolean; audio?: boolean }Enable vision and/or audio
Returns: Agent

agent.generate(input)

Run the agent and return a complete response. Accepts a string or message array as input.
PropertyTypeDescription
input`string \Message[]`Prompt string or message history
context?Record<string, unknown>Additional context passed to the agent
Returns: Promise<AgentResponse>

agent.stream(input)

Run the agent and stream the response. Returns a result with .toDataStreamResponse() for API routes.
PropertyTypeDescription
input?stringPrompt string
messages?Message[]Conversation message history
context?Record<string, unknown>Additional context passed to the agent
onToolCall?(toolCall: ToolCall) => voidCallback fired when a tool is invoked
onChunk?(chunk: string) => voidCallback fired for each text chunk
Returns: Promise<AgentStreamResult>

agent.respond(request)

Handle an incoming HTTP request and return a streaming Response. Reads messages from the request body. Returns: Promise<Response>

agent.getMemory()

Get the agent’s memory instance. Returns: Memory<Message>

agent.getMemoryStats()

Get memory usage statistics (message count, estimated tokens, type). Returns: Promise<{ totalMessages: number; estimatedTokens: number; type: string }>

agent.clearMemory()

Clear all stored messages from memory. Returns: Promise<void>

Exports

Functions

NameDescription
agentCreate an agent
agentAsToolWrap agent as callable tool
createMemoryCreate memory (buffer, conversation, summary)
createRedisMemoryCreate Redis-backed memory
createWorkflowCreate sequential agent workflow
getAgentGet agent by ID
getAgentsAsToolsGet agents as tools (multi-agent)
getAllAgentIdsList registered agent IDs
getTextFromPartsExtract text from multi-part message
getToolArgumentsExtract parsed tool call args
hasArgsCheck for parsed args on tool call
hasInputCheck for raw input on tool call
registerAgentRegister agent for discovery

Classes

NameDescription
AgentRuntimeAgent execution runtime
BufferMemoryIn-memory message buffer
ConversationMemoryFull conversation history
RedisMemoryRedis-backed persistent memory
SummaryMemoryCompresses old messages into summaries

Types

NameDescription
Agentagent() return type
AgentConfigAgent configuration
AgentContextAgent handler context
AgentMiddlewareAgent execution middleware
AgentResponseAgent execution response
AgentStatusAgent status (idle, running, etc.)
AgentStreamResultStreaming result (.toDataStreamResponse())
EdgeConfigAgent-to-agent edge config
MemoryMemory interface
MemoryConfigMemory creation config
MemoryPersistenceMemory storage backend
MemoryStatsMemory usage stats
MessageChat message (user, assistant, system, tool)
MessagePartMulti-part message segment
ModelProviderModel provider interface
ModelStringModel configuration string format: “provider/model-name”
RedisClientRedis client interface (compatible with ioredis and node-redis)
RedisMemoryConfigRedis memory configuration
StreamToolCallStreaming tool call
ToolCallCompleted tool call
ToolCallPartTool call message segment
ToolCallPartWithArgsTool call with parsed args
ToolCallPartWithInputTool call with raw input
ToolResultPartTool execution result segment
WorkflowConfigcreateWorkflow config
WorkflowResultCompleted workflow result
WorkflowStepWorkflow step definition