Executes agents and manages the agent loop.
Note: This SDK is designed to work with the Autohand Code CLI. While the SDK can be used standalone, we recommend installing the CLI for the best experience. Executes agent runs synchronously or asynchronously. Implements the core ReAct loop.
from autohand_agents import RunnerAsync execution with the full ReAct loop.
| Parameter | Type | Description |
|---|---|---|
agent |
Agent |
The agent to run |
prompt |
str |
User's initial prompt |
**kwargs |
— | Passed through to provider calls |
Returns RunResult(final_output, session, turns).
result = await Runner.run(agent, "Analyze main.py")
print(result.final_output)
print(f"Turns: {result.turns}")Synchronous convenience wrapper. Creates its own event loop.
result = Runner.run_sync(agent, "Analyze main.py")
print(result.final_output)Note: Do not call run_sync() from inside an already-running event loop — it will raise RuntimeError. Use await Runner.run() instead.
Streams output chunks in real-time. Each chunk is a string:
data: <text>— text from the LLMtool_result: <name> -> <output>— tool execution result
async for chunk in Runner.run_stream(agent, "Review the code"):
if chunk.startswith("data:"):
print(chunk[5:], end="")
elif chunk.startswith("tool_result:"):
print(f"\n{chunk}")Top-level async generator for streaming queries. Creates a bare agent internally.
from autohand_agents import query
async for message in query("What is 2+2?"):
print(message, end="")| Parameter | Type | Description |
|---|---|---|
prompt |
str |
The user query |
options |
AgentOptions | None |
Tool and behavior configuration |
**kwargs |
— | Passed through |
Returned by all runner methods.
| Attribute | Type | Description |
|---|---|---|
final_output |
str |
The agent's final response |
session |
Session | None |
The conversation session |
turns |
int |
Number of ReAct iterations consumed |