Complete reference for all public exports from @bradygaster/squad-sdk. Each section includes types, functions, and usage examples.
import {
// Resolution
resolveSquad, resolveGlobalSquadPath, ensureSquadPath,
// Runtime
MODELS, TIMEOUTS, AGENT_ROLES,
loadConfig, loadConfigSync,
// Agents
onboardAgent,
// Casting
CastingEngine, CastingHistory,
// Coordinator
SquadCoordinator, selectResponseTier, getTier,
// Tools
defineTool, ToolRegistry,
// OTel
initializeOTel, shutdownOTel, getTracer, getMeter,
bridgeEventBusToOTel, createOTelTransport,
initSquadTelemetry,
} from '@bradygaster/squad-sdk';Functions to locate Squad directories.
Find .squad/ directory starting from a path and walking up to the project root. Throws if not found.
const squadPath = resolveSquad();
const squadPath = resolveSquad('/home/user/project/src');Get the platform-specific Squad config directory (~/.config/squad/ on Linux, ~/Library/Application Support/squad/ on macOS, %APPDATA%\squad\ on Windows). Squad 2.0 keeps only externalized project state there (projects/<projectKey>/, see squad externalize); no squad is resolved from it.
Like resolveSquad(), but creates the directory if it doesn't exist.
All supported models, organized by tier.
MODELS.FALLBACK_CHAINS.premium; // ['gpt-5.6-sol', 'claude-opus-5', ...]
MODELS.FALLBACK_CHAINS.standard; // ['gpt-5.6-terra', 'claude-sonnet-5', ...]
MODELS.FALLBACK_CHAINS.fast; // ['gpt-5.6-luna', 'claude-haiku-4.5', 'gpt-5.4-mini', ...]Standard timeout values for agent operations.
TIMEOUTS.agentInitMs; // 30000 (30s)
TIMEOUTS.agentExecuteMs; // 300000 (5 min)
TIMEOUTS.coordinatorRouteMs; // 5000 (5s)Standard agent roles and their default properties.
Load configuration asynchronously. Reads squad.config.ts (if present), parses routing/model overrides, validates schemas.
const config = await loadConfig('./.squad');
console.log(config.team.name);
console.log(Object.keys(config.agents));Types:
interface ConfigLoadResult {
team: {
name: string;
root: string;
description?: string;
};
agents?: Record<string, AgentConfig>;
routing?: RoutingConfig;
models?: ModelConfig;
}
interface AgentConfig {
role: string;
model?: string;
tools?: string[];
status?: 'active' | 'inactive';
}Synchronous version of loadConfig().
Create a new agent directory, charter, and history file.
const result = await onboardAgent({
teamRoot: './.squad',
agentName: 'data-analyst',
role: 'backend',
displayName: 'Dana — Data Analyst',
projectContext: 'A recipe sharing app with PostgreSQL and React',
userName: 'Alice',
});Types:
interface OnboardOptions {
teamRoot: string;
agentName: string;
role: string;
displayName?: string;
projectContext?: string;
userName?: string;
charterTemplate?: string;
}
interface OnboardResult {
createdFiles: string[];
agentDir: string;
charterPath: string;
historyPath: string;
}Generate agent personas from universe themes.
const engine = new CastingEngine({
universes: ['The Wire', 'Seinfeld'],
activeUniverse: 'The Wire',
});
const members = await engine.castTeam([
{ role: 'lead', title: 'Lead Developer' },
{ role: 'backend', title: 'Backend Engineer' },
]);Track all casting decisions over time.
const history = new CastingHistory('./.squad/casting');
const records = history.getRecordsByAgent('lead');
const previousCast = history.findByName('Stringer');Types:
interface CastMember {
name: string;
role: string;
universe: string;
displayName: string;
}Main class for routing work to agents.
const coordinator = new SquadCoordinator({
teamRoot: './.squad',
enableParallel: true,
});
await coordinator.initialize();
const decision = await coordinator.route('refactor the API');
console.log(decision.tier); // 'standard' or 'full'
console.log(decision.agents); // ['backend', 'tester']
console.log(decision.parallel); // true if multi-agent
console.log(decision.rationale); // Explanation of routing choice
await coordinator.execute(decision, 'refactor the API');
await coordinator.shutdown();Types:
interface RoutingDecision {
tier: ResponseTier;
agents: string[];
parallel: boolean;
rationale: string;
}
type ResponseTier = 'direct' | 'lightweight' | 'standard' | 'full';Choose the right response tier for a task.
Get configuration for a specific tier (max agents, default model, available tools).
Define a new tool with typed parameters.
const myTool = defineTool<{ query: string }>({
name: 'search_docs',
description: 'Search project documentation',
parameters: {
type: 'object',
properties: {
query: { type: 'string', description: 'Search query' },
},
required: ['query'],
},
handler: async (args) => {
const results = await searchDocs(args.query);
return {
textResultForLlm: `Found ${results.length} results`,
resultType: 'success',
toolTelemetry: { resultCount: results.length },
};
},
});Manage the built-in tool set.
import { ToolRegistry } from '@bradygaster/squad-sdk/tools';
import type { FanOutDependencies } from '@bradygaster/squad-sdk/coordinator';
const registry = new ToolRegistry('./.squad');
const tools = registry.getTools();
const agentTools = registry.getToolsForAgent(['squad_route', 'squad_decide']);Constructor: new ToolRegistry(squadRoot?, sessionPoolGetter?, storage?, state?, fanOutDepsGetter?)
fanOutDepsGetter— Required forsquad_routeto spawn sessions viaspawnParallel. Returns aFanOutDependenciesobject (from@bradygaster/squad-sdk/coordinator). Without it,squad_routereturnsresultType: 'failure'witherror: 'fan-out-deps-unavailable'.state— When provided,squad_routevalidates that the target agent exists in the team roster before spawning.- Agent names must match
/^[a-zA-Z0-9_-]+$/. Spawn errors are sanitized before being returned to the LLM.
Built-in tools:
| Tool | Purpose |
|---|---|
squad_route |
Route a task to another agent (requires fanOutDepsGetter) |
squad_decide |
Write decisions to the inbox |
squad_memory |
Append to agent history |
squad_status |
Query session pool state |
squad_skill |
Read/write agent skills |
Three-layer observability API for traces, metrics, and telemetry.
import { initializeOTel, shutdownOTel, getTracer, getMeter } from '@bradygaster/squad-sdk';
await initializeOTel({
endpoint: 'http://localhost:4318',
serviceName: 'my-squad',
});
const tracer = getTracer('my-component');
const meter = getMeter('my-component');
await shutdownOTel();import { bridgeEventBusToOTel, createOTelTransport } from '@bradygaster/squad-sdk';
const unsubscribe = bridgeEventBusToOTel(eventBus);
const transport = createOTelTransport();import { initSquadTelemetry } from '@bradygaster/squad-sdk';
const telemetry = await initSquadTelemetry({
endpoint: 'http://localhost:4318',
serviceName: 'my-squad',
eventBus: myEventBus,
});
await telemetry.shutdown();Convert an agent response to a readable stream.
const stream = createReadableStream(agentResponse);
const reader = stream.getReader();
let result;
while (!(result = await reader.read()).done) {
console.log(result.value);
}Load upstream sources from .squad/upstream.json.
Resolve all upstreams and return their inherited content.
Build a markdown block of all inherited context (for agent charters).
Build a human-readable display of upstream sources (for squad status).
| Export | Type | Module | Purpose |
|---|---|---|---|
resolveSquad |
function | resolution | Find .squad directory |
resolveGlobalSquadPath |
function | resolution | Platform config dir (externalized project state only) |
ensureSquadPath |
function | resolution | Find or create .squad |
MODELS |
constant | runtime/constants | Model catalog |
TIMEOUTS |
constant | runtime/constants | Standard timeouts |
AGENT_ROLES |
constant | runtime/constants | Agent role definitions |
loadConfig |
function | config | Async config loading |
loadConfigSync |
function | config | Sync config loading |
onboardAgent |
function | agents | Create new agent |
CastingEngine |
class | casting | Generate personas |
CastingHistory |
class | casting | Track castings |
SquadCoordinator |
class | coordinator | Route and orchestrate |
selectResponseTier |
function | coordinator | Choose response tier |
getTier |
function | coordinator | Get tier config |
defineTool |
function | tools | Define custom tool |
ToolRegistry |
class | tools | Manage tools |
initializeOTel |
function | runtime/otel | Init OTel providers |
shutdownOTel |
function | runtime/otel | Shutdown OTel |
getTracer |
function | runtime/otel | Get tracer |
getMeter |
function | runtime/otel | Get meter |
bridgeEventBusToOTel |
function | runtime/otel-bridge | EventBus → OTel |
createOTelTransport |
function | runtime/otel-bridge | Create OTel transport |
initSquadTelemetry |
function | runtime/otel-init | One-call setup |
- SDK Reference — Quick reference for common SDK usage
- Integration Guide — Connecting to the Copilot SDK
- Tools & Hooks — Custom tools and hook pipeline
- Installation — Getting started