Skip to content

SDK Integration: External orchestration patterns #33

@cpfiffer

Description

@cpfiffer

Context

The Letta Code SDK enables creating agents with custom system prompts and memory configurations on-the-fly. This opens up external orchestration - coordinating multiple agents from outside the agent runtime.

Currently I use Task() to spawn subagents, but that's constrained to predefined agent types. The SDK enables more flexible patterns.

Exploration Areas

1. Dynamic Agent Spawning

Create purpose-built agents for specific tasks:

import { prompt, createSession } from '@letta-ai/letta-code-sdk';

// Spawn a specialist for a specific analysis
const result = await prompt('Analyze this thread for sentiment patterns', {
  systemPrompt: 'You are a sentiment analysis specialist. Be quantitative.',
  memory: [
    { label: 'context', value: threadContent }
  ],
  model: 'haiku',  // Cheap for one-off analysis
  permissionMode: 'bypassPermissions'
});

2. Agent-to-Agent Communication via SDK

Instead of internal Task() calls, external orchestration:

// Orchestrator coordinates Central and Comms
const centralSession = resumeSession(CENTRAL_ID);
const commsSession = resumeSession(COMMS_ID);

// Central analyzes
await centralSession.send('Analyze notification queue, identify what needs response');
const analysis = await collectResult(centralSession);

// Comms drafts based on Central's analysis
await commsSession.send(`Draft responses for: ${analysis}`);
const drafts = await collectResult(commsSession);

// Human reviews drafts, then...
await commsSession.send('Post the approved drafts');

3. Parallel Agent Execution

Run multiple agents concurrently:

// Parallel exploration
const [codeResult, docsResult, testsResult] = await Promise.all([
  prompt('Find authentication code', { model: 'haiku', ... }),
  prompt('Find authentication docs', { model: 'haiku', ... }),
  prompt('Find authentication tests', { model: 'haiku', ... })
]);

// Synthesize with more capable model
const synthesis = await prompt(`
  Code found: ${codeResult.result}
  Docs found: ${docsResult.result}
  Tests found: ${testsResult.result}
  
  Synthesize into a coherent understanding.
`, { model: 'sonnet' });

4. Conversation Branching

Use newConversation to explore multiple paths:

const session1 = resumeSession(agentId, { newConversation: true });
const session2 = resumeSession(agentId, { newConversation: true });

// Same agent, two parallel explorations
await session1.send('Explore approach A...');
await session2.send('Explore approach B...');

// Compare results, pick the better approach

Questions to Explore

  1. When is external orchestration better than internal Task()?
  2. How do agents coordinate state when orchestrated externally?
  3. What's the cost/latency profile of SDK calls vs Task()?
  4. Could this enable "agent swarms" for complex problems?

Potential Applications

  • Debate protocol: Multiple agents argue positions, synthesizer picks best
  • Research pipeline: Scout → Analyst → Writer chain
  • Consensus building: Multiple agents vote on decisions
  • A/B testing: Run same task with different prompts, compare

Caution

External orchestration adds complexity. Should only use when:

  • Task() subagents aren't flexible enough
  • Need cross-agent coordination
  • Building reusable pipelines
  • Experimenting with novel patterns

Not for: simple tasks that Task() handles fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions