Skip to main content

Module agent

Module agent 

Source
Expand description

Agent block — one-shot Claude Code spawn driven by an AgentRef and a per-call task template.

Phase 1.5 PR 2: replaces the original stub ({ response: "[stub]" }) with a real invocation of agents::runner::run_agent. The runner spawns claude --print --output-format=stream-json, drains its stdout through ClaudeTranslator, and produces a structured AgentRunResult that this function flattens into the snake_case drone-block output shape.

Block config (node.data):

  • task — required. Mustache-style template resolved against scope.outputs + scope.vars before spawning.
  • agent_ref — optional. Object matching AgentRef shape (camelCase keys): identityId, memoryId, instanceName, workingDirectory. All fields optional; missing = blank agent.
  • max_turns — optional. Hard cap on claude turns.
  • output_schema — optional. The few short fields the reply must carry (agent_output.rs): the reply format is added to the prompt, and the reply is checked against it. The validated fields are the block’s output, read as {{<this_block_id>.output.<field>}}; a reply that does not fit fails the block.

Output (snake_case to match other drone blocks — see spec §4.5):

{
  "response": "<text>",
  "tokens": { "input": .., "output": .., "cache_creation": .., "cache_read": .. },
  "cost_usd": 0.001,
  "status": "done",
  "output": { "<field>": .. }   // only with `output_schema`
}

Downstream blocks read {{<this_block_id>.response}} for the agent’s reply and {{<this_block_id>.cost_usd}} for accounting.

Functions§

agent_ref_of 🔒
The node’s agent_ref: its identity and memory, or a blank agent when it has none.
flatten 🔒
The block’s output, flattened to snake_case to match other drone block outputs (the AgentRunResult’s serde camelCase is for the IPC seam with the frontend, NOT for drone templates — see spec §4.5 NOTE), with the validated output fields when the node declared a schema.
resolved_allowance 🔒
The block’s allow_commands with each command line’s {{references}} resolved, as the task is: the line the agent runs is the one that was allowed.
run