Primitives.org.ai

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

FeaturedoFull Agent
StepsSingle passLoops until done
ToolsPicks onceRe-evaluates each step
ComplexitySimple tasksComplex goals
SpeedFastSlower

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?

On this page