SDK tutorial · 1 of 10
Build your first agent
Use Heddle's quickstart runner to prove the model, credentials, conversation state, and streaming output before you design a custom product surface.
Customization depth
Level 1 · Default conversation loop
Hosting depth
One Node.js 20+ process
Documentation status
Runnable reference
Assumptions
- Your project uses Node.js 20 or newer and ESM-compatible TypeScript.
- You installed @roackb2/heddle and configured one supported model credential.
- For this first step, Heddle may own an interactive terminal prompt and plain-text output.
- Resolve the workspace, local state root, model, and credential before opening the conversation.
- Create and persist the conversation session, run turns, and render streaming text and status.
- Record traces and artifacts under the resolved local state root.
- Choose the model and provide its credential.
- Supply product-specific system context and decide when to replace the terminal experience.
- Choose a durable application-data location before treating the local defaults as production storage.
What you will build
You will run a persisted conversational agent from a TypeScript entrypoint. This is an SDK evaluation path, not the full Heddle coding-agent CLI. It deliberately owns the local prompt loop so you can verify the runtime before adding product UI, tools, hosting, or custom storage.
1. Install the runtime package
npm install @roackb2/heddleThe root package is the curated Node.js SDK. Do not import it into browser code; remote browser clients use the separate @roackb2/heddle-remote package later in the hosting path.
2. Configure a model
For the stable OpenAI path:
export OPENAI_API_KEY=your_key_here
export HEDDLE_MODEL=gpt-5.4For Anthropic, use ANTHROPIC_API_KEY and select a Claude model. Local and OpenAI-compatible providers use their documented provider prefixes. Keep credentials in your server environment or secret manager—never put them in prompts, system context, or persisted product records.
3. Create the entrypoint
import { runQuickstartConversationCli } from '@roackb2/heddle'
await runQuickstartConversationCli()If the project does not already have a TypeScript runner, install tsx and run the entrypoint directly:
npm install --save-dev tsx
npx tsx src/agent.tsThe equivalent runnable example in the Heddle repository is:
yarn example:sdk:interactiveWhat the quickstart resolves
With no options, the runner uses:
- the current working directory as
workspaceRoot; .heddleinside that workspace asstateRoot;- the first configured model from
HEDDLE_MODEL,HEDDLE_EXAMPLE_MODEL,OPENAI_MODEL, orANTHROPIC_MODEL, followed by Heddle's built-in OpenAI default; - credential preflight that fails before session creation when the selected model cannot authenticate;
- no default hard step budget;
- no automatic memory-maintenance run;
- persisted conversation state and a plain-text streaming host.
The runner prints the selected model and credential source. That is useful evidence when a machine has more than one possible credential path.
Add a small amount of product behavior
Stay on the quickstart layer while the terminal loop is still acceptable:
import { runQuickstartConversationCli } from '@roackb2/heddle'
await runQuickstartConversationCli({
model: process.env.MY_PRODUCT_MODEL,
systemContext: 'You help users understand their project workspace.',
promptLabel: 'project> ',
credentialPreflight: {
missingCredentialHint: 'Configure a model credential for this product first.',
},
})Only set maxSteps when your product intentionally wants a hard turn budget. An arbitrary small value can stop a valid tool workflow before it finishes.
Verify the checkpoint
Before continuing, confirm that:
- credential preflight identifies the model and auth source;
- a prompt produces streamed output and a final result;
- the process creates durable state beneath the configured
stateRoot; - a later prompt in the same run continues the persisted conversation.
Move to the conversation engine when your product needs its own rendering, commands, approval UI, session browser, or lifecycle.