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.0.0.tar.gz (6.4 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.0.0-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for stewrd-1.0.0.tar.gz
Algorithm Hash digest
SHA256 85308a7bc7f37ee66d1756087afb948b13d60df1db98bb46995050eb0e76f976
MD5 6437f2ccc70fb0bc34f03f0838f2887c
BLAKE2b-256 0593a8011d520a6f2ceca917dc62abbc8f13f9efef124cbf02fa9011c1bbec46

See more details on using hashes here.

File details

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

File metadata

  • Download URL: stewrd-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.4 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.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a56f844cb0d66abb496eae1b29d8b618de6b949103479d8babbee9cf264378ba
MD5 4b71fbf5d6894f1ddd2ed58ac0221c6c
BLAKE2b-256 f509c34b12db1badc9e96fcd3c1fb2da02547fb17f53875004b82434e664c771

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