do
Single-pass task execution with tools
Single-pass task execution. Can use other ai-functions as tools, but doesn't loop like an agent.
Import
import { do as act } from 'ai-functions'Note: do is a reserved word in JavaScript, import with an alias.
Syntax
do`task description`
do`task with ${context}`Examples
// Simple task
const translation = await act`translate ${text} to Spanish`
// Complex task - picks appropriate tools
const analysis = await act`
analyze this article and give me a summary,
key people mentioned, and action items
${article}
`
// With context
const report = await act`
create a competitive analysis
${{ competitors, ourProduct, market }}
`How It Works
do analyzes the task and picks appropriate tools:
// Might internally call: summarize() + extract() + list()
const analysis = await act`
summarize this article, extract company names,
and list action items
${article}
`do vs Agent
| Feature | do | Full Agent |
|---|---|---|
| Steps | Single pass | Loops until done |
| Tools | Picks once | Re-evaluates each step |
| Complexity | Simple tasks | Complex goals |
| Speed | Fast | Slower |
Think of do as one step of what an agent would do.
Use Cases
// Data processing
const structured = await act`parse ${rawData} into JSON`
// Analysis
const report = await act`analyze ${metrics} and highlight anomalies`
// Transformation
const converted = await act`convert ${doc} to markdown`Was this page helpful?