Python SDK Reference

This page documents the public API of syntic-agent-sdk, the Python distribution of the Syntic Agent SDK. All exports connect to Amara on the Syntic model through api.syntic.ai. Install with pip install syntic-agent-sdk and import from the package root.

from syntic_agent_sdk import query, tool, create_sdk_mcp_server

The Python SDK is fully asynchronous and is designed to run inside an asyncio event loop. Its shapes mirror the TypeScript SDK so concepts transfer directly, with Python idioms substituted for TypeScript ones.

query()

query() is the entry point for running an agent. It is an async generator: iterate it with async for to receive messages as Amara reasons, calls tools, and returns a result.

async def query(
    *,
    prompt: str | AsyncIterable[dict],
    options: dict | None = None,
) -> AsyncIterator[Message]:
    ...

Pass a string prompt for a one-shot request, or an async iterable of user-message dicts for a live streaming session. The generator completes after it yields a result message.

import asyncio
from syntic_agent_sdk import query
 
async def main():
    async for message in query(
        prompt="Refactor utils.py to remove duplication.",
        options={"cwd": ".", "permission_mode": "acceptEdits"},
    ):
        if message.type == "assistant":
            print(message.text, end="", flush=True)
        if message.type == "result":
            print("\nDone:", message.result)
 
asyncio.run(main())

options

The options mapping configures the agent. Keys use snake_case; all are optional.

KeyTypeDescription
cwdstrWorking directory for the agent.
modelstrSyntic model identifier for Amara.
system_promptstr | dictReplace or extend the default system prompt.
permission_modestr"default", "acceptEdits", "plan", or "bypassPermissions".
allowed_toolslist[str]Tools Amara may use.
disallowed_toolslist[str]Tools to exclude.
mcp_serversdictMCP servers to connect, including in-process ones.
can_use_toolCallableAsync approval callback per tool call.
hooksdictLifecycle hook callbacks.
max_turnsintCap on agent loop iterations.
resumestrSession id to resume a persisted conversation.

Messages

Each yielded object has a .type attribute you branch on.

typeMeaning
systemSession initialization and metadata.
assistantText or tool calls from Amara.
userUser or tool-result content.
resultTerminal message with result, usage, and total_cost_usd.

Read usage and total_cost_usd from the result message for cost tracking.

tool and permission callbacks

Define in-process tools with the @tool decorator and expose them with create_sdk_mcp_server(). The decorator declares a name, description, and input schema.

from syntic_agent_sdk import tool, create_sdk_mcp_server
 
@tool("get_weather", "Return the current weather for a city.", {"city": str})
async def get_weather(args):
    return {"content": [{"type": "text", "text": f"Sunny in {args['city']}."}]}
 
server = create_sdk_mcp_server(name="weather", tools=[get_weather])

Pass the server via options["mcp_servers"]. The can_use_tool callback receives the tool name and input and returns an approval decision — allow, deny, or a modified input. See Custom tools and Permissions.