Skip to main content

Writing Good Instructions

The instructions field is the most important part of your agent. A well-written prompt is the difference between an agent that works and one that frustrates users.

Structure with Sections

Break your instructions into clear sections so the LLM knows exactly how to behave:

Be Specific About Tool Usage

Don’t just list tools — tell the agent when and how to use them:

Set Boundaries

Tell the agent what it should NOT do:

Choosing the Right Approach

Tool vs Connector

  • Tool: You write the logic. Use when you need custom business logic, database queries, or APIs that aren’t in the connector catalog.
  • Connector: Pre-built integration. Use for supported platforms (HubSpot, Slack, Twilio) — no code needed for the API call itself.

Tool vs Workflow

  • Tool: A single action the agent can call during a conversation.
  • Workflow: A multi-step pipeline that runs independently, with conditions, retries, and different step types.
Use a tool when the agent needs to do something during a conversation. Use a workflow when you need to orchestrate a process with multiple steps.

Identify Patterns

Always call identify() before agent.process(). It connects memory, traces, and metrics to the user.
Without identify(), memory won’t persist correctly between sessions and your traces won’t be linked to specific users in the dashboard.

Tool Patterns

One File Per Tool

Keep tools in separate files. This makes them easier to find, test, and reuse:

Return Structured Data

Always return objects with clear fields. Avoid returning raw strings — the LLM interprets structured data better:

Handle Errors Gracefully

Don’t let tools throw exceptions. Return error information so the LLM can inform the user:

Memory Tips

Choose maxTurns Based on Use Case

Use Summarization for Long Conversations

When conversations exceed maxTurns, older messages are dropped. Use summarizeAfter to preserve context:

Tracking Business Metrics

Use track() to emit events that power dashboards in the Runflow portal. Track what matters for your business:
Use snake_case for event names and keep properties flat (no nested objects). This works best with the dashboard aggregations (count, sum, avg, rate).

Input Validation

Validate the input in main() before processing. This prevents cryptic errors:

Next Steps

Core Concepts

Deep dive into Agents, Memory, Tools

Real-World Examples

See production-ready examples

Observability

Tracing and business metrics

Context Management

User identification patterns