Skip to content

Latest commit

 

History

History
81 lines (57 loc) · 2.43 KB

File metadata and controls

81 lines (57 loc) · 2.43 KB

Runner

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 Runner

Methods

Runner.run(agent, prompt, **kwargs) -> RunResult

Async 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}")

Runner.run_sync(agent, prompt, **kwargs) -> RunResult

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.

Runner.run_stream(agent, prompt, **kwargs) -> AsyncIterator[str]

Streams output chunks in real-time. Each chunk is a string:

  • data: <text> — text from the LLM
  • tool_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}")

query(prompt, options, **kwargs) -> AsyncIterator[str]

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

RunResult

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