⚙️
Agent SDK — Programmatic Agent Loop
Build custom agents in code — the loop is yours to control
P0Core Pattern
Summary
The Claude Agent SDK provides a programmatic interface for building custom agent loops. Instead of using Claude Code's built-in loop, developers write their own: prompt → tool selection → execution → observation → repeat. The SDK handles API communication and tool marshalling while giving full control over loop behavior.
Technical Details
SDK architecture:
• Agent class: configurable model, tools, instructions, memory
• Tool interface: define custom tools with input/output schemas
• Loop control: developer decides when to continue/stop/escalate
• Context management: automatic window management with manual override
Three integration patterns:
1. Standalone agent: SDK manages everything
2. Embedded agent: SDK runs inside your application
3. Pipeline agent: SDK agents chained in sequence (m8100 → m590 → m495)
Claude Code itself is built on this pattern — the leaked source shows the agent loop is ~200 lines of core logic with 40 tools plugged in. The SDK democratizes this.
Implementation Pattern
TypeScript (conceptual)
// Agent SDK — custom pipeline agent
import Anthropic from '@anthropic-ai/sdk';
const client = new Anthropic();
const tools = [
{ name: 'search_knowledge', description: 'Search m8100 knowledge base',
input_schema: { type: 'object', properties: { query: { type: 'string' } } } },
{ name: 'compile_to_m590', description: 'Send compiled knowledge to m590',
input_schema: { type: 'object', properties: { topic: { type: 'string' }, content: { type: 'string' } } } },
];
async function pipelineAgent(task: string) {
let messages = [{ role: 'user', content: task }];
while (true) {
const response = await client.messages.create({
model: 'claude-sonnet-4-6', max_tokens: 4096, tools, messages
});
if (response.stop_reason === 'end_turn') return response;
for (const block of response.content.filter(b => b.type === 'tool_use')) {
const result = await executeTool(block.name, block.input);
messages.push({ role: 'tool', tool_use_id: block.id, content: result });
}
}
}Architecture Insight
The SDK reveals Claude Code's secret: the magic isn't in the loop, it's in the tools and prompts. A good agent is 10% loop, 40% tools, 50% prompt engineering.
Official / Public Basis
Agent SDK documented at docs.anthropic.com/en/docs/claude-code/sdk. Programmatic access to Claude Code's agent loop.
Governance Concerns
Custom agent loops bypass Claude Code's built-in safety checks. Developers must implement their own permission models, failure budgets, and audit logging.
LightHope Ecosystem Mapping
m8100→m590 pipeline automation, m495 skill execution engine, m8101 AI OS agent layer, m595 game AI reasoning engine