Skip to content

Implementation guide

Python quickstart

Install the Python SDK, create an agent from Python, and read its first result.

Browse developer docs

Current: Python quickstart

Install and authenticate

These examples target SDK 0.2.x, which is published on PyPI, and the unified v2 backend. See version and availability. Use Python 3.10+. Set AGENTRUN_API_KEY on your server.

bash

python -m pip install parcha-agentrun==0.2.0

The distribution on PyPI is parcha-agentrun; the module you import is agentrun. Pin the version your integration was reviewed against.

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.