Skip to main content

Official Prisme.ai Python SDK for Agent Factory and Storage APIs

Project description

prismeai-sdk-agents

Official Python SDK for the Prisme.ai Agent Factory and Storage APIs.

Installation

pip install prismeai-sdk-agents

Quick Start

from prismeai import PrismeAI

client = PrismeAI(
    api_key="sk-...",
    environment="production",  # or "sandbox"
    agent_factory_workspace_id="your-workspace-id",
    storage_workspace_id="your-storage-workspace-id",  # optional
)

Authentication

# API Key (recommended for server-side)
client = PrismeAI(
    api_key="sk-...",
    agent_factory_workspace_id="ws-id",
)

# Bearer Token (for user-scoped access)
client = PrismeAI(
    bearer_token="eyJ...",
    agent_factory_workspace_id="ws-id",
)

Environment variables PRISMEAI_API_KEY and PRISMEAI_BEARER_TOKEN are also supported.

Sync and Async

The SDK provides both synchronous and asynchronous clients:

# Sync
from prismeai import PrismeAI

with PrismeAI(api_key="sk-...", agent_factory_workspace_id="ws-id") as client:
    agent = client.agents.get("agent-id")

# Async
from prismeai import AsyncPrismeAI

async with AsyncPrismeAI(api_key="sk-...", agent_factory_workspace_id="ws-id") as client:
    agent = await client.agents.get("agent-id")

Usage Examples

Agents

# List agents (auto-pagination)
for agent in client.agents.list():
    print(agent["name"])

# Create an agent
agent = client.agents.create(
    name="My Agent",
    description="A helpful assistant",
    model="claude-sonnet-4-20250514",
    instructions="You are a helpful assistant.",
)

# Get, update, delete
agent = client.agents.get(agent["id"])
updated = client.agents.update(agent["id"], name="Renamed Agent")
client.agents.delete(agent["id"])

# Publish / discard draft
client.agents.publish(agent["id"])
client.agents.discard_draft(agent["id"])

Messages

# Send a message (non-streaming)
response = client.agents.messages.send("agent-id", message="Hello!")
print(response)

# Stream a message (SSE)
with client.agents.messages.stream("agent-id", message="Tell me a story") as stream:
    for event in stream:
        if event.get("type") == "delta":
            print(event.get("content", ""), end="")

Conversations

# List conversations
for conv in client.conversations.list():
    print(conv["id"], conv.get("title"))

# Create and manage
conv = client.conversations.create(agent_id="agent-id")
client.conversations.update(conv["id"], title="New Title")

# Get messages
for msg in client.conversations.messages(conv["id"]):
    print(msg["role"], msg["content"])

A2A (Agent-to-Agent)

# Send message to another agent
result = client.a2a.send("target-agent-id", message="Perform this task")

# Stream A2A response
with client.a2a.send_subscribe("target-agent-id", message="Perform this task") as stream:
    for event in stream:
        print(event)

# Get agent card
card = client.a2a.get_card("agent-id")

Files (Storage)

# Upload a file
file = client.files.upload(b"Hello World", filename="hello.txt")

# List files
for f in client.files.list():
    print(f["name"], f.get("size"))

# Download
data = client.files.download(file["id"])

Vector Stores (Storage)

# Create a vector store
vs = client.vector_stores.create(name="My Knowledge Base")

# Search
results = client.vector_stores.search(vs["id"], query="How to reset password?", limit=5)

# Manage files
client.vector_stores.files.add(vs["id"], file_id="file-id")

for f in client.vector_stores.files.list(vs["id"]):
    print(f["name"], f.get("status"))

Tasks

for task in client.tasks.list(status="running"):
    print(task["id"], task["status"])

task = client.tasks.get("task-id")
client.tasks.cancel("task-id")

Pagination

All list methods return iterables that auto-paginate:

# Auto-pagination with for loop
for agent in client.agents.list():
    print(agent["name"])

# Manual page control
page = client.agents.list(limit=10)
first_page = page.get_page()
print(first_page.data, first_page.total)

# Collect all into list
all_agents = client.agents.list().to_list()

Error Handling

from prismeai import (
    PrismeAIError,
    AuthenticationError,
    RateLimitError,
    NotFoundError,
    ValidationError,
)

try:
    client.agents.get("nonexistent")
except NotFoundError:
    print("Agent not found")
except RateLimitError as e:
    print(f"Rate limited, retry after {e.retry_after}ms")
except AuthenticationError:
    print("Invalid credentials")
except PrismeAIError as e:
    print(e.message, e.status_code)

Async Usage

import asyncio
from prismeai import AsyncPrismeAI

async def main():
    async with AsyncPrismeAI(
        api_key="sk-...",
        agent_factory_workspace_id="ws-id",
    ) as client:
        # All methods are async
        agent = await client.agents.create(name="Async Agent")

        # Async streaming
        stream = await client.agents.messages.stream("agent-id", message="Hello")
        async with stream:
            async for event in stream:
                print(event)

        # Async pagination
        async for agent in client.agents.list():
            print(agent["name"])

asyncio.run(main())

Configuration

Option Type Default Description
api_key str PRISMEAI_API_KEY env API key for authentication
bearer_token str PRISMEAI_BEARER_TOKEN env Bearer token for auth
environment str "production" "sandbox" or "production"
base_url str Custom API base URL (overrides environment)
agent_factory_workspace_id str required Workspace ID for Agent Factory
storage_workspace_id str Workspace ID for Storage API
timeout float 60.0 Request timeout in seconds
max_retries int 2 Max retries on 429/5xx

Requirements

  • Python 3.9+
  • httpx
  • pydantic >= 2.0

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

prismeai_sdk_agents-0.1.0.tar.gz (26.4 kB view details)

Uploaded Source

Built Distribution

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

prismeai_sdk_agents-0.1.0-py3-none-any.whl (37.3 kB view details)

Uploaded Python 3

File details

Details for the file prismeai_sdk_agents-0.1.0.tar.gz.

File metadata

  • Download URL: prismeai_sdk_agents-0.1.0.tar.gz
  • Upload date:
  • Size: 26.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for prismeai_sdk_agents-0.1.0.tar.gz
Algorithm Hash digest
SHA256 19251701778553931e96459db9bf96ba7a764af1acd157d5e4d769c9b7484056
MD5 67a65d79bb24cf195af27a8ddb220392
BLAKE2b-256 ba4d22b568df6331032bdea106f596179b6f571661a3c06ed3a5bef410be5c15

See more details on using hashes here.

File details

Details for the file prismeai_sdk_agents-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for prismeai_sdk_agents-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f56ea1ed15a27542f2b99f87024af2ec761e20e356564226d852981e9399f5e1
MD5 d524ccd59275886330eda1bd43a18af5
BLAKE2b-256 bb609421cb3f0501659f0879d8020b2722685f3e93f071293972ad5925374655

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