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_monitorPlus 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.0000182
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:80803
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
| Provider | Default model | API key |
|---|---|---|
openai | gpt-4o-mini | OPENAI_API_KEY |
anthropic | claude-haiku-4-5-20251001 | ANTHROPIC_API_KEY |
gemini | gemini-2.0-flash-lite | GOOGLE_API_KEY |
ollama | llama3.2 | — (local, no key) |
Switch providers with one argument — LLM(provider="openai") — everything else stays the same.