Agent API¶
Module: src/agent.py
create_cianaparrot_agent¶
Factory function that builds the complete agent with all tools, memory, and persistence.
Returns¶
| Index | Type | Description |
|---|---|---|
agent |
LangGraph CompiledGraph |
The runnable agent |
checkpointer |
AsyncSqliteSaver |
LangGraph conversation persistence |
mcp_client |
MultiServerMCPClient \| None |
MCP client (if configured), needs cleanup on shutdown |
Construction Sequence¶
- Initialize tool configs — calls
init_web_tools(),init_cron_tools(),init_host_tools()(if gateway enabled),init_transcription()(if enabled) - Create base LLM —
init_chat_model("{provider}:{model}")with optional temperature, max_tokens, base_url - Model router (if
model_router.enabled) — initializes all tier models, createsRoutingChatModelas the main model (replacesprovider), addsswitch_modeltool. Each tier is pre-bound with tools viabind_tools(). - Load memory files — scans workspace for
IDENTITY.md,AGENT.md,MEMORY.md - Load MCP tools —
MultiServerMCPClient(config.mcp_servers)if configured - Build tool list —
[web_search, web_fetch, schedule_task, list_tasks, cancel_task]+ optionallyhost_execute+ optionallyswitch_model - Create checkpointer —
AsyncSqliteSaverbacked bydata/checkpoints.db - Create agent —
create_deep_agent()withWorkspaceShellBackend
Usage¶
agent, checkpointer, mcp_client = await create_cianaparrot_agent(config)
# Invoke the agent
result = await agent.ainvoke(
{"messages": [{"role": "user", "content": "Hello"}]},
config={"configurable": {"thread_id": "telegram_12345"}},
)
WorkspaceShellBackend¶
Module: src/backend.py
class WorkspaceShellBackend(SandboxBackendProtocol, FilesystemBackend):
def __init__(self, *, root_dir, virtual_mode=True, timeout=120, max_output_bytes=100_000): ...
Combines DeepAgents' FilesystemBackend (sandboxed file tools) with an allowlisted shell executor.
Parameters¶
| Parameter | Type | Default | Description |
|---|---|---|---|
root_dir |
str |
— | Workspace directory path |
virtual_mode |
bool |
True |
Confine file operations to root_dir |
timeout |
int |
120 |
Shell command timeout in seconds |
max_output_bytes |
int |
100_000 |
Max output before truncation |
File Tools (from FilesystemBackend)¶
With virtual_mode=True, these tools are sandboxed to the workspace:
ls— list directory contentsread_file— read file contentswrite_file— create or overwrite a fileedit_file— apply edits to a fileglob— pattern matchinggrep— content search
Shell Execution¶
def execute(self, command: str) -> ExecuteResponse: ...
async def aexecute(self, command: str) -> ExecuteResponse: ...
Allowed commands (26 total):
curl, wget, python, python3, pip, pip3, git, jq, ffmpeg, ffprobe,
nano-pdf, echo, date, env, whoami, tar, gzip, gunzip, unzip,
wc, sort, uniq, tr, cut, base64, sha256sum, md5sum
Security:
- Command basename must be in
ALLOWED_COMMANDS - Shell metacharacters (
;|&$`) are rejected before parsing - Executed via
subprocess.run(shell=False)— no shell injection - Output truncated at
max_output_bytes