Start here

Getting Started

Three levels, each one working code — a single call, a monitored conversation, then a tool-using RAG agent. Add a library only when you need what it does.

Install

Each library is separately installable — add only what you need.

pip install -e ./pywrapai
pip install -e ./pywrapai_graph
pip install -e ./pywrapai_monitor

Plus the provider SDK you're calling — pip install anthropic, openai, or google-genai. Ollama needs no SDK; it runs locally.

1

A single call

Just pywrapai. Call any provider, get cost and tokens back automatically.

from pywrapai import LLM

llm      = LLM(provider="anthropic")
response = llm.chat("What is the capital of France?")

print(response.content)              # → Paris is the capital of France.
print(response.usage.input_tokens)   # → 14
print(f"${llm.tokens.total_cost:.6f}")  # → $0.000018
2

History and analytics

Add pywrapai_graph for conversation assembly and pywrapai_monitor for automatic persistence — plus a live dashboard.

from pywrapai         import LLM
from pywrapai_graph   import GraphLLM
from pywrapai_monitor import Monitor

llm     = LLM(provider="anthropic")
graph   = GraphLLM(llm=llm)
monitor = Monitor(db_path="./pywrapai.db")

# Wrap the graph — history and token records are saved automatically
tracked = monitor.wrap(graph, user_id="alice", session_id="chat-001")

r1 = tracked.chat("My name is Alice and I need help with billing.")
r2 = tracked.chat("What did I say my name was?")  # model remembers

monitor.serve(port=8080)  # → http://localhost:8080
3

Tools and RAG

A ReAct agent that calls tools and retrieves document context, with a hard cost cap per run.

from pywrapai        import LLM, Embedder
from pywrapai_graph  import (
    GraphLLM, Agent, AgentConfig,
    ToolRegistry, tool,
    VectorRetriever, InMemoryVectorStore, Document,
)

registry = ToolRegistry()

@tool
def get_weather(city: str) -> str:
    "Get the current weather for a city."
    return f"16 °C, partly cloudy in {city}"

registry.register(get_weather)

store     = InMemoryVectorStore()
retriever = VectorRetriever(embedder=Embedder(provider="openai"), store=store)
retriever.add_documents([
    Document(text="Company policy: refunds are processed within 3 business days.")
])

llm    = LLM(provider="anthropic")
graph  = GraphLLM(llm=llm, retriever=retriever)
config = AgentConfig(max_turns=8, max_cost_usd=0.10)
agent  = Agent(graph=graph, registry=registry, config=config)

result = agent.run("What's the weather in London? And how long do refunds take?")

print(result.content)
print(f"${result.total_cost_usd:.4f}")

Supported providers

ProviderDefault modelAPI key
openaigpt-4o-miniOPENAI_API_KEY
anthropicclaude-haiku-4-5-20251001ANTHROPIC_API_KEY
geminigemini-2.0-flash-liteGOOGLE_API_KEY
ollamallama3.2— (local, no key)

Switch providers with one argument — LLM(provider="openai") — everything else stays the same.

Where to go next