Learning-oriented guides that take you through a series of steps to complete a project. Follow them in order — explanations of why things work come later, in Explanation.
Tutorial 1 — Your First Agent
Get from zero to a running AI agent in five minutes. You will install Delfhos, set an API key, run a task, and read the Response.
An agent that searches the web and returns a structured answer with cost and timing telemetry.
Install Delfhos
Requires Python 3.9 or newer.
Set your API key
Delfhos works with Google Gemini, OpenAI, and Anthropic. Create a .env file:
Create and run an agent
Pass tools and an llm, then call agent.run().
Read the Response
Every run returns a Response dataclass.
| Field | Type | Description |
|---|---|---|
| text | str | Final answer text |
| status | bool | True = success, False = failure |
| error | str | None | Error message if status is False |
| cost_usd | float | None | Estimated USD cost |
| duration_ms | int | Wall-clock time in milliseconds |
| trace | Any | Full execution trace object |
- Your task was sent to the LLM for code generation
- The LLM generated Python code that calls WebSearch
- That code executed in a sandboxed environment
- The result was returned to the LLM to compose a final answer
- A
Responseobject was returned with the answer, cost, and timing
Tutorial 2 — Connecting to Gmail
Connect an agent to a real Gmail account so it can read and send emails, with human approval required before sending.
An agent connected to Gmail that summarizes unread emails and pauses for your approval before sending anything.
Get OAuth credentials
- Go to the Google Cloud Console and create or select a project
- Enable the Gmail API
- Go to Credentials → Create Credentials → OAuth client ID
- Choose Desktop app, download the JSON file
- Save it as
client_secrets.jsonin your project folder
Build the agent
The first run opens a browser for OAuth consent. After you click Allow, the token is saved at ~/.config/oauth_gmail.json and reused automatically.
Try sending an email (with approval)
Because confirm=["send"] is set, the terminal pauses:
Tutorial 3 — Custom Tools
Expose your own Python functions as agent tools using the @tool decorator. The LLM uses the function name, docstring, and type hints to call it correctly.
Define a tool
Three things are required: the @tool decorator, type hints on every parameter and the return value, and a docstring.
Register and run
Add error handling with ToolException
Raise ToolException to send a recoverable error back to the LLM instead of crashing.
Async tools
Tools can be async. Delfhos handles both sync and async transparently.
Tutorial 4 — Chat Mode and Memory
Build a persistent, context-aware agent. Chat keeps conversation history within a session; Memory persists facts across restarts.
Enable session memory with Chat
Pass a Chat instance in the Agent constructor. The agent remembers context across multiple run() calls.
Start an interactive terminal session
| Command | Action |
|---|---|
| /help | Show available commands |
| /exit | Exit the chat session |
| /stop | Stop the agent (restarts on next input) |
| /clear | Clear the terminal screen |
Add persistent long-term memory
Memory survives across program restarts. Facts are retrieved by semantic similarity before each task.
