Skip to main content

Python SDK for the Stewrd Agent API

Project description

stewrd

Python SDK for the Stewrd Agent API.

Install

pip install stewrd

Quickstart

from stewrd import Stewrd

stewrd = Stewrd("sk-stw_your_key")

result = stewrd.agent.run(
    message="Research the top 5 CRM tools",
    capabilities=["research", "documents"],
)

print(result.message)
print(result.files[0].url)

Streaming

for event in stewrd.agent.stream(message="Write a detailed analysis"):
    if event.type == "token":
        print(event.content, end="")
    if event.type == "tool_start":
        print(f"Using {event.tool}...")
    if event.type == "done":
        print(f"\n\nTokens: {event.usage.tokens_used}")

You can also collect the full response after streaming:

stream = stewrd.agent.stream(message="Hello")
response = stream.final_response()
print(response.message)

Configuration

stewrd = Stewrd(
    "sk-stw_...",
    base_url="https://api.stewrd.dev",  # default
    timeout=120.0,                       # default, in seconds
)

API Reference

Stewrd(api_key, *, base_url, timeout)

Create a new client instance.

Param Type Description
api_key str Your Stewrd API key (sk-stw_...)
base_url str API base URL (default: https://api.stewrd.dev)
timeout float Request timeout in seconds (default: 120.0)

stewrd.agent.run(message, *, capabilities, files)

Run the agent synchronously. Returns AgentResponse.

Param Type Description
message str The instruction for the agent
capabilities list[str] Capabilities to enable (e.g. ["research", "documents"])
files list[InputFile] Files to include as context

stewrd.agent.stream(message, *, capabilities, files)

Run the agent with streaming. Returns AgentStream.

Takes the same params as run(). The returned AgentStream is an Iterator[StreamEvent].

Stream Events

Event Fields Description
token content: str A chunk of response text
tool_start tool: str A tool invocation started
tool_end tool: str A tool invocation finished
done response, usage Stream complete with full response
error code: str, message: str An error occurred

StewrdError

Thrown on non-2xx API responses.

from stewrd import Stewrd, StewrdError

try:
    stewrd.agent.run(message="...")
except StewrdError as e:
    print(e.status)   # 401
    print(e.code)     # 'invalid_api_key'
    print(e.message)  # 'Invalid API key'
    print(e.docs)     # 'https://docs.stewrd.dev/errors/invalid_api_key'

Requirements

  • Python 3.9+
  • httpx (installed automatically)

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stewrd-1.1.0.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

stewrd-1.1.0-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file stewrd-1.1.0.tar.gz.

File metadata

  • Download URL: stewrd-1.1.0.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for stewrd-1.1.0.tar.gz
Algorithm Hash digest
SHA256 5337c9a8c94e5a36b91324cc8ea30801f37b3bacdb7bbdd9399a6b0a47ba35db
MD5 19ecaa08d1a1588c1e981b5c3507e1e6
BLAKE2b-256 72ca3e0491fe1495e50e24db1d5f3738d2cdcdbe8729747f41617fac99eace3f

See more details on using hashes here.

File details

Details for the file stewrd-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: stewrd-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for stewrd-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f2683e0dc46443fe65612289875bd61508b960a322256650dfae8ceed29624e6
MD5 a3063854f165136c07768158c4033463
BLAKE2b-256 2f87be6e9662c81e0b9312e88402eccebd28faa4aec575f195c5223afc7daddc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page