Overview
The Agentica SDK allows agents to write and execute arbitrary Python code in a sandboxed execution environment, while maintaining direct access to objects in your runtime.Why?
The Agentica SDK is built on the premise that code is the most expressive interface through which models can interact with their environment; with the Agentica SDK, agents can manage and engineer their own context, manipulate and return objects by reference and dynamically create their own tools. Check out the blog post Beyond Code Mode: The Agentica SDK.The Mental Model
This is achieved by Warp, the Agentica SDK’s protocol that combines Remote Procedure Call (RPC) with transparent proxying in a Python REPL using a language-agnostic object model.- Sandboxed execution: Agents write Python code that is executed in a safe, isolated environment
- Warp bridge: Functions you pass in scope appear in the sandbox as stubs, but execute in your runtime
- Your code stays local: All actual computation happens in your process with full access to your dependencies
- Objects are warped: Return values from your functions are represented as lightweight proxies in the sandbox, not fully serialized
- Type safety enforced: Return values are validated against your type annotations
Anatomy of an Invocation
Let’s walk through exactly what happens when you call an agentic function (much like an agent). Consider the simplified example below where we have elided portions of the code for clarity.What Happens Behind the Scenes
When is called, it triggers the following interaction. 1. The Agentica SDK sends a request to the underlying model with:- The instruction:
"Look up customer tier, calculate discount, and create order" - The input parameters:
- The signatures and docstrings of functions in scope:
- The details of the types in scope:
OrderResult,CustomerTier - The details of the expected return type,
OrderResult
get_customer_tier, calculate_discount, OrderResult, CustomerTier, etc. The agent can write and evaluate code like normal. Here’s what a sample REPL session could look like.
An example of an agent's output in the Agentica SDK.
Async Functions in the REPL: The REPL includes a top-level event loop, so async functions work naturally. When you pass async functions from your runtime, they appear in the REPL as functions returning
Future[T] (Python async def foo(...) -> T becomes def foo(...) -> Future[T], TypeScript async function foo(...): Promise<T> similarly translates). The agent can use top-level await, and standard patterns like asyncio.gather() work as expected.A breakdown
Let’s break down the key lines from the agent’s output above:get_customer_tier was never defined in the sandbox, but Warp makes it appear to be present in the agent’s execution environment. The stub intercepts the call and sends an RPC to your runtime, where your actual get_customer_tier() executes with access to your database, environment, etc.
CustomerTier object, but it’s actually a lightweight reference to the real object in your runtime.
tier to another function, Warp resolves the proxy back to the real object. Your actual calculate_discount() executes in your runtime with the real CustomerTier object.
OrderResult triggers your actual class constructor in your runtime via Warp, returning another proxy.
3. The result type is validated and returned to your code:
result matches the required return type (OrderResult), which ensures type safety.
Current limitations
Agents and agentic functions currently cannot:- define a type and then return an instance of that type
- return functions, types, or generators that they have defined themselves
Expanded module support: Entire modules (e.g.
numpy, pandas, scipy, sympy), C-implemented functions, and pure lambdas can now be passed from the client into agent scope and warped (proxied by reference) to the sandbox.Bug reports
To report bugs and errors to the Agentica team, please create an issue in the relevant GitHub repo (Python SDK or TypeScript SDK) and include the agent logs (filenames are printed to output). Happy programming!Next Steps
Scope
Learn about passing functions, state, and types
Functions vs Agents
Understand when to use each
Agentic Functions
Dive into agentic function usage
Examples
See practical examples