Skip to content

API Reference

Quick reference for all public classes, functions, and types.


Agent

from exagent import Agent

Base class for all agents.

Constructor pattern

class MyAgent(Agent):
    def __init__(self):
        self.system_description = "..."   # optional — sets the system prompt
        self.set_model(provider, model)   # required
        self.add_tool(my_tool)            # optional, repeatable
        self.load_system_skill("path")    # optional, repeatable
        super().__init__()                # always last

Methods

Method Signature Description
set_model (provider: str, model: str, **kwargs) → Model Configure the LLM. Accepted providers: "openai", "anthropic".
add_tool (tool: Tool \| Callable) → Tool Register a tool. Accepts a Tool instance or a plain function.
add_tools (tools: list) → list[Tool] Register multiple tools at once.
load_system_skill (path: str) → dict Load a skill from a markdown file and register it.
load_system_skills (paths: list[str]) → list[dict] Load multiple skills at once.
run (prompt, max_iterations=10, on_tool_call=None, on_iteration=None) → str Drive the agent loop (blocking) and return the final text.
stream (prompt, max_iterations=10, on_tool_call=None, on_iteration=None) → Iterator[dict] Drive the agent loop (streaming) and yield events.

Attributes

Attribute Type Description
chat_history list[dict] Full conversation history. chat_history[0] is always the system turn.
system_prompt str The assembled system prompt (base description + injected skills).
tools list[Tool] Registered tools.
skills list[dict] Loaded skills. Each dict has name, description, content.
model Model \| None The configured model. None until set_model() is called.

OrchestratorAgent

from exagent.multi_agent.orchestrator import OrchestratorAgent

Extends Agent. Routes tasks to registered specialist agents. All Agent methods are inherited.

Class attributes

Attribute Type Default Description
parallel bool False Allow the model to call multiple agents in one turn. Default is serial. OpenAI only.

Additional method

Method Signature Description
add_agent (agent: Agent, name: str, description: str \| None = None) → None Register a specialist as a callable tool. description falls back to agent.system_description.

Constructor pattern

class MyOrchestrator(OrchestratorAgent):
    parallel = False  # default — serial calls (recommended)

    def __init__(self):
        self.set_model("openai", "gpt-4.1-mini")
        self.add_agent(SpecialistA(), name="specialist_a", description="...")
        self.add_agent(SpecialistB(), name="specialist_b", description="...")
        super().__init__()

@tool decorator

from exagent import tool

Turns a plain Python function into a Tool. Schema is inferred from type hints; description from the docstring.

@tool
def my_function(x: str, y: int = 0) -> str:
    """Does something."""
    ...

# Override name or description
@tool(name="custom_name", description="Custom description.")
def my_function(...):
    ...

Tool

from exagent import Tool

A callable tool the model can invoke.

Constructor

Tool(
    name: str,
    description: str,
    parameters: dict,   # JSON Schema object
    handler: Callable,
)

Methods

Method Description
tool.run(arguments: dict) Invoke the handler with a dict of arguments.
tool.to_anthropic() Return the Anthropic-format tool definition dict.
tool.to_openai() Return the OpenAI Responses API-format tool definition dict.

shell()

from exagent import shell

Start an interactive terminal session with an agent.

shell(
    agent: Agent,
    *,
    stream: bool = True,
    prompt: str = "> ",
) -> None
Command Effect
/help Show available commands
/clear Reset conversation history (keeps system prompt)
/exit / /quit Exit the shell
Ctrl-C / Ctrl-D Exit cleanly

ToolCall

from exagent import ToolCall

Represents a tool-use request emitted by the model.

Attribute Type Description
id str Unique ID for this call.
name str Name of the tool being called.
input dict Arguments the model passed.

ProviderResponse

from exagent import ProviderResponse

The structured result from a model turn.

Attribute Type Description
text str Text content of the response.
tool_calls list[ToolCall] Tool calls requested this turn. Empty if the model stopped.
assistant_message dict \| None Canonical assistant turn appended to history.
stop_reason str \| None Why the model stopped ("end_turn", "tool_use", etc.)

Stream event shapes

All events yielded by agent.stream():

{"type": "text_delta",  "text": str}
{"type": "tool_call",   "tool_call": ToolCall}
{"type": "tool_result", "id": str, "name": str, "content": str, "is_error": bool}
{"type": "done",        "text": str}

Utility functions

from exagent import load_skill, load_file_as_string

load_skill(path: str) -> dict          # parse a skill markdown file
load_file_as_string(path: str) -> str  # read a file as a plain string