RobutlerRobutler

Python SDK Reference

Install the SDK:

pip install webagents

BaseAgent

The core agent class. Supports decorator-based registration, streaming, and scope-based access control.

from webagents import BaseAgent, tool

agent = BaseAgent(
    name="my-agent",
    instructions="You are a helpful assistant.",
    model="gpt-4o",
    skills={"my_skill": MySkill()},
)

Constructor

ParameterTypeDescription
namestrAgent display name
instructionsstrSystem prompt
modelstr | NoneLLM model identifier
skillslist[Skill]List of skill instances
scopeslist[str]Required auth scopes
toolslistStandalone tool functions
hookslistStandalone hook functions
handoffslistStandalone handoff functions
capabilitiesdictUAMP capabilities

Methods

MethodSignatureDescription
run(input: str, **kwargs) -> RunResponseSingle-turn execution
run_streaming(input: str, **kwargs) -> AsyncGeneratorStreaming execution

Skill

Abstract base class for skills. Skills bundle tools, hooks, handoffs, and endpoints.

from webagents import Skill, tool, hook

class WeatherSkill(Skill):
    @tool(description="Get weather for a city")
    async def get_weather(self, city: str) -> str:
        return f"Weather in {city}: sunny"

    @hook("before_run")
    async def on_before_run(self, data):
        pass

Key Methods

MethodDescription
initialize()Called when the skill is registered with an agent
register_tool(func)Programmatically register a tool
register_hook(func)Programmatically register a hook
register_handoff(func)Programmatically register a handoff
get_context()Access the current execution context

Decorators

@tool

Register a function as an LLM-callable tool.

@tool(name=None, description=None, scope="all", provides=None)
def my_tool(query: str) -> str:
    ...

@prompt

Register a system prompt provider. Multiple prompts are concatenated by priority.

@prompt(priority=50, scope="all")
def system_context() -> str:
    return "Additional context..."

@hook

Register a lifecycle hook.

@hook("before_run", priority=50, scope="all")
async def on_before_run(data):
    ...

Events: before_run, after_run, before_tool, after_tool, on_error

@handoff

Register a handoff handler for multi-agent delegation.

@handoff(name=None, prompt=None, scope="all", subscribes=None, produces=None)
async def delegate_to_specialist(context, query: str):
    ...

@command

Register a slash command (also creates an HTTP endpoint).

@command("/search", description="Search the knowledge base")
async def search(query: str) -> str:
    ...

@http

Register a custom HTTP endpoint on the agent server.

@http("/webhook", method="post", scope="all")
async def handle_webhook(request):
    ...

@websocket

Register a WebSocket endpoint.

@websocket("/stream", scope="all")
async def handle_stream(ws):
    ...

@widget

Register a widget that renders dynamic UI.

@widget(name="chart", description="Render a chart", template="<div>{{ data }}</div>")
def render_chart(data: dict) -> dict:
    return {"data": data}

@observe

Register a non-consuming event observer.

@observe(subscribes=["tool_call", "response"])
async def log_events(event):
    ...

WebAgentsServer

FastAPI-based server for hosting agents.

from webagents.server.core.app import WebAgentsServer, create_server

server = create_server(
    title="My Agents",
    agents=[agent],
    enable_cors=True,
    url_prefix="/api",
)
server.run(port=8080)

create_server

ParameterTypeDescription
agentslist[BaseAgent]Agents to serve
dynamic_agentscallableFactory for dynamic agent creation
enable_corsboolEnable CORS (default: True)
url_prefixstrURL prefix for all routes
enable_file_watchingboolHot-reload agent files
enable_cronboolEnable cron scheduling
storage_backendstr"json" or "sqlite"

Context

Available in tools, hooks, and handoffs via get_context() or as an injected parameter.

from webagents.server.context.context_vars import Context

ctx = self.get_context()
ctx.session  # SessionState
ctx.auth     # AuthInfo
ctx.payment  # PaymentInfo

Agent Loader

Load agents from AGENT.md files or Python modules.

from webagents import AgentLoader

loader = AgentLoader()
agents = loader.load_directory("./agents")
ClassDescription
AgentFileParsed AGENT.md file
AgentMetadataAgent metadata (name, model, skills)
MergedAgentAgent assembled from file + code

Session Management

from webagents import SessionManager, LocalState

manager = SessionManager()
state = manager.get_or_create("session-123")
ClassDescription
LocalStateIn-memory state store
LocalRegistryAgent registry for local development
SessionManagerSession lifecycle management

On this page