from ai_infra.llm import AgentBaseLLMAgent-oriented interface (tool calling, streaming updates, fallbacks). The Agent class provides a simple API for running LLM agents with tools. Tools can be plain Python functions, LangChain tools, or MCP tools. Example - Basic usage:
def get_weather(city: str) -> str:
'''Get weather for a city.'''
return f"Weather in {city}: Sunny, 72°F"
# Simple usage with tools
agent = Agent(tools=[get_weather])
result = agent.run("What's the weather in NYC?")Example - With session memory (conversations persist):
from ai_infra.llm.session import memory
agent = Agent(tools=[...], session=memory())
# Conversation 1 - remembered
agent.run("I'm Bob", session_id="user-123")
agent.run("What's my name?", session_id="user-123") # Knows "Bob"
# Different session - fresh start
agent.run("What's my name?", session_id="user-456") # Doesn't knowExample - Pause and resume (HITL):
from ai_infra.llm.session import memory
agent = Agent(
tools=[dangerous_tool],
session=memory(),
pause_before=["dangerous_tool"], # Pause before this tool
)
result = agent.run("Delete file.txt", session_id="task-1")
if result.paused:
# Show user what's pending, get approval
print(result.pending_action)
# Resume with decision
result = agent.resume(session_id="task-1", approved=True)Example - Production with Postgres:
from ai_infra.llm.session import postgres
agent = Agent(
tools=[...],
session=postgres("postgresql://..."),
)
# Sessions persist across restartsExample - Human approval (sync, per-request):
agent = Agent(
tools=[dangerous_tool],
require_approval=True, # Console prompt for approval
)Example - DeepAgents mode (autonomous multi-step tasks):
from ai_infra.llm import Agent
from ai_infra.llm.session import memory
# Define specialized agents
researcher = Agent(
name="researcher",
description="Searches and analyzes code",
system="You are a code research assistant.",
tools=[search_codebase],
)
writer = Agent(
name="writer",
description="Writes and edits documentation",
system="You are a technical writer.",
)
# Create a deep agent that can delegate to subagents
agent = Agent(
deep=True,
session=memory(),
subagents=[researcher, writer], # Agents auto-convert to subagents
)
# The agent can now autonomously:
# - Read/write/edit files
# - Execute shell commands
# - Delegate to subagents
# - Maintain todo lists
result = agent.run("Refactor the auth module to use JWT tokens")