This repository is the companion repository for the tutorial How To Build a Durable Agentic AI with Temporal and Python.
The code in this repository supports learning how to build a durable agentic AI with Temporal. It is inspired by Steve Androulakis' agengit AI implementation using Temporal. This tutorial currently is the first step in building out an application similar to Steve's.
Want to learn how to build this application from scratch? Check out the tutorial
There are a lot of AI and Agentic AI tools out there, and more on the way. But why Temporal? Temporal gives this system reliablity, state management, a code-first approach that we really like, built-in observability and easy error handling.
These are the key elements of an agentic framework:
- Goals that a system can accomplish, made up of tools that can execute individual steps
- Agent loops - executing an LLM, executing tools, and eliciting input from an external source such as a human: repeat until goal(s) are done
- Support for tool calls that require input and approval
- Use of an LLM to check human input for relevance before calling the 'real' LLM
- Use of an LLM to summarize and compact the conversation history
- Prompt construction made of system prompts, conversation history, and tool metadata - sent to the LLM to create user questions and confirmations
- Ideally high durability (done in this system with Temporal Workflow and Activities)
To run the code in this repository, use the uv
package and project manager.
Setup the development environment:
uv sync
Make a copy of .env.example
and configure the environment variables.
cp .env.example .env
You can get started by only setting these two variables. If you want to use the Sky Scrapper API or Stripe APIs, you will need to create accounts and provide the keys. (more information in the tutorial)
LLM_MODEL=openai/gpt-4o # or any other model supported by LiteLLM
LLM_KEY=your-api-key-here
In one terminal, run the Temporal development server.
Alternatively you can set the configuration options in your .env
file to connect to Temporal cloud.
temporal server start-dev
In another terminal, run the worker
uv run worker/worker.py
In another terminal, run the API
uv run uvicorn api.main:app --reload
Finally, in another terminal, install and run the frontend
npm install
npx vite
Test the agent in the web browser localhost:5173
You can also test each individual tool using the testing scripts found in the scripts
directory.
You would call them similarly to how you called the worker code above.
uv run scripts/find_events_test.py
uv run scripts/search_flights_test.py
uv run scripts/create_invoice_test.py