mirror of
https://github.com/hanzoai/python-sdk.git
synced 2026-10-23 20:23:00 +00:00
Twelve ids came from the document's own old->new map; the rest are generated method spellings the map does not carry, read off the regenerated client. Neither set follows a search-and-replace: the document renamed 2014 operations and 21 of those do not reduce to dropping `_v1_` — /tasks and /meet became `*_app` and `*_app_assets` when the SPA and the API stopped sharing a name, and `get_v1_team_transactor_api_v1_statistics` drops only the first, the second being part of the path. Checked, not assumed: every `.get_*`/`.post_*` an example calls resolves against the 7519 methods the client exposes.
54 lines
1.6 KiB
Python
54 lines
1.6 KiB
Python
"""agent — define one, run it, read the run back.
|
|
|
|
POST /v1/agents post_agents
|
|
POST /v1/agents/{ref}/run post_agents_by_ref_run
|
|
GET /v1/agents/{ref}/runs get_agents_by_ref_runs
|
|
|
|
``ref`` is the agent's public id (``agent_...``) OR its org-unique name, which
|
|
is why the run and the read below can both use the name we just created without
|
|
waiting for an id to come back.
|
|
|
|
The read-back is the RUN list rather than the agent record: an agent you just
|
|
created tells you nothing you did not just send, while its runs are the part the
|
|
server actually produced.
|
|
|
|
python -m examples.agent
|
|
"""
|
|
|
|
import time
|
|
|
|
from hanzoai.cloud import AgentsApi, CreateAgentIn
|
|
|
|
from examples.client import MODEL, client, run
|
|
|
|
# Org-unique: a fixed name collides with itself on the second run.
|
|
NAME = f"example-greeter-{time.time_ns()}"
|
|
|
|
|
|
def main() -> None:
|
|
with client() as api:
|
|
agents = AgentsApi(api)
|
|
|
|
created = agents.post_agents(
|
|
CreateAgentIn(
|
|
name=NAME,
|
|
model=MODEL,
|
|
description="Created by the hanzoai SDK agent example.",
|
|
instructions="You greet the user in one short sentence.",
|
|
)
|
|
)
|
|
print(f"created {created.name} ({created.id}) on {created.model}")
|
|
|
|
agents.post_agents_by_ref_run(NAME)
|
|
print("run started")
|
|
|
|
runs = agents.get_agents_by_ref_runs(NAME, limit=5)
|
|
entries = runs.runs or []
|
|
print(f"{len(entries)} run(s):")
|
|
for entry in entries:
|
|
print(f" {entry.to_str()}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
run(main)
|