Install and authenticate
These examples target SDK 0.2.0 and require the unified v2 backend. See release availability. Use Python 3.10+. Set AGENTRUN_API_KEY on your server.
bash
python -m pip install agentrun-ai==0.2.0This version-specific registry command becomes available after release. Before release, install the reviewed wheel with python -m pip install ./agentrun_ai-0.2.0-py3-none-any.whl.
Build and run
python
import os
from agentrun import Agent
agent = Agent.create(
api_key=os.environ["AGENTRUN_API_KEY"],
base_url="https://api.grep.ai/api/v2",
prompt="Research companies and cite primary sources.",
)
print("Save build ID:", agent.build_id)
agent.wait_until_ready()
print("Save agent ID:", agent.id)
run = agent.run("Research example.com", idempotency_key="example-001")
print("Save run ID:", run["id"])
result = agent.wait(run["id"])
if result.get("status") == "completed":
print(result.get("report"))
else:
print("Run ended:", result.get("status"))Build generation can take several minutes. Save IDs as soon as they are returned. A wait returning does not imply success; inspect the status. Local timeouts do not stop remote work.
Reuse an agent
python
saved = Agent(api_key=os.environ["AGENTRUN_API_KEY"], agent_id="YOUR_AGENT_ID")
next_run = saved.run("Research another company", idempotency_key="example-002")Reuse a stable idempotency key for a retry of the same logical submission. Use a new key for new work. See the python reference and errors guide.