Skip to main content

Agents

An agent gives a model instructions and tools, then repeats a simple cycle: ask the model what to do, run any requested tool, and give the result back to the model. The run ends when the model returns an answer or a configured limit is reached. Your application provides the model and tool implementations; the shared Rust runtime handles the cycle and configured policies.

The agent itself does not decide where every kind of state belongs. Use a stable session_id plus a persistence store for dialogue that should continue in a later run. Use ContextStore for mutable task data shared with tools or subagents, and MemoryStore for reusable agent knowledge that can be recalled across sessions. Context and memory are in memory unless persistence is configured. See Short-Term Dialogue, Context, and Memory.

import asyncio
from ish import Agent, tool


@tool
async def lookup_order(order_id: str) -> str:
"""Return the current status of an order."""
return f"Order {order_id} is being prepared."


async def main() -> None:
agent = Agent(
name="order_assistant",
model="gpt-4o-mini",
instructions="Answer using the available order lookup tool when needed.",
tools=[lookup_order],
max_turns=6,
)
try:
result = await agent.run("Where is order A-104?")
print(result.content)
finally:
agent.close()


if __name__ == "__main__":
asyncio.run(main())

How the agent loop works​

Before the first model call, the runtime validates the request and applies input checks. If configured, it also loads prior session history. Each turn then asks the model for an answer or tool call. Tool calls pass through permissions and guardrails before execution, and their results become input for the next turn. The runtime can batch eligible independent read-only tools; other calls run in order. Advanced options such as speculative prefetch and compaction are described below.

How independent tools run​

When a model requests multiple independent, read-only tools in one turn, the runtime may run them concurrently. Calls that can write data, require approval, or pass through configured policy hooks remain ordered so checks happen consistently.

The runtime can also prefetch likely read-only work when you configure a draft model. Prefetch uses the run’s token and cost budgets. Context compaction can archive older turns before the model’s context window fills; the agent can retrieve those turns when needed.

Configure run limits​

SettingWhat it controls
max_turnsMaximum number of model/tool cycles
max_total_tokens and max_cost_usdOptional run budgets
context_window_tokensStarts proactive compaction before the context limit
auto_virtualize and virtualize_thresholdStores large tool results out of the prompt
context_offloadSaves large results to files with a short preview
tombstone_observationsReplaces older tool results in the conversation with a short note; tools can still access the original result during the run
enable_circuit_breakerStops repeated identical tool calls

See the API reference for every option and its defaults.

Create an agent​

Each language exposes an agent entry point backed by the same Rust execution loop. Python offers a host-specific @tool decorator for automatic schema inference. TypeScript, Go, C#, and Java register explicit JSON Schema tool descriptors. Rust applications can provide their own tool implementation using the Rust tool interface.

Set the API key required by the selected provider before running the example. See Rust quickstart for Rust source-build setup and model integrations for provider configuration.

Streaming events​

The runtime enriches each StreamEvent with monotonic per-run sequence, trace_id, optional session_id, event_id ("<trace_id>:<16-hex sequence>"), and tool_call_id when present. The terminal "done" event carries the serialized AgentResult payload (usage, model_usages, total_cost_usd, and verification):

async for event in agent.stream("Summarize order A-104."):
if event.event_type == "token":
print(event.data, end="", flush=True)

Results, checkpoints​

AgentResult reports trace_id, content, history, tool_calls_count, duration_ms, prompt_tokens, completion_tokens, reasoning_tokens, total_tokens, total_cost_usd, cost_is_estimate, cost_estimate_complete, model_usages, and verification (VerificationReport with status: "passed", "incomplete", or "not_configured"). Durable runner checkpoints (RunnerCheckpointOptions) bind the saved run to a fingerprint of its tools, instructions, and settings. If these inputs change before resume, ISH stops instead of continuing with a different setup. See SQLite storage for details.

For language-specific option names and builder signatures, consult the package guides:

The shared conformance suite checks selected portable behavior across the six SDKs. Idiomatic method names, signatures, and host integrations can differ by language; the shared behavior covered by the suite is defined by the Rust operations and their conformance cases. The suite does not cover every possible input. See SDK coverage for its scope.

Continue reading​

Reusable, remote agents​

All six language SDKs provide a reusable Agent abstraction; C# and Java expose it alongside their IshClient run APIs. RemoteAgent provides a typed remote-run helper in the host SDKs. For coding tasks, compose the workspace tools, context, skills, memory, planning, policy gates, and child-agent definitions exposed by your SDK. There is currently no one-call coding-agent constructor in the public SDK surface. The ish-code command-line application is a separate Rust application. See each SDK guide for its available components and language-specific API names.