Agentic SDK for LLM agents with AgentBlit tools
Project description
AgentBlit Python SDK
Build LLM agents that combine AgentBlit remote tools with optional local Python tools. The SDK supports streaming output, approval-gated tools, and short-term memory with automatic summarization.
It now also includes automatic event tracking (agent_init, user_prompt, llm_call, tool_call, and tools_updated) sent as asynchronous batches so agent output is not blocked by analytics delivery.
Upcoming Changes (Next Release)
The upcoming release includes these user-facing updates:
- Agent initialization now supports a complete runtime contract in one place:
approval_callbackfor non-interactive approval flowscustom_toolsfor registering local tools at construction timemax_tool_roundsto cap recursive tool-call loops safely
modelparsing now requiresvendor/modelformat.- System instructions now always include a default tool-usage hint unless already present:
Use tools when they help answer accurately.
- Timeout behavior is consistent across LLM calls and AgentBlit tool HTTP calls via a single
timeoutconfig. - Auto event tracking sends asynchronous
POST /api/events/batchcalls after each run loop.
Requirements
- Python 3.10+
- A supported LLM provider key (OpenAI, Anthropic, Gemini, or OpenRouter)
- An AgentBlit server exposing:
GET /api/tools/listwithX-API-KeyPOST /api/tools/callwith body{ "tool_calls": [...] }POST /api/events/batchwith body{ "events": [...] }
Install
cd agentblit-python
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txt
Run Tests
.venv/bin/python -m pytest -q
Agent Initialization
import asyncio
from agentblit import Agent
async def main() -> None:
agent = Agent(
model="openai/gpt-4o-mini",
api_key="YOUR_LLM_KEY",
agentblit_api_key="YOUR_AGENTBLIT_KEY",
system_prompt="You are a helpful assistant.",
max_history=5,
debug=False,
timeout=30.0,
approval_callback=None,
custom_tools=[],
max_tool_rounds=25,
)
print("agent_id:", agent.agent_id)
print("session_id:", agent.session_id)
async for chunk in agent.run("What is 200 + 30? Use tools if needed."):
print(chunk, end="")
print()
asyncio.run(main())
Parameters
model: LLM id invendor/modelformat, for example:openai/gpt-4o-minianthropic/claude-sonnet-4-0gemini/gemini-2.0-flashopenrouter/openai/gpt-4o-mini
api_key: API key for the LLM provider.agentblit_url: Optional AgentBlit base URL (defaulthttps://console.agentblit.com).agentblit_api_key: API key for AgentBlit (X-API-Keyheader). Required.system_prompt: Optional custom system instruction.max_history: Recent turns to keep verbatim before summarization (default5).debug: Enable verbose logs for LLM and tool activity (defaultFalse).timeout: Timeout in seconds for both LLM and tool HTTP calls (default30.0).approval_callback: Optional async callbackasync (tool_name, args_dict) -> bool.custom_tools: Optional list of local@toolfunctions.max_tool_rounds: Maximum tool/LLM round-trips perrun()call (default25).agent_id: Auto-generated UUID created once perAgentinstance.session_id: Auto-generated UUID used across events for thatAgentinstance.
Features
- Vendor-based model routing from
model. - Agentblit remote tool discovery and execution.
- Local custom tools via
@tool+custom_toolsorregister_tool. - Approval flow for
needs_approvaltools. - Streaming assistant output with
async for. - Memory summarization when history exceeds
max_history. - Debug logging for requests, tool calls, and tool results.
- Automatic batched event tracking at end of each loop.
Tool Decorator
from agentblit import tool
@tool(description="Add two integers.")
def add(a: int, b: int) -> int:
return a + b
@tool(name="risky_email_send", permission_mode="needs_approval")
def send_email(to: str, body: str) -> str:
...
Schemas are inferred from Python type hints.
Quick Usage Pattern
- Create
Agent(...). - Optionally register custom tools.
- Call
agent.run(user_message)and stream chunks. - Reuse the same agent instance to preserve short-term memory.
Event Tracking
The SDK automatically tracks and batches these events:
agent_init(sent once perAgentinstance, includessystem_prompt+ current tools)user_promptllm_call(includes compact request + response JSON,tokens,latency_ms)tool_call(includes request + response JSON,latency_ms)tools_updated(sent when tool list changes in a laterrun()call)
For llm_call events, request payloads are intentionally compact:
system_promptis not repeated in each calltoolsare not repeated in each call- Only the latest message is included
- If chat history was summarized, payload includes the summary message + latest message
The batch is posted to:
POST {AGENTBLIT_URL}/api/events/batch- Headers include
X-API-Key: AGENTBLIT_API_KEY
If event delivery fails, agent execution still completes and the SDK logs a debug message when debug=True.
Custom Events
You can queue custom events that are flushed with the next run() batch:
agent.track("purchase_started", {"plan": "pro", "source": "checkout"})
Examples
[examples/basic_agent.py](examples/basic_agent.py): Remote tools with environment config.[examples/custom_tools.py](examples/custom_tools.py): Local tools + remote tools.
AgentBlit API Reference
- List tools:
GET /api/tools/listwithX-API-Key. - Call tools:
POST /api/tools/callwith:
{
"tool_calls": [
{
"id": "call_1",
"type": "function",
"function": {
"name": "fastmcp_add",
"arguments": "{\"a\":200,\"b\":30}"
}
}
]
}
- Batch events:
POST /api/events/batchwith:
{
"events": [
{
"id": "evt_001",
"session_id": "sess_123",
"agent_id": "abc1",
"timestamp": "2026-04-21T10:30:00.123Z",
"type": "llm_call",
"data": {
"request": {
"model": "gpt-5"
},
"response": {
"content": "Hello"
}
},
"tokens": 245,
"latency_ms": 240
}
]
}
Troubleshooting
If you see RemoteProtocolError: Server disconnected without sending a response, verify protocol alignment:
- Use
https://...if the server expects TLS. - Use
http://...only for plain HTTP servers.
If you see UnicodeEncodeError when calling AgentBlit (tools list, tools call, or events), your AGENTBLIT_API_KEY likely contains non-ASCII characters (often curly “smart quotes” from copy/paste). HTTP headers require ASCII—fix the key in your environment (plain quotes and ASCII-only characters).
If event ingestion returns 400 with “Invalid option” for events[].type, your AgentBlit backend must accept the event types this SDK sends (agent_init, user_prompt, llm_call, tool_call, tools_updated, agent_loop_error, and custom types from track()). Upgrade or configure the console/API accordingly; the SDK does not downgrade or split batches.
Extensibility
- Providers: switch provider/model by changing
model. - Multimodal-ready shape: message flow is compatible with future image/audio additions.
- Minimal API surface:
Agent,tool, andregister_tool.
License
Use and modify as needed for your project.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file agentblit-0.1.0.tar.gz.
File metadata
- Download URL: agentblit-0.1.0.tar.gz
- Upload date:
- Size: 17.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
25730e8570fe79bc1c0cba6c8df4fdcf6ffe2b31bb1c086128a91b1add2501fb
|
|
| MD5 |
674137ac66c9250778d619bd33a674ad
|
|
| BLAKE2b-256 |
e2f0bb748d3a722dee3eca35e90a6afaf735e16ef083d2e5826d924d4b204e89
|
File details
Details for the file agentblit-0.1.0-py3-none-any.whl.
File metadata
- Download URL: agentblit-0.1.0-py3-none-any.whl
- Upload date:
- Size: 15.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3191b2ce30c69d3c8290416feaa54b5538799735108049c7d6bc173a917bf949
|
|
| MD5 |
551f6a8b066cb2994ef3a03a43e2307f
|
|
| BLAKE2b-256 |
00219bcdf5384e2851484110174ee8e0c3977771732c5e5d37eaffad37cd785f
|