In this tutorial, you'll create your first custom agent from scratch. By the end, you'll have a working "Hello World" chat application that demonstrates the core concepts of building with Pika.
What You'll Build
Section titled “What You'll Build”You'll create a simple greeter agent that:
- Responds to user greetings
- Provides information about itself
- Demonstrates basic agent configuration
- Shows how agents appear in the chat interface
Prerequisites
Section titled “Prerequisites”Before starting this tutorial, make sure you have:
- Completed the Quick Start or Installation Guide
- A working Pika installation
- Basic familiarity with TypeScript and AWS CDK
Tutorial Overview
Section titled “Tutorial Overview”Step 1: Understand the Structure
Learn how chat apps and agents are organized in Pika
Step 2: Create Your Agent Configuration
Define your agent's behavior and instructions
Step 3: Deploy Your Service
Deploy to AWS or run locally
Step 4: Test Your Agent
Interact with your new agent in the chat interface
Step 1: Understand the Project Structure
Section titled “Step 1: Understand the Project Structure”Navigate to your Pika project and explore the structure:
my-chat-app/├── services/│ ├── pika/ # Core Pika service (don't modify)│ ├── samples/│ │ └── weather/ # Sample weather service (reference)│ └── custom/ # Your custom services go hereStep 2: Create Your Service Structure
Section titled “Step 2: Create Your Service Structure”Create a new directory for your Hello World service:
cd services/custommkdir hello-worldcd hello-worldInitialize the service:
pnpm initInstall necessary dependencies:
pnpm add @pika/shared aws-cdk-lib constructspnpm add -D typescript @types/nodeCreate a basic tsconfig.json:
{ "extends": "../../../tsconfig.json", "compilerOptions": { "outDir": "./dist", "rootDir": "./src" }, "include": ["src/**/*"], "exclude": ["node_modules", "dist"]}Step 3: Define Your Agent Configuration
Section titled “Step 3: Define Your Agent Configuration”Create the agent configuration file at src/agent-config.ts:
import type { Agent } from '@pika/shared';
export const helloWorldAgent: Agent = { // Unique identifier for your agent agentId: 'hello-world-agent',
// Display name shown in the UI name: 'Hello World Agent',
// Short description description: 'A friendly greeting agent that welcomes users',
// Detailed instructions for the agent's behavior instruction: `You are a friendly Hello World agent built with Pika Platform.
Your purpose is to:1. Greet users warmly when they say hello2. Introduce yourself and explain what you do3. Help users understand that you're their first custom Pika agent
Keep your responses concise and friendly. Always be enthusiastic about beingtheir first custom agent!
When users ask what you can do, explain that you're a simple example agentdesigned to demonstrate Pika's agent configuration system. `.trim(),
// Model configuration model: { modelId: 'anthropic.claude-3-sonnet-20240229-v1:0', temperature: 0.7, maxTokens: 1000 },
// No tools needed for this simple agent tools: []};Step 4: Define Your Chat App Configuration
Section titled “Step 4: Define Your Chat App Configuration”Create the chat app configuration at src/chat-app-config.ts:
import type { ChatApp } from '@pika/shared';
export const helloWorldChatApp: ChatApp = { // Unique identifier for your chat app chatAppId: 'hello-world',
// Display title title: 'Hello World',
// Description shown on the home page description: 'Your first custom Pika agent',
// The agent this chat app uses agentId: 'hello-world-agent',
// User types allowed to access this chat app userTypesAllowed: ['internal-user', 'external-user'],
// Initial greeting message initialMessage: 'Hello! I\'m your first custom Pika agent. Say hi!',
// Suggested prompts shown to users suggestedPrompts: [ 'Hello!', 'What can you do?', 'Tell me about yourself', 'How were you created?' ]};Step 5: Create the CDK Stack
Section titled “Step 5: Create the CDK Stack”Create your infrastructure stack at src/hello-world-stack.ts:
import * as cdk from 'aws-cdk-lib';import { Construct } from 'constructs';import { helloWorldAgent } from './agent-config';import { helloWorldChatApp } from './chat-app-config';
export class HelloWorldStack extends cdk.Stack { constructor(scope: Construct, id: string, props?: cdk.StackProps) { super(scope, id, props);
// Register the agent with Pika new cdk.CustomResource(this, 'RegisterAgent', { serviceToken: cdk.Fn.importValue('PikaAgentRegistryFunctionArn'), properties: { agent: helloWorldAgent } });
// Register the chat app with Pika new cdk.CustomResource(this, 'RegisterChatApp', { serviceToken: cdk.Fn.importValue('PikaChatAppRegistryFunctionArn'), properties: { chatApp: helloWorldChatApp } }); }}Step 6: Create the CDK App
Section titled “Step 6: Create the CDK App”Create the CDK app entry point at bin/hello-world.ts:
#!/usr/bin/env nodeimport * as cdk from 'aws-cdk-lib';import { HelloWorldStack } from '../src/hello-world-stack';
const app = new cdk.App();
new HelloWorldStack(app, 'HelloWorldStack', { env: { account: process.env.CDK_DEFAULT_ACCOUNT, region: process.env.CDK_DEFAULT_REGION }});
app.synth();Update your package.json with CDK scripts:
{ "name": "hello-world-service", "version": "1.0.0", "scripts": { "build": "tsc", "cdk:deploy": "cdk deploy", "cdk:destroy": "cdk destroy" }, "bin": { "hello-world": "bin/hello-world.js" }}Step 7: Create CDK Configuration
Section titled “Step 7: Create CDK Configuration”Create cdk.json in your service root:
{ "app": "node bin/hello-world.js", "requireApproval": "never", "context": { "@aws-cdk/core:enableStackNameDuplicates": true }}Step 8: Deploy Your Service
Section titled “Step 8: Deploy Your Service”First, make sure the core Pika service is deployed:
# From your project rootcd services/pikapnpm buildpnpm run cdk:deployThen deploy your Hello World service:
cd services/custom/hello-worldpnpm buildpnpm run cdk:deployStep 9: Test Your Agent
Section titled “Step 9: Test Your Agent”Start the Pika frontend:
cd apps/pika-chatpnpm devVisit http://localhost:3000 and you should see your "Hello World" chat app listed on the home page!
Click on it to open the chat interface, then try these interactions:
- Type "Hello!" - Your agent should greet you warmly
- Ask "What can you do?" - It should explain it's a demo agent
- Ask "Tell me about yourself" - It should introduce itself
Congratulations!
You've successfully created and deployed your first custom Pika agent!
Understanding What You Built
Section titled “Understanding What You Built”Let's review the key components:
Agent Configuration
Section titled “Agent Configuration”The agent configuration defines:
- Identity (ID, name, description)
- Behavior (instruction/system prompt)
- Capabilities (model, tools)
Chat App Configuration
Section titled “Chat App Configuration”The chat app configuration defines:
- User interface (title, description, initial message)
- Access control (which user types can access)
- User experience (suggested prompts)
CDK Stack
Section titled “CDK Stack”The CDK stack:
- Defines infrastructure as code
- Registers your agent and chat app with Pika
- Keeps your service decoupled from core Pika infrastructure
Next Steps: Enhance Your Agent
Section titled “Next Steps: Enhance Your Agent”Now that you have a working agent, try these enhancements:
Add a Simple Tool
Section titled “Add a Simple Tool”Modify your agent configuration to include a tool:
export const helloWorldAgent: Agent = { // ... previous configuration ...
tools: [{ type: 'inline', toolId: 'get-greeting', name: 'getGreeting', description: 'Get a personalized greeting for a user', parameters: { type: 'object', properties: { userName: { type: 'string', description: 'The user\'s name' }, language: { type: 'string', description: 'Language for the greeting (en, es, fr)', enum: ['en', 'es', 'fr'] } }, required: ['userName', 'language'] }, handler: async (input: { userName: string; language: string }) => { const greetings = { en: `Hello, ${input.userName}! Welcome!`, es: `¡Hola, ${input.userName}! ¡Bienvenido!`, fr: `Bonjour, ${input.userName}! Bienvenue!` };
return { greeting: greetings[input.language] || greetings.en }; } }]};Update the instruction to tell the agent about the tool:
instruction: `You are a friendly Hello World agent built with Pika Platform.
You have access to a getGreeting tool that can generate greetings in differentlanguages (English, Spanish, or French). When users tell you their name, offerto greet them in different languages using this tool.
// ... rest of instruction ...`.trim(),Customize the User Interface
Section titled “Customize the User Interface”Add more suggested prompts:
suggestedPrompts: [ 'Hello!', 'What can you do?', 'Tell me about yourself', 'How were you created?', 'My name is Alice', 'Greet me in Spanish']Add User Type Restrictions
Section titled “Add User Type Restrictions”Restrict to internal users only:
userTypesAllowed: ['internal-user']Common Issues
Section titled “Common Issues”Agent Not Showing Up
Section titled “Agent Not Showing Up”If your agent doesn't appear on the home page:
- Check CloudFormation console for deployment status
- Verify the core Pika service is deployed
- Check CloudWatch logs for registration errors
- Refresh the frontend (clear browser cache if needed)
TypeScript Compilation Errors
Section titled “TypeScript Compilation Errors”# Clean and rebuildpnpm cleanpnpm installpnpm buildCDK Deployment Fails
Section titled “CDK Deployment Fails”Make sure:
- AWS CLI is configured (
aws configure) - Core Pika service is deployed first
- You're in the correct directory when running deploy
Learn More
Section titled “Learn More”Now that you've built your first agent, explore these topics:
Agent Development
Learn more about configuring agents with advanced features
Tools and Integration
Add tools and integrations to make your agent more powerful
Concepts
Understand how Pika works under the hood
Summary
Section titled “Summary”In this tutorial, you:
- Created a new service structure
- Defined an agent configuration
- Defined a chat app configuration
- Created a CDK stack for deployment
- Deployed your service to AWS
- Tested your agent in the chat interface
You now understand the basic building blocks of Pika agents!
Ready to build something more complex? Check out the Capabilities section to see what's possible, or dive into How-To Guides for specific tasks.