Basic Agent
A simple TypeScript agent with invoke and chat handlers
A simple example demonstrating an agent with both invoke and chat handlers.
The Agent
import { Agent, serve } from '@reminix/runtime';
// Create an agent
const agent = new Agent('echo');
// Handle invoke requests
agent.onInvoke(async (input) => {
const message = (input.message as string) ?? '';
return { output: `You said: ${message}` };
});
// Handle chat requests
agent.onChat(async (messages) => {
const lastMessage = messages[messages.length - 1];
const content = typeof lastMessage?.content === 'string' ? lastMessage.content : '';
return {
message: {
role: 'assistant',
content: `Echo: ${content}`,
},
};
});
serve(agent, { port: 8080 });Running
npx tsx agent.tsTesting
# Health check
curl http://localhost:8080/health
# Agent health
curl http://localhost:8080/agent/echo/health
# Invoke
curl -X POST http://localhost:8080/agent/echo/invoke \
-H "Content-Type: application/json" \
-d '{"input": {"message": "Hello!"}, "stream": false}'
# Chat
curl -X POST http://localhost:8080/agent/echo/chat \
-H "Content-Type: application/json" \
-d '{"messages": [{"role": "user", "content": "Hello!"}], "stream": false}'Response Examples
Invoke response:
{"output": "You said: Hello!"}Chat response:
{"message": {"role": "assistant", "content": "Echo: Hello!"}}Next Steps
- Streaming - Stream responses
- Multi-Agent - Run multiple agents