| name | pikku-ai-agent |
| description | Use when building AI agents, chatbots, or LLM-powered assistants with Pikku. Covers pikkuAIAgent, tool registration, memory, streaming, and agent invocation. TRIGGER when: code uses pikkuAIAgent/runAIAgent/streamAIAgent, user asks about AI agents, chatbots, LLM assistants, tool-calling agents, or agent memory/streaming. DO NOT TRIGGER when: user asks about MCP tool exposure (use pikku-mcp) or general function definitions (use pikku-concepts). |
Pikku AI Agent Wiring
Agent Operating Procedure
Use this skill as an execution checklist, not reference material.
- Discover before editing. Prefer OpenCode tools such as
pikku-meta when available; otherwise run the relevant pikku meta ... --json command and inspect only the focused output you need.
- Identify the source files that own the behavior. Do not start by reading generated output,
.pikku, node_modules, vendored packages, or broad build artifacts.
- Make the smallest source change that satisfies the task. Keep generated files generated, and avoid hand-editing SDKs, schema output, or typegen.
- Validate with the narrowest relevant command first, then run
pikku-verify or pikku all when functions, wirings, schemas, or generated clients may have changed.
- If validation fails, fix the source cause and rerun validation. Do not paper over generated errors by editing generated files.
Build AI agents that use Pikku functions as tools. Agents support conversation memory, streaming, and multi-step tool execution.
Before You Start
pikku info functions --verbose
pikku info tags --verbose
See pikku-concepts for the core mental model.
API Reference
pikkuAIAgent(config)
import { pikkuAIAgent } from '#pikku'
pikkuAIAgent({
name: string,
description: string,
instructions: string | string[],
model: string,
tools?: PikkuFunc[],
agents?: AIAgentConfig[],
memory?: {
storage?: string,
vector?: string,
embedder?: string,
lastMessages?: number,
workingMemory?: ZodSchema,
},
maxSteps?: number,
temperature?: number,
toolChoice?: 'auto' | 'required' | 'none',
input?: ZodSchema,
output?: ZodSchema,
tags?: string[],
aiMiddleware?: PikkuAIMiddlewareHooks[],
middleware?: PikkuMiddleware[],
permissions?: PermissionGroup,
})
runAIAgent(name, input, options) — Non-streaming
const result = await runAIAgent(
agentName,
{
message: string,
threadId: string,
resourceId: string,
},
{ singletonServices }
)
result.text
result.steps
result.usage
streamAIAgent(name, input, channel, options) — Streaming
await streamAIAgent(
agentName,
{
message: string,
threadId: string,
resourceId: string,
},
channel,
{ singletonServices }
)
Usage Patterns
Define an Agent
const todoAssistant = pikkuAIAgent({
name: 'todo-assistant',
description: 'A helpful assistant that manages todos',
instructions:
'You help users manage their todo lists. Be concise and helpful.',
model: 'openai/gpt-4o-mini',
tools: [listTodos, createTodo, completeTodo],
memory: {
storage: 'aiStorage',
lastMessages: 20,
},
maxSteps: 5,
temperature: 0.7,
})
Invoke Non-Streaming
const result = await runAIAgent(
'todo-assistant',
{
message: 'Create a task for tomorrow: buy groceries',
threadId: 'thread-123',
resourceId: 'user-456',
},
{ singletonServices }
)
console.log(result.text)
console.log(result.steps)
console.log(result.usage)
Stream Responses
await streamAIAgent(
'todo-assistant',
{
message: 'Create a task for tomorrow',
threadId: 'thread-123',
resourceId: 'user-456',
},
channel,
{ singletonServices }
)
Complete Example
export const listTodos = pikkuSessionlessFunc({
description: 'List all todo items',
func: async ({ db }, { status }) => {
return { todos: await db.listTodos(status) }
},
})
export const createTodo = pikkuFunc({
description: 'Create a new todo item',
func: async ({ db }, { text, priority, dueDate }) => {
return await db.createTodo({ text, priority, dueDate })
},
})
export const completeTodo = pikkuFunc({
description: 'Mark a todo as complete',
func: async ({ db }, { todoId }) => {
return await db.completeTodo(todoId)
},
})
const todoAssistant = pikkuAIAgent({
name: 'todo-assistant',
description: 'A helpful assistant that manages todos',
instructions: `You help users manage their todo lists.
- Be concise and helpful
- When creating todos, infer priority if not specified
- When listing todos, summarize the results`,
model: 'openai/gpt-4o-mini',
tools: [listTodos, createTodo, completeTodo],
memory: {
storage: 'aiStorage',
lastMessages: 20,
},
maxSteps: 5,
temperature: 0.7,
})
wireHTTP({
method: 'post',
route: '/chat',
func: pikkuFunc({
title: 'Chat',
func: async (services, { message, threadId }, wire) => {
const session = await wire.session.get()
return await runAIAgent(
'todo-assistant',
{
message,
threadId,
resourceId: session.userId,
},
{ singletonServices: services }
)
},
}),
})