$npx -y skills add parcadei/Continuous-Claude-v3 --skill agentica-sdkBuild Python agents with Agentica SDK - @agentic decorator, spawn(), persistence, MCP integration
| 1 | # Agentica SDK Reference (v0.3.1) |
| 2 | |
| 3 | Build AI agents in Python using the Agentica framework. Agents can implement functions, maintain state, use tools, and coordinate with each other. |
| 4 | |
| 5 | ## When to Use |
| 6 | |
| 7 | Use this skill when: |
| 8 | - Building new Python agents |
| 9 | - Adding agentic capabilities to existing code |
| 10 | - Integrating MCP tools with agents |
| 11 | - Implementing multi-agent orchestration |
| 12 | - Debugging agent behavior |
| 13 | |
| 14 | ## Quick Start |
| 15 | |
| 16 | ### Agentic Function (simplest) |
| 17 | |
| 18 | ```python |
| 19 | from agentica import agentic |
| 20 | |
| 21 | @agentic() |
| 22 | async def add(a: int, b: int) -> int: |
| 23 | """Returns the sum of a and b""" |
| 24 | ... |
| 25 | |
| 26 | result = await add(1, 2) # Agent computes: 3 |
| 27 | ``` |
| 28 | |
| 29 | ### Spawned Agent (more control) |
| 30 | |
| 31 | ```python |
| 32 | from agentica import spawn |
| 33 | |
| 34 | agent = await spawn(premise="You are a truth-teller.") |
| 35 | result: bool = await agent.call(bool, "The Earth is flat") |
| 36 | # Returns: False |
| 37 | ``` |
| 38 | |
| 39 | ## Core Patterns |
| 40 | |
| 41 | ### Return Types |
| 42 | |
| 43 | ```python |
| 44 | # String (default) |
| 45 | result = await agent.call("What is 2+2?") |
| 46 | |
| 47 | # Typed output |
| 48 | result: int = await agent.call(int, "What is 2+2?") |
| 49 | result: dict[str, int] = await agent.call(dict[str, int], "Count items") |
| 50 | |
| 51 | # Side-effects only |
| 52 | await agent.call(None, "Send message to John") |
| 53 | ``` |
| 54 | |
| 55 | ### Premise vs System Prompt |
| 56 | |
| 57 | ```python |
| 58 | # Premise: adds to default system prompt |
| 59 | agent = await spawn(premise="You are a math expert.") |
| 60 | |
| 61 | # System: full control (replaces default) |
| 62 | agent = await spawn(system="You are a JSON-only responder.") |
| 63 | ``` |
| 64 | |
| 65 | ### Passing Tools (Scope) |
| 66 | |
| 67 | ```python |
| 68 | from agentica import agentic, spawn |
| 69 | |
| 70 | # In decorator |
| 71 | @agentic(scope={'web_search': web_search_fn}) |
| 72 | async def researcher(query: str) -> str: |
| 73 | """Research a topic.""" |
| 74 | ... |
| 75 | |
| 76 | # In spawn |
| 77 | agent = await spawn( |
| 78 | premise="Data analyzer", |
| 79 | scope={"analyze": custom_analyzer} |
| 80 | ) |
| 81 | |
| 82 | # Per-call scope |
| 83 | result = await agent.call( |
| 84 | dict[str, int], |
| 85 | "Analyze the dataset", |
| 86 | dataset=data, # Available as 'dataset' |
| 87 | analyzer=custom_fn # Available as 'analyzer' |
| 88 | ) |
| 89 | ``` |
| 90 | |
| 91 | ### SDK Integration Pattern |
| 92 | |
| 93 | ```python |
| 94 | from slack_sdk import WebClient |
| 95 | |
| 96 | slack = WebClient(token=SLACK_TOKEN) |
| 97 | |
| 98 | # Extract specific methods |
| 99 | @agentic(scope={ |
| 100 | 'list_users': slack.users_list, |
| 101 | 'send_message': slack.chat_postMessage |
| 102 | }) |
| 103 | async def team_notifier(message: str) -> None: |
| 104 | """Send team notifications.""" |
| 105 | ... |
| 106 | ``` |
| 107 | |
| 108 | ## Agent Instantiation |
| 109 | |
| 110 | ### spawn() - Async (most cases) |
| 111 | |
| 112 | ```python |
| 113 | agent = await spawn(premise="Helpful assistant") |
| 114 | ``` |
| 115 | |
| 116 | ### Agent() - Sync (for `__init__`) |
| 117 | |
| 118 | ```python |
| 119 | from agentica.agent import Agent |
| 120 | |
| 121 | class CustomAgent: |
| 122 | def __init__(self): |
| 123 | # Synchronous - use Agent() not spawn() |
| 124 | self._brain = Agent( |
| 125 | premise="Specialized assistant", |
| 126 | scope={"tool": some_tool} |
| 127 | ) |
| 128 | |
| 129 | async def run(self, task: str) -> str: |
| 130 | return await self._brain(str, task) |
| 131 | ``` |
| 132 | |
| 133 | ## Model Selection |
| 134 | |
| 135 | ```python |
| 136 | # In spawn |
| 137 | agent = await spawn( |
| 138 | premise="Fast responses", |
| 139 | model="openai:gpt-5" # Default: openai:gpt-4.1 |
| 140 | ) |
| 141 | |
| 142 | # In decorator |
| 143 | @agentic(model="anthropic:claude-sonnet-4.5") |
| 144 | async def analyze(text: str) -> dict: |
| 145 | """Analyze text.""" |
| 146 | ... |
| 147 | ``` |
| 148 | |
| 149 | **Available models:** |
| 150 | - `openai:gpt-3.5-turbo`, `openai:gpt-4o`, `openai:gpt-4.1`, `openai:gpt-5` |
| 151 | - `anthropic:claude-sonnet-4`, `anthropic:claude-opus-4.1` |
| 152 | - `anthropic:claude-sonnet-4.5`, `anthropic:claude-opus-4.5` |
| 153 | - Any OpenRouter slug (e.g., `google/gemini-2.5-flash`) |
| 154 | |
| 155 | ## Persistence (Stateful Agents) |
| 156 | |
| 157 | ```python |
| 158 | @agentic(persist=True) |
| 159 | async def chatbot(message: str) -> str: |
| 160 | """Remembers conversation history.""" |
| 161 | ... |
| 162 | |
| 163 | await chatbot("My name is Alice") |
| 164 | await chatbot("What's my name?") # Knows: Alice |
| 165 | ``` |
| 166 | |
| 167 | For `spawn()` agents, state is automatic across calls to the same instance. |
| 168 | |
| 169 | ## Token Limits |
| 170 | |
| 171 | ```python |
| 172 | from agentica import spawn, MaxTokens |
| 173 | |
| 174 | # Simple limit |
| 175 | agent = await spawn( |
| 176 | premise="Brief responses", |
| 177 | max_tokens=500 |
| 178 | ) |
| 179 | |
| 180 | # Fine-grained control |
| 181 | agent = await spawn( |
| 182 | premise="Controlled output", |
| 183 | max_tokens=MaxTokens( |
| 184 | per_invocation=5000, # Total across all rounds |
| 185 | per_round=1000, # Per inference round |
| 186 | rounds=5 # Max inference rounds |
| 187 | ) |
| 188 | ) |
| 189 | ``` |
| 190 | |
| 191 | ## Token Usage Tracking |
| 192 | |
| 193 | ```python |
| 194 | from agentica import spawn, last_usage, total_usage |
| 195 | |
| 196 | agent = await spawn(premise="You are helpful.") |
| 197 | await agent.call(str, "Hello!") |
| 198 | |
| 199 | # Agent method |
| 200 | usage = agent.last_usage() |
| 201 | print(f"Last: {usage.input_tokens} in, {usage.output_tokens} out") |
| 202 | |
| 203 | usage = agent.total_usage() |
| 204 | print(f"Total: {usage.total_tokens} processed") |
| 205 | |
| 206 | # For @agentic functions |
| 207 | @agentic() |
| 208 | async def my_fn(x: str) -> str: ... |
| 209 | |
| 210 | await my_fn("test") |
| 211 | print(last_usage(my_fn)) |
| 212 | print(total_usage(my_fn)) |
| 213 | ``` |
| 214 | |
| 215 | ## Streaming |
| 216 | |
| 217 | ```python |
| 218 | from agentica import spawn |
| 219 | from agentica.logging.loggers import StreamLogger |
| 220 | import asyncio |
| 221 | |
| 222 | agent = await spawn(premise="You are helpful.") |
| 223 | |
| 224 | stream = StreamLogger() |
| 225 | with stream: |
| 226 | result = asyncio.create_t |