createAgentSession()
Create an agent session with automatic discovery of extensions, skills, and tools.
Parameters
CreateAgentSessionOptions
Configuration for the agent session
string
default:"process.cwd()"
Working directory for project-local discovery
string
default:"~/.pi/agent"
Global config directory
Auth storage for credentials. Default: AuthStorage.create(agentDir/auth.json)
Model registry. Default: new ModelRegistry(authStorage, agentDir/models.json)
Model to use. Default: from settings, else first available
Thinking level. Default: from settings, else ‘medium’ (clamped to model capabilities)
Array<{ model: Model<any>; thinkingLevel: ThinkingLevel }>
Models available for cycling (Ctrl+P in interactive mode)
Tool[]
default:"codingTools"
Built-in tools to use. Default: [read, bash, edit, write]
Custom tools to register in addition to built-in tools
Resource loader. When omitted, DefaultResourceLoader is used
Session manager. Default: SessionManager.create(cwd)
Settings manager. Default: SettingsManager.create(cwd, agentDir)
Returns
The created agent session
Extensions result for UI context setup in interactive mode
Warning if session was restored with a different model than saved
Examples
Minimal Usage
Uses all defaults: discovers skills, extensions, tools, and context files from cwd and ~/.pi/agent.
With Explicit Model
Full Control
When using a custom cwd, you must use tool factory functions to ensure tools resolve paths relative to your cwd, not process.cwd().
These use process.cwd() as the working directory:
Full access mode: [read, bash, edit, write]
Read-only exploration: [read, grep, find, ls]
All available built-in tools as a keyed object
Type Exports