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.1.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.1-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: stewrd-1.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 c7b4bcde11feeb82643e4684745d73abc2d8ac38e7c2e9e252445dbfab1b10c4
MD5 d2407d64b870abe72d8599862cb3325b
BLAKE2b-256 e2ede8541797a3f34c78abff0d3a4393c0bed254d78de0aa04637267fc62d497

See more details on using hashes here.

File details

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

File metadata

  • Download URL: stewrd-1.0.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f2f7c71c0a0fc8ccda3706550f867ee4d6ec897ea85977a4f8cca70fd18c17d2
MD5 cbd4dda0f0bd3d56ebb2091bfd3e6692
BLAKE2b-256 62ca865bae782fda9a0c7407f33d9b4f224fa41dd34e834931412b5271472e5a

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