Steve Androulakis fcd580dfa6 fix test env
2025-04-16 14:03:32 -07:00
2025-03-12 10:30:42 -04:00
2025-03-20 12:51:40 -04:00
2025-04-10 09:38:13 -04:00
2025-03-12 10:30:42 -04:00
2025-04-10 09:38:13 -04:00
2025-04-12 15:41:47 -04:00
2024-12-31 11:46:57 -08:00
2025-04-10 09:41:14 -04:00
2025-04-11 17:43:34 -04:00
2025-03-14 11:43:51 -04:00
2025-02-27 13:37:01 -06:00
2025-04-16 14:03:32 -07:00
2025-04-16 14:03:32 -07:00
2025-04-16 14:03:32 -07:00
2025-04-16 14:03:32 -07:00
2025-04-14 11:42:40 -04:00

Temporal AI Agent

This demo shows a multi-turn conversation with an AI agent running inside a Temporal workflow. The purpose of the agent is to collect information towards a goal, running tools along the way. There's a simple DSL input for collecting information (currently set up to use mock functions to search for public events, search for flights around those events, then create a test Stripe invoice for the trip).

The AI will respond with clarifications and ask for any missing information to that goal. You can configure it to use ChatGPT 4o, Anthropic Claude, Google Gemini, Deepseek-V3, Grok or a local LLM of your choice using Ollama.

It's really helpful to watch the demo (5 minute YouTube video) to understand how interaction works.

Watch the demo

Why Temporal?

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. For more, check out architecture-decisions.

What is "Agentic AI"?

These are the key elements of an agentic framework:

  1. Goals a human can get done, made up of tools that can execute individual steps
  2. The "agent loop" - call LLM, either call tools or prompt human, repeat until goal(s) are done
  3. Support for tool calls that require human input and approval
  4. Use of an LLM to check human input for relevance before calling the 'real' LLM
  5. Use of an LLM to summarize and compact the conversation history
  6. Prompt construction (made of system prompts, conversation history, and tool metadata - sent to the LLM to create user prompts)
  7. Bonus: durable tool execution via Temporal Activities

For a deeper dive into this, check out the architecture guide.

Setup and Configuration

See the Setup guide.

Customizing Interaction & Tools

See the guide to adding goals and tools.

Architecture

See the architecture guide.

Productionalization & Adding Features

  • In a prod setting, I would need to ensure that payload data is stored separately (e.g. in S3 or a noSQL db - the claim-check pattern), or otherwise 'garbage collected'. Without these techniques, long conversations will fill up the workflow's conversation history, and start to breach Temporal event history payload limits.
  • A single worker can easily support many agent workflows (chats) running at the same time. Currently the workflow ID is the same each time, so it will only run one agent at a time. To run multiple agents, you can use a different workflow ID each time (e.g. by using a UUID or timestamp).
  • Perhaps the UI should show when the LLM response is being retried (i.e. activity retry attempt because the LLM provided bad output)
  • Tests would be nice! See tests.

See the todo for more details.

See the guide to adding goals and tools for more ways you can add features.

Enablement Guide (internal resource for Temporal employees)

Check out the slides here and the enablement guide here (TODO).

Tests

Running the tests requires poe and pytest_asyncio to be installed.

python -m pip install poethepoet
python -m pip install pytest_asyncio

Once you have poe and pytest_asyncio installed you can run:

poetry run poe test
Description
This demo shows a multi-turn conversation with an AI agent running inside a Temporal workflow.
Readme MIT 3.4 MiB
Languages
Python 86.7%
JavaScript 9.6%
C# 2.6%
Makefile 0.4%
CSS 0.3%
Other 0.4%