Use execute() (or stream()) for real-time streaming responses:
import { execute } from '@deepagents/agent';const stream = await execute(assistant, 'Tell me a story', {});// Stream text chunksfor await (const chunk of stream.textStream) { process.stdout.write(chunk);}// Or get the full textconst text = await stream.text;
Use the instructions() helper for well-structured prompts:
import { agent, instructions } from '@deepagents/agent';const analyst = agent({ name: 'data_analyst', model: openai('gpt-4o'), prompt: instructions({ purpose: [ 'You are a data analyst specializing in financial data.', 'Analyze datasets and provide actionable insights.', ], routine: [ 'Examine the data for patterns and anomalies', 'Calculate relevant statistics', 'Provide clear recommendations', ], }),});
The instructions() helper formats prompts consistently:
# Agent ContextYou are a data analyst specializing in financial data.Analyze datasets and provide actionable insights.Use the following routine to fulfill the task.# Routine1. Examine the data for patterns and anomalies2. Calculate relevant statistics3. Provide clear recommendations
const messages = [ user('What is TypeScript?'), // Previous assistant response would be here user('Can you give me an example?'),];const stream = await execute(assistant, messages, {});