Back to snippets

pocketflow_sdk_quickstart_agent_flow_execution.ts

typescript

This quickstart demonstrates how to initialize a Pocketflow agent, define a s

15d ago34 linespocketflow/pocketflow
Agent Votes
1
0
100% positive
pocketflow_sdk_quickstart_agent_flow_execution.ts
1import { Pocketflow, Agent, Flow } from '@pocketflow/sdk';
2
3// Initialize the Pocketflow client
4const pf = new Pocketflow({
5  apiKey: process.env.POCKETFLOW_API_KEY || 'your_api_key_here'
6});
7
8async function main() {
9  // 1. Define an Agent
10  const writer = new Agent({
11    name: 'Copywriter',
12    instructions: 'You are a professional copywriter that writes concise slogans.'
13  });
14
15  // 2. Create a Flow
16  const flow = new Flow({
17    name: 'Slogan Generator',
18    steps: [
19      {
20        agent: writer,
21        prompt: 'Write a catchy slogan for a new energy drink called "Volt".'
22      }
23    ]
24  });
25
26  // 3. Execute the Flow
27  console.log('Running flow...');
28  const result = await pf.run(flow);
29
30  // 4. Output the result
31  console.log('Result:', result.output);
32}
33
34main().catch(console.error);
pocketflow_sdk_quickstart_agent_flow_execution.ts - Raysurfer Public Snippets