04. Agents, Swarm, Memory, and Workspace
This chapter covers the higher-level workflow features in the Hadamard SDK.
1. Named agents
Register reusable agent roles:
const sdk = await createAgentSdk({
agents: [
{
name: 'reviewer',
description: 'Review work and report the sharpest findings first.',
systemPrompt:
'You are a careful reviewer. Prioritize bugs, regressions, and missing verification.',
},
],
});Run directly through that role:
const result = await sdk.runWithAgent(
'reviewer',
'Review this repository as if you were preparing a release.',
);2. Agent delegation
If named agents are registered, the Hadamard SDK exposes the model-facing Agent tool. Task remains an alias for compatibility.
Useful entry points:
sdk.createTaskTool()sdk.runWithAgent(...)sdk.createAgentSession(...)sdk.tasks.list(),sdk.tasks.wait(...), andsdk.tasks.stop(...)
The Agent tool supports foreground and background execution, named agent instances, per-call model selection, explicit working directories, and isolation: "worktree". Background completion is injected into the parent session as a structured notification. SendMessage can steer a running agent at its next tool boundary or continue a completed persisted agent session.
Agent definitions can also be loaded from Markdown:
---
name: reviewer
description: Review code without editing it
tools: Read, Grep, Glob
disallowedTools: Write, Edit
skills: release-checklist
effort: high
permissionMode: plan
memory: project
background: true
---
Prioritize correctness, regressions, and verification gaps.Place project definitions in .actoviq/agents/*.md and user definitions in ~/.actoviq/agents/*.md. Programmatic definitions override project definitions, which override user definitions. Definitions can also constrain nested agents, require MCP servers, preload skills, and opt into worktree isolation. A dirty delegated worktree is retained and its path is returned; an unchanged worktree is removed automatically.
3. Swarm teammates and side sessions
Use swarm helpers when you want a leader plus teammate pattern:
const team = sdk.swarm.createTeam({
name: 'release-team',
leader: 'lead',
continuous: true,
});Useful operations:
spawn(...)message(...)continueFromMailbox(...)reenter(...)runBackground(...)transcript(...)waitForIdle()
You can now also apply team-level runtime context:
team.setRuntimeContext({
permissions: [{ toolName: 'write_note', behavior: 'ask' }],
approver: ({ publicName }) =>
publicName === 'write_note'
? { behavior: 'allow', reason: 'Approved for teammate work.' }
: { behavior: 'deny', reason: 'Unexpected tool.' },
});Repository example:
4. Workspace helpers
You can create isolated directories before starting an agent session.
Available helpers:
createWorkspace(...)createTempWorkspace(...)createGitWorktreeWorkspace(...)
const workspace = await createTempWorkspace({
prefix: 'actoviq-demo-',
copyFrom: './examples',
});
const sdk = await createAgentSdk({
workDir: workspace.path,
});5. Memory and session memory
The SDK provides:
- relevant memory selection
- session-memory prompt and summary helpers
- compact-state inspection
- automatic session-memory extraction once a session is large enough
Main APIs:
const memory = sdk.memory;
console.log(await memory.findRelevantMemories('how should I release this package?'));At session level:
const extraction = await session.extractMemory();
const state = await session.compactState({
includeSessionMemory: true,
includeSummaryMessage: true,
});Repository examples:
6. Buddy
Buddy is a persistent companion-style context layer. It is not a separate tutorial section in the nav because it works best as part of the wider clean-SDK workflow story.
Useful entry points:
sdk.buddy.get()sdk.buddy.hatch(...)sdk.buddy.mute() / unmute()sdk.buddy.pet()sdk.buddy.getPromptContext()
Example:
await sdk.buddy.hatch({
name: 'Luna',
persona: 'A calm engineering companion.',
});
console.log(await sdk.buddy.state());7. Dream
Dream is the Hadamard SDK's reflective memory-consolidation pass over recent sessions.
const state = await sdk.dreamState();
console.log(state);
const session = await sdk.createSession({ title: 'Dream demo' });
const result = await session.dream({
extraContext: 'Consolidate stable release workflow notes and recurring project facts.',
});
console.log(result.result?.text);
console.log(result.touchedFiles);Auto-dream:
await sdk.memory.updateSettings({ autoDreamEnabled: true });
await sdk.maybeAutoDream({
currentSessionId: session.id,
background: true,
});Repository example:
8. Compact
The Hadamard SDK supports:
- automatic compact
- reactive compact
- API-oriented microcompact shaping
- persisted compact history and continuity metadata
This matters most in long-running sessions and multi-turn task flows.
Manual compact accepts optional summary guidance and returns structured failure state instead of losing continuity:
const result = await session.compact({
force: true,
summaryInstructions: 'Preserve unresolved test failures and exact file paths.',
});
if (!result.compacted) {
console.error(result.reason, result.error, result.consecutiveFailures);
}Compact history and the three-failure circuit breaker are stored with the session, so resumeSession() does not reset recovery state.
Next chapter: