This guide explains how to customize your AG-UI server to meet your specific needs.
Your AG-UI server is fully customizable. The most common customizations are:
- System Prompt - Change the LLM's behavior
- Agent Behavior - Modify how the agent processes requests
- Custom Routes - Add new endpoints
- Configuration - Adjust server settings
The system prompt controls how the LLM agent behaves. There are three ways to customize it:
Edit src/config/system-prompt.ts:
const DEFAULT_SYSTEM_PROMPT = 'You are a helpful coding assistant specialized in TypeScript.';Set the AGUI_SYSTEM_PROMPT environment variable:
export AGUI_SYSTEM_PROMPT="You are a helpful assistant specialized in data analysis."
pnpm run devCreate a system-prompt.txt file in the project root:
You are a helpful assistant with expertise in web development.
You provide clear, concise answers with code examples.
Edit src/routes/agent-factory.ts to change:
- LLM Endpoint: Default is LiteLLM or DeepSeek
- Model: Change the model name
- Retry Logic: Adjust
maxRetries,retryDelayMs - Timeout: Modify
timeoutMs
Example:
return new LLMAgent({
endpoint: 'https://api.openai.com/v1',
apiKey: process.env.OPENAI_API_KEY,
model: 'gpt-4',
maxRetries: 3,
retryDelayMs: 2000,
timeoutMs: 60000,
mcpServerId: 'mcpui-server',
});The main agent logic is in src/agents/llm.ts. Key customization points:
- Message Processing (line ~740):
convertMessages()- Modify how messages are formatted - Tool Call Handling (line ~400):
handleToolCalls()- Change tool execution logic - Event Streaming (line ~200):
run()- Customize event generation
Add new routes by creating a file in src/routes/ and registering it in src/server.ts.
Create src/routes/custom.ts:
import type { FastifyPluginAsync } from 'fastify';
export const customRoute: FastifyPluginAsync = async (fastify) => {
fastify.get('/custom/status', async (request, reply) => {
return {
status: 'ok',
custom: 'data',
timestamp: new Date().toISOString(),
};
});
};Register in src/server.ts:
import { customRoute } from './routes/custom.js';
// ...
await fastify.register(customRoute);All configuration is in src/utils/config.ts. Environment variables:
| Variable | Description | Default |
|---|---|---|
PORT |
Server port | 3000 |
HOST |
Server host | 0.0.0.0 |
CORS_ORIGIN |
CORS origin | * |
AGENT_MODE |
Agent mode (llm or emulated) |
emulated |
LLM_PROVIDER |
LLM provider (litellm or deepseek) |
litellm |
LITELLM_ENDPOINT |
LiteLLM endpoint (required if LLM_PROVIDER=litellm) |
- |
LITELLM_API_KEY |
LiteLLM API key (required if LLM_PROVIDER=litellm) |
- |
LITELLM_MODEL |
LiteLLM model name | deepseek-chat |
DEEPSEEK_API_KEY |
DeepSeek API key (required if LLM_PROVIDER=deepseek) |
- |
DEEPSEEK_MODEL |
DeepSeek model name | deepseek-chat |
Note: When using LLM_PROVIDER=deepseek, you do NOT need LiteLLM. The server connects directly to DeepSeek's API. See the AG-UI server README for details.
| MCP_SERVER_URL | MCP server HTTP URL | - |
| MCP_SERVER_COMMAND | MCP server stdio command | - |
| AGUI_SYSTEM_PROMPT | System prompt override | - |
Create .env.development:
PORT=3000
LOG_LEVEL=debug
LOG_PRETTY=true
AGENT_MODE=llm
LLM_PROVIDER=litellm
LITELLM_ENDPOINT=http://localhost:4000Create .env.production:
PORT=8080
LOG_LEVEL=info
LOG_PRETTY=false
AGENT_MODE=llm
LLM_PROVIDER=deepseek
DEEPSEEK_API_KEY=your-api-keyTo connect to an MCP-UI server:
MCP_SERVER_URL=http://localhost:3100/mcp pnpm run dev --use-llmMCP_SERVER_COMMAND="node dist/server.js" pnpm run dev --use-llm- Create a new agent class in
src/agents/extendingBaseAgent - Import and instantiate it in
src/routes/agent-factory.ts
Modify src/streaming/encoder.ts to:
- Add custom event types
- Change event formatting
- Implement event filtering
Add authentication middleware in src/server.ts:
fastify.addHook('preHandler', async (request, reply) => {
const apiKey = request.headers['x-api-key'];
if (!apiKey || apiKey !== process.env.API_KEY) {
reply.code(401).send({ error: 'Unauthorized' });
}
});Run tests:
pnpm testAdd custom tests in the tests/ directory.
Enable debug logging:
LOG_LEVEL=debug pnpm run devOr use the TypeScript debugger:
pnpm run dev:debugThen attach your IDE's debugger to the Node process.
See ../../docs/cloud-deployment-guide.md for deployment instructions.
- Check the AG-UI Documentation
- Review the original
agui-test-serverfor examples - See
../../docs/scaffold-guide.mdfor scaffold tool usage
// src/config/system-prompt.ts
const DEFAULT_SYSTEM_PROMPT = `You are an expert in financial analysis.
You help users understand market data and make informed decisions.
Always provide sources for your claims and be cautious about predictions.`;// src/routes/agent-factory.ts
const modelOverride = (input.forwardedProps as any)?.model;
return new LLMAgent({
model: modelOverride || config.litellmModel || 'deepseek-chat',
// ...
});The AG-UI server fetches tools from the connected MCP server. To add custom tools:
- Deploy an MCP-UI server with your custom tools
- Connect your AG-UI server to it via
MCP_SERVER_URL
See the mcpui-server-template for creating custom MCP-UI tools.