Skip to main content
This is detailed usage documentation. New to the Agentica SDK? Start with the Quickstart or learn when to use agents vs agentic functions.
Agents are stateful, long‑lived LLM workers you spawn and call repeatedly; they keep conversational history across invocations. We expose two ways to instantiate an agent:
  • direct instantiation via Agent.__init__
  • awaitable instantiation via the spawn function Both return an instance of the Agent class.
Direct instantiation is often useful in functions that must be synchronous e.g. setting attributes of objects in protected methods such as __init__. See here for the API reference of Agent.

Using agents

Agents built with the Agentica SDK accomplish specific tasks using native libraries, code, APIs, and SDKs available in your programming language’s runtime. A single agent represents an evolving history of invocations, each of which may be provided a specific task and set of resources.

When to use agents

Agents work best for longer-running, multi-step tasks where each action depends on prior outcomes, state is preserved, and task-appropriate sets of resources need to be delegated. For single, well-bounded tasks without cross-step context, see Agentic functions.

The basics

Agents can be created with the Agentica SDK using spawn and later called to perform tasks. An agent’s history evolves across its invocations, so you can follow up with tasks in the context of previous results. In Python, provide a return type to receive a result of that runtime type (defaulting to str). In TypeScript, the return type is specified via the generic <T> type parameter.
See the API references: Python | TypeScript.

Use your tools and types

Any function, object, method, or other runtime value can be directly exposed as resources your agent can interact with. No need to set up MCP servers. Expose the full programmatic power of an SDK or API directly to your agent. Make them available when spawning the agent and/or pass per-invocation resources. You can also expose existing remote or local MCP tools by passing an MCP configuration path. See here for more information.
  • Objects passed to scope or as arguments are presented without private methods or field names (fields with a leading _).
  • Async functions in scope are exposed to the REPL as synchronous functions returning Future[T]. The REPL includes a top-level event loop, so agents can await these futures directly and use standard patterns like asyncio.gather().

Multi-agent orchestration

Multi-agent orchestration becomes straightforward. Agents can trigger sub-agents by passing spawn in scope, enabling completely dynamic agent delegation.

Streaming

Stream responses as they are being generated.

Chat with your agents

Create a simple chat loop using streaming. Consume the stream before awaiting the final result to see live generation.
That’s all it takes!

Advanced

You can expose custom exceptions in scope so they can be raised from within execution (see Advanced, including information on logging, retries, rate-limiting and prefix caching). For more examples, see Examples.