Hanzo Agent SDK
hanzo-agent runs agents in Python. An agent is a model reached over an
OpenAI-compatible /v1 API, its instructions, and the Python functions it may
call as tools. It installs as hanzo-agent and imports as agents.
Install
Python 3.9 or newer.
pip install hanzo-agent
First agent
from openai import AsyncOpenAI
from agents import Agent, Runner, set_default_openai_api, set_default_openai_client
set_default_openai_client(AsyncOpenAI(base_url="http://localhost:11434/v1", api_key="ollama"))
set_default_openai_api("chat_completions")
agent = Agent(name="Assistant", instructions="You are a helpful assistant.", model="qwen3:0.6b")
result = Runner.run_sync(agent, "Write a haiku about recursion in programming.")
print(result.final_output)
One run printed:
Recursive function deferring calls,
A loop unrolled with grace,
Ends with a loop.
The two calls before the agent decide where it runs:
set_default_openai_clientnames the endpoint and the key. Above it is a local server on port 11434, Ollama withqwen3:0.6bpulled. For the hosted API passbase_url="https://api.hanzo.ai/v1", a Hanzo API key asapi_key, and a model id fromhttps://api.hanzo.ai/v1/models.set_default_openai_api("chat_completions")sendsPOST /v1/chat/completions. Without it the SDK sendsPOST /v1/responsesinstead.
Tools
A decorated function becomes a tool the model can call:
from agents import function_tool
@function_tool
def get_weather(city: str) -> str:
return f"The weather in {city} is sunny."
agent = Agent(
name="Weather",
instructions="Answer with the get_weather tool.",
tools=[get_weather],
model="qwen3:0.6b",
)
print(Runner.run_sync(agent, "What is the weather in Tokyo?").final_output)
With the setup above it printed The weather in Tokyo is sunny.
Errors and retries
Model calls go through the openai client and follow its rules. A 401, 402 or
403 raises on the first answer (AuthenticationError, APIStatusError,
PermissionDeniedError). A 429 or 5xx is retried twice and then raises;
AsyncOpenAI(..., max_retries=0) sends it once. A 200 whose body is an error
object raises openai.APIError carrying the server's message, as the client
does for an error inside a stream. A <think>…</think> block at the start of a
reply is dropped from final_output and from the history the next turn sends;
result.raw_responses keeps it.
Tracing
Runs create traces and spans and send them nowhere. To export them, add a processor:
from agents import add_trace_processor
from agents.tracing.processors import BackendSpanExporter, BatchTraceProcessor
exporter = BackendSpanExporter(endpoint="https://collector.example/ingest", api_key="...")
add_trace_processor(BatchTraceProcessor(exporter))
The exporter posts batches of JSON to that endpoint with the key as a bearer
token. set_tracing_disabled(True) or OPENAI_AGENTS_DISABLE_TRACING=1 stops
creating them.
Extras
pip install "hanzo-agent[web3]" # agents.extensions.web3: AgentWallet, Web3Wallet, MpcClient
pip install "hanzo-agent[tee]" # agents.extensions.tee: ConfidentialAgent, TEEProvider
agents.network routes a request among several agents and
agents.orchestration runs workflows over registered agents; both are in the
base package.
This repository
The root is also a Go module, github.com/hanzoai/agent, and sdk/ holds
Python, TypeScript and Go clients published under other names. This README
covers hanzo-agent only.
Development
make sync # uv sync --all-extras --all-packages --group dev
make tests # uv run pytest
Metadata
Release files for hanzo-agent 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hanzo_agent-0.1.2.tar.gz | 11.9 MB | Without provenance | Details for hanzo_agent-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hanzo_agent-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for hanzo_agent-0.1.2-py3-none-any.whl |
Total release size: 12.0 MB
Release files / hanzo_agent-0.1.2.tar.gz
| Download URL | hanzo_agent-0.1.2.tar.gz |
|---|---|
| Size | 11.9 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
68ba8df7bc6e8c8e2bd1b4d712114ec1413c84952da62641302fcedaad8fa950
|
|
BLAKE2b-256 checksum How to use checksums |
d1a8aa15a552b582b72795ec82f58febcabf4e8b0ea12f521fe2736d91d42603
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Release files / hanzo_agent-0.1.2-py3-none-any.whl
| Download URL | hanzo_agent-0.1.2-py3-none-any.whl |
|---|---|
| Size | 170.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0f668eb312bea23b40da5642480bf922a6603ae5d485af06cf67af5333304f83
|
|
BLAKE2b-256 checksum How to use checksums |
51e554b492d448098c236a18af9fa5a58e616cf920f3443dd9a67b9959ad4702
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Security for hanzo-agent 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.