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.
- Python
- TypeScript
- Rust
- Go
- C#
- Java
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,
)
],
)
import { Agent } from "ish-harness";
const coordinator = new Agent({
name: "coordinator",
model: { provider: "openai_chat", name: "gpt-4o-mini" },
instructions: "Delegate service checks when useful and summarize the result.",
tools: [
{
name: "lookup_status",
description: "Return the current status of a service.",
parameters: {
type: "object",
properties: { service: { type: "string" } },
required: ["service"],
},
execute: async (args) => {
const { service } = args as { service: string };
return `${service}: operational`;
},
},
],
subagents: [
{
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,
},
],
});
use std::sync::Arc;
use ish_harness::{
data_plane::tool_backend::ToolBackend,
subagents::build_dispatch_tool,
Agent, OpenAIModel, RunnerConfig,
};
use serde_json::json;
fn build_coordinator(
model: Arc<OpenAIModel>,
parent_tools: Vec<Arc<dyn ToolBackend>>,
) -> Result<Agent, String> {
let model_dyn: Arc<dyn ish_harness::ModelBackend> = model.clone();
let definitions = json!([
{
"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
}
]);
let mut tools = parent_tools;
if let Some(task_tool) = build_dispatch_tool(
&definitions,
&model_dyn,
&tools,
&RunnerConfig::default(),
0,
Vec::new(),
3,
false,
0,
)? {
tools.push(task_tool);
}
Agent::builder(model)
.name("coordinator")
.instructions("Delegate service checks when useful and summarize the result.")
.tools(tools)
.build()
}
coordinator := ish.NewAgent(client, ish.AgentRunRequest{
AgentName: "coordinator",
Model: &ish.AgentModel{Provider: "openai_chat", Name: "gpt-4o-mini"},
SystemPrompt: ish.StringPtr("Delegate service checks when useful and summarize the result."),
Tools: []ish.AgentTool{
{
Name: "lookup_status",
Description: "Return the current status for a service.",
Parameters: map[string]any{
"type": "object",
"properties": map[string]any{
"service": map[string]any{"type": "string"},
},
"required": []string{"service"},
},
Execute: func(ctx context.Context, args map[string]any) (any, error) {
return fmt.Sprintf("%v: operational", args["service"]), nil
},
},
},
Subagents: []ish.AgentSubagent{
{
Name: "service_researcher",
Description: "Check the current status of a service.",
Instructions: "Check the service status using lookup_status and report concisely.",
Tools: []string{"lookup_status"},
MaxTurns: ish.IntPtr(6),
ReturnDirect: ish.BoolPtr(true),
},
},
})
using System.Text.Json;
using Ish.Harness;
using var schema = JsonDocument.Parse(
"""{"type":"object","properties":{"service":{"type":"string"}},"required":["service"]}""");
var request = new AgentRunRequest
{
AgentName = "coordinator",
Model = new AgentModel { Provider = "openai_chat", Name = "gpt-4o-mini" },
SystemPrompt = "Delegate service checks when useful and summarize the result.",
UserPrompt = "Check the status of billing-api.",
Tools =
[
new AgentTool
{
Name = "lookup_status",
Description = "Return the current status for a service.",
Parameters = schema.RootElement.Clone(),
Execute = (args, _) => ValueTask.FromResult<object?>(
$"{args.GetProperty("service").GetString()}: operational"),
},
],
Subagents =
[
new AgentSubagent
{
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"],
MaxTurns = 6,
ReturnDirect = true,
},
],
};
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.ishharness.IshClient;
import java.util.List;
var schema = new ObjectMapper().readTree(
"{\"type\":\"object\",\"properties\":{\"service\":{\"type\":\"string\"}},\"required\":[\"service\"]}");
var child = new IshClient.AgentSubagent(
"service_researcher",
"Check the service status using lookup_status and report concisely.")
.description("Check the current status of a service.")
.tools(List.of("lookup_status"))
.maxTurns(6)
.returnDirect(true);
var request = new IshClient.AgentRequest(
"gpt-4o-mini",
"Delegate service checks when useful and summarize the result.",
"Check the status of billing-api.")
.provider("openai_chat")
.agentName("coordinator")
.tool(
"lookup_status",
"Return the current status for a service.",
schema,
args -> args.path("service").asText() + ": operational")
.subagents(List.of(child));
- Synchronous isolated delegation (
task/SubagentDispatchTool): The parent delegates a focused subtask, blocks for the child's completion, and receives the child's final content. - Parallel background delegation (
AsyncDelegationFleet): The parent launches multiple non-blocking child runs tracked durably inAsyncJobStore(ish_async_jobsin 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:
| Tool | Purpose |
|---|---|
launch_subagent | Start a background task |
check_subagent | Read task status and result |
update_subagent | Add guidance to a task |
cancel_subagent | Stop a running task |
list_subagents | Review known tasks |
reconcile_subagent | Record 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.
- Python
- TypeScript
- Rust
- Go
- C#
- Java
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(),
)
import { Agent, AsyncDelegationFleet, createClient } from "ish-harness";
const client = createClient();
const fleet = new AsyncDelegationFleet(client, {
service_researcher: async (prompt) => `Checked: ${prompt} -> operational`,
});
const coordinator = new Agent({
name: "fleet_coordinator",
model: { provider: "openai_chat", name: "gpt-4o-mini" },
instructions: "Launch background checks and summarize results once completed.",
tools: fleet.tools(),
});
use std::sync::Arc;
use ish_harness::{Agent, AsyncDelegationFleet, OpenAIModel};
fn build_fleet_coordinator(
model: Arc<OpenAIModel>,
researcher: Arc<Agent>,
) -> Result<Agent, String> {
let fleet = Arc::new(AsyncDelegationFleet::new(None)?);
fleet.register_subagent(researcher)?;
Agent::builder(model)
.name("fleet_coordinator")
.instructions("Launch background checks and summarize results once completed.")
.async_subagents(fleet)
.build()
}
fleet, err := ish.NewAsyncDelegationFleet(client, "")
if err != nil {
panic(err)
}
defer fleet.Close()
err = fleet.RegisterSubagent("service_researcher", func(ctx context.Context, prompt string) (string, error) {
return fmt.Sprintf("Checked: %s -> operational", prompt), nil
})
if err != nil {
panic(err)
}
coordinator := ish.NewAgent(client, ish.AgentRunRequest{
AgentName: "fleet_coordinator",
Model: &ish.AgentModel{Provider: "openai_chat", Name: "gpt-4o-mini"},
SystemPrompt: ish.StringPtr("Launch background checks and summarize results once completed."),
Tools: fleet.GetTools(),
})
using Ish.Harness;
await using var fleet = new AsyncDelegationFleet(ish);
fleet.RegisterSubagent("service_researcher", (prompt, _) =>
Task.FromResult($"Checked: {prompt} -> operational"));
var result = ish.Run(new AgentRunRequest
{
AgentName = "fleet_coordinator",
Model = new AgentModel { Provider = "openai_chat", Name = "gpt-4o-mini" },
SystemPrompt = "Launch background checks and summarize results once completed.",
UserPrompt = "Check billing-api and auth-api in the background.",
Tools = fleet.GetTools(),
});
import io.github.ishharness.AsyncDelegationFleet;
import io.github.ishharness.IshClient;
import java.util.concurrent.CompletableFuture;
try (var fleet = new AsyncDelegationFleet(ish)) {
fleet.registerSubagent(
"service_researcher",
prompt -> CompletableFuture.completedFuture("Checked: " + prompt + " -> operational"));
var request = new IshClient.AgentRequest(
"gpt-4o-mini",
"Launch background checks and summarize results once completed.",
"Check billing-api and auth-api in the background.")
.provider("openai_chat")
.agentName("fleet_coordinator");
fleet.addTools(request);
var result = ish.runAgent(request);
System.out.println(result.path("content").asText());
}
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.