Skip to main content

Python client for the Tandem autonomous agent engine HTTP + SSE API

Project description

tandem-client

Python client for the Tandem autonomous agent engine HTTP + SSE API.

Install

pip install tandem-client

Python 3.10+ required.

Quick start

import asyncio
from tandem_client import TandemClient

async def main():
    async with TandemClient(
        base_url="http://localhost:39731",
        token="your-engine-token",     # from `tandem-engine token generate`
    ) as client:
        # 1. Create a session
        session_id = await client.sessions.create(
            title="My agent",
            directory="/path/to/my/project",
        )

        # 2. Start an async run
        run = await client.sessions.prompt_async(
            session_id, "Summarize the README and list the top 3 TODOs"
        )

        # 3. Stream the response
        async for event in client.stream(session_id, run.run_id):
            if event.type == "session.response":
                print(event.properties.get("delta", ""), end="", flush=True)
            if event.type in ("run.complete", "run.completed", "run.failed", "session.run.finished"):
                break

asyncio.run(main())

Sync usage (scripts)

from tandem_client import SyncTandemClient

client = SyncTandemClient(base_url="http://localhost:39731", token="...")
session_id = client.sessions.create(title="My agent")
run = client.sessions.prompt_async(session_id, "Analyze this folder")
print(f"Run started: {run.run_id}")
# Note: stream() is async-only; use the async client to receive events
client.close()

API

TandemClient(base_url, token, *, timeout=20.0)

Use as an async context manager or call await client.aclose() manually.

Method Description
await client.health() Check engine readiness
client.stream(session_id, run_id?) Async generator of EngineEvent
client.global_stream() Stream all engine events
await client.list_tool_ids() List all registered tool IDs

client.sessions

Method Description
create(title?, directory?, provider?, model?) Create session, returns session_id
list(q?, page?, page_size?, archived?, scope?, workspace?) List sessions
get(session_id) Get session details
delete(session_id) Delete a session
messages(session_id) Get message history
active_run(session_id) Get active run state
prompt_async(session_id, prompt) Start async run, returns PromptAsyncResult(run_id)
prompt_async_parts(session_id, parts) Start async run with text/file parts

Prompt with file attachments:

run = await client.sessions.prompt_async_parts(
    session_id,
    [
        {
            "type": "file",
            "mime": "image/png",
            "filename": "diagram.png",
            "url": "/srv/tandem/channel_uploads/telegram/667596788/diagram.png",
        },
        {"type": "text", "text": "Explain this diagram."},
    ],
)

client.routines

Method Description
list(family?) List routines or automations
create(options, family?) Create a scheduled routine
delete(routine_id, family?) Delete a routine
run_now(routine_id, family?) Trigger a routine immediately
list_runs(family?, limit?) List recent run records
list_artifacts(run_id, family?) List run artifacts

Create a cron routine:

await client.routines.create({
    "name": "Daily digest",
    "schedule": "0 8 * * *",
    "prompt": "Summarize today's activity and write a report to daily-digest.md",
    "allowed_tools": ["read", "write", "websearch"],
})

client.mcp

await client.mcp.add("arcade", "https://mcp.arcade.ai/mcp")
await client.mcp.connect("arcade")
tools = await client.mcp.list_tools()
Method Description
list() List registered MCP servers
list_tools() List discovered tools
add(name, transport, *, headers?, enabled?) Register an MCP server
connect(name) Connect and discover tools
disconnect(name) Disconnect
refresh(name) Re-discover tools
set_enabled(name, enabled) Enable/disable

client.channels

await client.channels.put("telegram", {"token": "bot:xxx", "allowed_users": ["@you"]})
status = await client.channels.status()
print(status.telegram.connected)

client.permissions

snapshot = await client.permissions.list()
for req in snapshot.requests:
    await client.permissions.reply(req.id, "allow")

client.memory

# Put (SDK accepts `text`; server persists global `content`)
await client.memory.put(
    "Use WAL mode for sqlite in long-lived services.",
    run_id="run-123",
)

# Search
result = await client.memory.search("sqlite wal", limit=5)

# List by user scope
listing = await client.memory.list(user_id="user-123", q="sqlite")

# Promote / demote / delete
await client.memory.promote(listing.items[0].id)
await client.memory.demote(listing.items[0].id, run_id="run-123")
await client.memory.delete(listing.items[0].id)

client.providers

catalog = await client.providers.catalog()
await client.providers.set_defaults("openrouter", "anthropic/claude-3.7-sonnet")
await client.providers.set_api_key("openrouter", "sk-or-...")

Common event types

event.type Description
session.response Text delta in event.properties["delta"]
session.tool_call Tool invocation
session.tool_result Tool result
run.complete Run finished successfully (legacy event name)
run.completed Run finished successfully
run.failed Run failed
session.run.finished Session-scoped terminal run event
permission.request Approval needed
memory.write.succeeded Memory write persisted
memory.search.performed Memory retrieval telemetry
memory.context.injected Prompt context injection telemetry

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

tandem_client-0.3.26.tar.gz (15.9 kB view details)

Uploaded Source

Built Distribution

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

tandem_client-0.3.26-py3-none-any.whl (17.1 kB view details)

Uploaded Python 3

File details

Details for the file tandem_client-0.3.26.tar.gz.

File metadata

  • Download URL: tandem_client-0.3.26.tar.gz
  • Upload date:
  • Size: 15.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tandem_client-0.3.26.tar.gz
Algorithm Hash digest
SHA256 e78a619c272a4deefa83a0815a11ec52ec275885a0cc5e0fb4ac81fc38953cdd
MD5 995f5caac7e7e8abe5b3d6deee6f99d4
BLAKE2b-256 bae46ab19ad1420f0ea5439f33eab85575444718d83dc8ee830a77881bd7247c

See more details on using hashes here.

Provenance

The following attestation bundles were made for tandem_client-0.3.26.tar.gz:

Publisher: publish-registries.yml on frumu-ai/tandem

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tandem_client-0.3.26-py3-none-any.whl.

File metadata

  • Download URL: tandem_client-0.3.26-py3-none-any.whl
  • Upload date:
  • Size: 17.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tandem_client-0.3.26-py3-none-any.whl
Algorithm Hash digest
SHA256 8b25054da61aaaf5054a4c0d72b5b21d2873fdcb37864454bd317f30989dbc73
MD5 c48af0e054fab82ebc6e06dfea3018e4
BLAKE2b-256 2aef343c6ff7c64e73ac0836a3971a69a42a600361d5053caf00cc2a373059f3

See more details on using hashes here.

Provenance

The following attestation bundles were made for tandem_client-0.3.26-py3-none-any.whl:

Publisher: publish-registries.yml on frumu-ai/tandem

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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