TheDocumentation Index
Fetch the complete documentation index at: https://thinkwell.sh/llms.txt
Use this file to discover all available pages before exploring further.
Plan class provides a fluent interface for constructing prompts. You obtain a Plan by calling agent.think() or session.think(), then chain methods to build up your prompt content before executing with .run().
Plan was previously named ThinkBuilder. The old name is still available as a deprecated type alias.Basic Usage
Content Methods
These methods add content to your prompt..text(content)
Adds literal text to the prompt.
.textln(content)
Adds text with a trailing newline. Useful when building prompts incrementally.
.quote(content, label?)
Adds content wrapped in XML-style tags. Use this for user input, documents, or any content that should be clearly delimited from instructions.
.code(content, language?)
Adds content as a fenced Markdown code block. Use this when including source code in your prompt.
Tool Methods
Tools allow the AI agent to call back into your code during prompt execution..tool(name, description, handler) - Simple Form
Register a tool that takes no input parameters.
.tool(name, description, inputSchema, handler) - With Input Schema
Register a tool with typed, validated input. Define the input shape using an interface with @JSONSchema:
- Tells the AI how to format tool calls
- Validates incoming calls at runtime
- Provides TypeScript typing for your handler
Skill Methods
Skills let you give the agent reusable, self-contained capabilities following the Agent Skills standard. Skills support progressive disclosure — only metadata is loaded initially, with full instructions loaded on demand when the agent activates a skill..skill(path) - Stored Skill
Load a skill from a SKILL.md file on disk.
run() time. The skill directory must contain a SKILL.md with YAML frontmatter:
read_skill_file tool.
.skill(definition) - Virtual Skill
Define a skill programmatically without filesystem artifacts.
tools array. These are invoked through the call_skill_tool dispatcher — they don’t appear as individual MCP tools, preserving progressive disclosure.
Skill Name Rules
Skill names must follow the Agent Skills spec:- 1-64 characters
- Lowercase alphanumeric plus hyphens
- No leading, trailing, or consecutive hyphens
Multiple Skills
You can attach multiple skills to a single prompt:Configuration Methods
.cwd(path)
Sets the working directory for the session. This affects where the agent looks for files when using its built-in tools.
Execution
.run()
Executes the prompt and returns the typed result. This is always the final method in the chain.
.stream()
Executes the prompt and returns a ThoughtStream — a handle providing both the final typed result and an async iterable of intermediate progress events.
stream() is called — you don’t need to iterate to start the operation.
ThoughtStream
TheThoughtStream<Output> class provides access to streaming events during prompt execution.
Properties
.result
A Promise<Output> that resolves with the final typed result.
Async Iteration
ThoughtStream implements AsyncIterable<ThoughtEvent>, allowing you to iterate over events with for await:
Execution Semantics
The async iterator and result promise have independent lifecycles:- Iterate without awaiting
.result— the result resolves in the background - Await
.resultwithout iterating — events buffer internally - Do both concurrently — iterate and await simultaneously
- Early termination — break out of the loop and still await
.result
ThoughtEvent Types
Events emitted during streaming are represented as a discriminated union:thought
Streaming internal reasoning / chain-of-thought from the agent.
message
Streaming visible response text from the agent.
tool_start
Emitted when the agent starts using a tool.
kind field indicates the category of tool: "read", "edit", "delete", "move", "search", "execute", "think", "fetch", "switch_mode", or "other".
tool_update
Emitted during tool execution with progress or intermediate content.
content array may include:
{ type: "content"; content: ContentBlock }— text, image, or resource link{ type: "diff"; path: string; oldText: string; newText: string }— file diff{ type: "terminal"; terminalId: string }— terminal output reference
tool_done
Emitted when a tool completes.
plan
Emitted when the agent shares its execution plan.
PlanEntry has:
content: string— description of the plan stepstatus: "pending" | "in_progress" | "completed"priority: "high" | "medium" | "low"
Complete Example
Here’s a complete example showing multiple Plan features:Method Chaining Order
While most methods can be called in any order, we recommend this sequence for readability:.think(schema)- Always first (starts the builder).cwd(path)- Configuration.skill()- Skill attachments.text()/.textln()/.quote()/.code()- Main prompt instructions.tool()- Tool definitions.run()or.stream()- Always last (executes the prompt)
