Skip to main content

Python SDK client for the Argentor AI agent framework REST API

Project description

argentor-sdk v1.0.0

Python SDK client for the Argentor AI agent framework REST API.

Installation

pip install argentor-sdk

For development:

pip install argentor-sdk[dev]

Quick Start

from argentor import ArgentorClient

client = ArgentorClient(
    base_url="http://localhost:8080",
    api_key="your-api-key",
)

# Run a task
result = client.run_task(
    role="code_reviewer",
    context="Review the following pull request...",
)
print(result)

# Stream results via SSE
for chunk in client.run_task_stream(
    role="assistant",
    context="Explain how Argentor works",
):
    print(chunk, end="", flush=True)

# Batch execution
batch = client.batch_tasks(
    tasks=[
        {"agent_role": "analyst", "context": "Analyze Q1 sales data"},
        {"agent_role": "analyst", "context": "Analyze Q2 sales data"},
    ],
    max_concurrent=5,
)
print(batch)

# Evaluate a response
evaluation = client.evaluate(
    text="The code looks clean and follows best practices.",
    context="Code review task",
    criteria=["accuracy", "completeness", "helpfulness"],
)
print(evaluation)

# List skills
skills = client.list_skills()
for skill in skills:
    print(skill["name"])

# Execute a skill
result = client.execute_skill("echo", {"text": "Hello, world!"})
print(result)

# Health check
health = client.health()
print(health)

Async Usage

import asyncio
from argentor import AsyncArgentorClient

async def main():
    async with AsyncArgentorClient(
        base_url="http://localhost:8080",
        api_key="your-api-key",
    ) as client:
        # Run a task
        result = await client.run_task(
            role="assistant",
            context="Hello, world!",
        )
        print(result)

        # Stream results
        async for chunk in client.run_task_stream(
            role="assistant",
            context="Explain Argentor",
        ):
            print(chunk)

        # List sessions
        sessions = await client.list_sessions()
        print(sessions)

asyncio.run(main())

Agent SDK (subprocess wrapper)

The agent module wraps the argentor CLI binary as a subprocess, similar to how Claude Agent SDK wraps Claude Code. It communicates via NDJSON over stdin/stdout and works with any LLM provider.

import asyncio
from argentor import query, query_simple, AgentOptions

# Stream events from the agent
async def main():
    async for event in query(
        "What files are in this directory?",
        AgentOptions.claude("sk-your-api-key"),
    ):
        if event.type == "assistant":
            print(event.text)
        elif event.type == "tool_use":
            print(f"[tool] {event.data.get('name')}")
        elif event.is_done:
            print(f"\nDone: {event.text}")

asyncio.run(main())

One-liner convenience functions

from argentor import ask_claude, ask_openai, ask_gemini, ask_ollama

# Each returns the final text output
result = asyncio.run(ask_claude("Explain Argentor", "sk-..."))
result = asyncio.run(ask_openai("Explain Argentor", "sk-..."))
result = asyncio.run(ask_gemini("Explain Argentor", "AIza..."))
result = asyncio.run(ask_ollama("Explain Argentor", "llama3"))

Provider presets

AgentOptions.claude(api_key)   # Anthropic Claude
AgentOptions.openai(api_key)   # OpenAI GPT-4o
AgentOptions.gemini(api_key)   # Google Gemini
AgentOptions.ollama("llama3")  # Local Ollama (no key)

AgentOptions

Parameter Type Default Description
provider str "claude" LLM provider
model str "claude-sonnet-4-20250514" Model name
api_key str "" API key
system_prompt str|None None System prompt override
max_turns int 10 Max agentic turns
temperature float 0.7 Sampling temperature
tools list[str]|None None Tool names (None = builtins)
permission_mode str "default" "default", "strict", "permissive", "plan"
working_directory str|None None Working directory
mcp_servers list[dict]|None None MCP server configs
argentor_binary str|None None Path to binary (auto-detected if omitted)

Error Handling

from argentor import ArgentorClient
from argentor.exceptions import ArgentorAPIError, ArgentorConnectionError

client = ArgentorClient(base_url="http://localhost:8080")

try:
    result = client.run_task(role="assistant", context="Hello")
except ArgentorAPIError as e:
    print(f"API error {e.status_code}: {e.message}")
    print(f"Response body: {e.response_body}")
except ArgentorConnectionError as e:
    print(f"Connection failed: {e.message}")

API Reference

ArgentorClient / AsyncArgentorClient

Both clients expose the same methods. The async client returns awaitables and uses async for for streaming.

Method Description
run_task(role, context, **kwargs) Execute a single agent task
run_task_stream(role, context, **kwargs) Stream task results via SSE
batch_tasks(tasks, max_concurrent=5) Submit a batch of tasks
evaluate(text, context, criteria) Evaluate text against criteria
agent_chat(message, **kwargs) Send a message via agent chat
agent_status() Get agent status
create_session() Create a new session
get_session(session_id) Retrieve a session
list_sessions() List all sessions
delete_session(session_id) Delete a session
list_skills() List registered skills
get_skill(name) Get skill details
execute_skill(name, arguments) Execute a skill
health() Check API health
health_ready() Readiness probe
metrics() Get Prometheus metrics
list_connections() List WebSocket connections
create_persona(tenant_id, agent_role, persona) Create persona
list_personas(tenant_id) List tenant personas
get_usage(tenant_id) Get usage breakdown
webhook_proxy(event, data, **kwargs) Forward a webhook
search_marketplace(query, category) Search skill marketplace
install_skill(name) Install from marketplace

License

AGPL-3.0-only

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

argentor_sdk-1.1.1.tar.gz (26.2 kB view details)

Uploaded Source

Built Distribution

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

argentor_sdk-1.1.1-py3-none-any.whl (25.2 kB view details)

Uploaded Python 3

File details

Details for the file argentor_sdk-1.1.1.tar.gz.

File metadata

  • Download URL: argentor_sdk-1.1.1.tar.gz
  • Upload date:
  • Size: 26.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for argentor_sdk-1.1.1.tar.gz
Algorithm Hash digest
SHA256 b52a9c8b405920d00c05dd86ae29d91b7cdf0d2329284694928d41fc1de13e15
MD5 7d58a72ea4fdb15c2cec31d5c97c0958
BLAKE2b-256 3c601ebe575e1f7f4911e8490a4d6ea765de4e16d119d4264da05b974b3e879e

See more details on using hashes here.

File details

Details for the file argentor_sdk-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: argentor_sdk-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 25.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for argentor_sdk-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 122c4d463b3535e310fd98f82c64ab18651352fb30b2d1e3205a2f3593fd0031
MD5 edcb2dd5c111014140ee1285078a1c1a
BLAKE2b-256 bbfcaf86b5d86789aff2f50c710dbaac3bec23a8643dbdc6ebc8dcb30fe83183

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