Skip to main content

Subagents

A subagent lets an agent delegate a focused task to another agent with its own working context. Use synchronous delegation when the parent needs the result before continuing. Use background delegation when several tasks can run while the parent does other work:

Define a portable subagent​

Use a declarative definition when the child should be configured the same way across SDKs. Python also accepts an in-process Agent instance as a child; that host-language composition is Python-specific.

from ish import Agent, SubagentDefinition, tool


@tool
def lookup_status(service: str) -> str:
"""Return the current status for a service."""
return f"{service}: operational"

# Build a coordinator with a declarative child agent.
coordinator = Agent(
name="coordinator",
model="gpt-4o-mini",
instructions="Delegate service checks when useful and summarize the result.",
tools=[lookup_status],
subagents=[
SubagentDefinition(
name="service_researcher",
description="Check the current status of a service.",
instructions="Check the service status using lookup_status and report concisely.",
tools=["lookup_status"],
max_turns=6,
return_direct=True,
)
],
)

  1. Synchronous isolated delegation (task / SubagentDispatchTool): The parent delegates a focused subtask, blocks for the child's completion, and receives the child's final content.
  2. Parallel background delegation (AsyncDelegationFleet): The parent launches multiple non-blocking child runs tracked durably in AsyncJobStore (ish_async_jobs in SQLite WAL) and checks, updates, cancels, or reconciles them across turns.

How delegation works​

The runtime creates an isolated child run for each definition while reusing the configured tool implementations. It enforces context boundaries and recursion limits consistently across SDKs:

What is shared​

A child receives only the tools and context configured for it. It cannot modify the parent's context directly. The parent receives the child's final report and can decide how to use it. Nested delegation is allowed only when explicitly configured and is bounded to prevent runaway recursion.

For background work, AsyncDelegationFleet exposes tools to launch, check, update, cancel, list, and reconcile tasks. If a process stops during a task, inspect any external effects before marking the task complete or retrying it.

Isolated child subagents​

Portable subagent definitions share the same Rust task schema, tool allowlisting (tools), context scoping (pass_by_reference), recursion checks (max_depth), and return_direct behavior across every language. Python also offers a host-specific subagents=[researcher] shorthand that wraps another Python Agent instance directly, while TypeScript (HostSubagent), Go (HostExecute), C# (HostExecute), and Java (hostExecute) support host subagent callbacks alongside portable definitions.

Parallel background delegation (AsyncDelegationFleet)​

When a coordinator needs to launch multiple independent subagent tasks concurrently and check, update, cancel, or reconcile them across turns, use AsyncDelegationFleet. Each launched task runs in the background with trace_id = "async-subagent-<job_id>", persists status in AsyncJobStore (in-memory or SQLite WAL table ish_async_jobs with owner_pid, owner_token, and expiring worker leases), and exposes the same six model-callable tools across every SDK:

ToolPurpose
launch_subagentStart a background task
check_subagentRead task status and result
update_subagentAdd guidance to a task
cancel_subagentStop a running task
list_subagentsReview known tasks
reconcile_subagentRecord a verified outcome after interruption

If a worker disappears while a task is running, the task is marked interrupted. Reconcile it only after checking whether its external work took effect.

from ish import Agent, AsyncDelegationFleet

researcher = Agent(
name="service_researcher",
model="gpt-4o-mini",
instructions="Check service status and return a brief report.",
)

fleet = AsyncDelegationFleet(subagents=[researcher])
coordinator = Agent(
name="fleet_coordinator",
model="gpt-4o-mini",
instructions="Launch background checks and summarize results once completed.",
tools=fleet.get_tools(),
)

Subagents are useful when a delegated task needs a separate model interaction. They still consume model and tool resources, and the parent may need to call the child's delegation tool explicitly. Context sharing and isolation depend on the child configuration; see the context guide.

Remote agents​

RemoteAgent is a typed SDK wrapper in Python, TypeScript, Go, C#, and Java, backed by the shared Rust remote_agent.run operation. It invokes a remote ISH server; local child-agent definitions continue to run under the parent agent's shared orchestration.