Skip to content

Start typing to search the documentation.

Subagents

Last updated View as Markdown

Subagents let an agent delegate a piece of work to a named specialist while it continues to own the interaction. Use them when an agent should ask another configured role to research, classify, or review something and then work with the returned answer.

A subagent is an agent profile declared on another agent. Delegated work runs in a separate child session, rather than continuing the parent agent’s conversation history. The subagent is not a separately addressable agent endpoint.

Define a subagent

Create a named profile with defineAgentProfile(...), then provide it through an agent’s subagents configuration:

import { createAgent, defineAgentProfile } from '@flue/runtime';

const issueClassifier = defineAgentProfile({
  name: 'issue_classifier',
  description: 'Classifies support issues for routing.',
  instructions: 'Return the likely product area and urgency for the reported issue.',
});

export default createAgent(() => ({
  model: 'anthropic/claude-sonnet-4-6',
  instructions: 'Help resolve support requests. Delegate classification when it helps your answer.',
  subagents: [issueClassifier],
}));

In this example, support-assistant can delegate work to issue_classifier. The profile configures the specialist used for delegated tasks; it does not define another agent at /agents/issue_classifier/:id.

Delegate work

An agent with configured subagents can decide to delegate while answering a prompt. Flue gives the agent a built-in task capability that starts a child session for the selected subagent and returns that child’s answer to the parent agent.

The child session receives the delegated request and its own configured context, not the parent’s existing conversation transcript. When a subagent works in a configured sandbox, it uses that same sandbox boundary as its parent. See Sandboxes for controlling workspace and command access.

Use subagents in workflows

A workflow can choose delegation directly when application logic requires work from a particular subagent. Call session.task(...) with the name of a declared subagent, and provide result when the workflow needs validated data:

import { createAgent, defineAgentProfile, type FlueContext } from '@flue/runtime';
import * as v from 'valibot';

const reviewer = defineAgentProfile({
  name: 'reviewer',
  instructions: 'Review the proposed change and identify concrete correctness risks.',
});

const coordinator = createAgent(() => ({
  model: 'anthropic/claude-sonnet-4-6',
  subagents: [reviewer],
}));

const Review = v.object({
  summary: v.string(),
  risks: v.array(v.string()),
});

export async function run({ init, payload }: FlueContext<{ change: string }>) {
  const harness = await init(coordinator);
  const session = await harness.session();
  const response = await session.task(payload.change, {
    agent: 'reviewer',
    result: Review,
  });

  return response.data;
}

Here, the workflow chooses reviewer rather than leaving delegation to the parent agent. See Workflows for workflow orchestration and the Agent API for task options and result types.

Next steps

  • Agents — create agents and reusable agent profiles.
  • Workflows — orchestrate finite agent work in application code.
  • Tools and Skills — give an agent profile capabilities and reusable instructions.
  • Sandboxes — control the workspace available during delegated work.
  • Agent API — look up session.task(...) options and results.
  • Observability — inspect delegated activity alongside other agent work.