Skip to content

Temporal & AI Agent Memory and State #150

Open

Description

@nyghtowl

Project link

https://github.com/temporal-community/temporal-ai-agent-memory-state-stripe

Language

Python

Short description (max 256 chars)

What should your agent remember, and what happens to its work when the process dies? This hands-on demo walks you through context, long-term memory, and state, and shows how Temporal helps long-running agents pick up right where they left off.

Long Description

An agent can remember the whole conversation and still forget the work. Stop its process one step before it issues a refund, and the next process has no idea the customer already answered its questions, or that the refund was the next move. This repo shows what it takes to keep that work alive, and where context, long-term memory, and state each fit in.

One refund agent, two demos, the same crash. Without Temporal, the customer starts the return over. With Temporal, the agent's loop runs as a Workflow, and a new Worker picks the work back up from Event History at the refund, without asking the customer a single question twice.

That gap is the difference between memory and state. Context is what the model sees for the decision in front of it. Long-term memory is what the agent carries from one run to the next, like past cases or facts it has learned. State is the set of facts the agent relies on but doesn't own, and it comes in many types. This demo looks at two of them. Execution state, where the work stands, lives in Temporal. Effect state, whether the refund really happened, belongs to Stripe. A memory store can remind an agent what it knew. It can't tell the agent that the refund still needs to go out.

Nothing here is hidden behind a framework. The loop is hand-written Python, so the Temporal pieces are right there to borrow. The model call and four tools run as Activities, so their finished results survive a crash. The customer's answers arrive as Signals, and the Workflow waits for them durably, which is the pattern to reach for when your own agent has to pause for input and pick up later. Every refund attempt in a run reuses one idempotency key, so a retry gets back the refund Stripe already made instead of making a second one.

Replay saves money too. Finished model calls come back from the record, so recovery doesn't pay their tokens and dollars again the way a restart does. Only a call that was in flight at the crash can run twice. The README has the measured numbers for both demos.

To try it, you need Python 3.11+, uv, and the Temporal CLI. make run plays both demos in one terminal with a fixed policy and an offline ledger, so you don't need any API keys. Add a live OpenAI or Anthropic model with --real-model, and real Stripe test-mode refunds with --real. The guide covers failure drills and how to watch the recovery in the Temporal Web UI.

Author(s)

Melanie Warrick

Activity

  1. github-actions commented on Oct 16, 2026

    @github-actions

    ZiggyBot — automated pre-evaluation


    Criterion Assessment
    Useful to Temporal users ✅ Yes — Demonstrates durable execution for an AI agent loop, distinguishing agent memory from execution state, which is a common concern for users building long-running agents.
    Benefits clearly explained ✅ Yes — The README and descriptions define context, long-term memory, execution state, and effect state, and map each to concrete components in the demo.
    OSI Approved License ✅ Yes — MIT License is present and identified via SPDX.
    README with working instructions ✅ Yes — Setup prerequisites, clone/sync/run commands, make targets, and a default key-free path are documented with expected output.

    Overall: Looks good ✅

    Notes:

    • Default run requires no API keys and makes no model calls (offline fixed policy and offline ledger), which lowers the barrier to reproducing the demo.
    • The agent loop is hand-written Python with no agent framework, which keeps Temporal primitives (Workflow, Activities, Signals, Event History) visible rather than abstracted.
    • Idempotency is handled by deriving one key per Workflow run and disabling Stripe's own network retries so each attempt maps to a Temporal Activity attempt; this is the stated mechanism for preventing duplicate refunds across retries.
    • Two failure drills (--simulate-stripe-timeout, --simulate-stripe-retry) exercise mid-Activity crashes, including the in-flight-at-crash case where an Activity can run twice.
    • The README references model identifiers (gpt-5.6-luna, claude-sonnet-4-6) and dates in 2026 that may be placeholders or not yet valid; worth confirming the live-model paths were actually exercised versus estimated. The README itself notes the Claude figures are estimates.
    • Source files provided are truncated; the Workflow definition (workflow.py) and Signal handling were referenced but not included in the fetched code, so the Signal/wait implementation was evaluated from documentation only.
    • Repository has 2 stars; low adoption signal but not a criterion.

    Suggested questions for submitter:

    • Were the live-model paths (--real-model with OpenAI and Anthropic) run against actual available models, or are the named model identifiers placeholders?
    • Can you confirm the release Signal wait in workflow.py uses a durable wait condition so recovery resumes at the pause point without re-prompting?

    Notable Temporal pattern:

    Durable execution of an agent loop via Event History: the agent's decision loop runs as a Workflow with model calls and tools as Activities, so completed results survive a Worker crash and a new Worker rebuilds state from Event History and resumes at the next step. Combined with a per-run idempotency key on the single external effect (the refund), this ensures a retried or recovered run does not duplicate the side effect.
    View in source ↗


    Automated AI pre-screen by ZiggyBot. Final decisions are made by the community team.

    Reviewer: Check the box below to generate a Contentful-ready long description for this submission.

    • Generate long description if needed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    code exchange submissionCode and/or content about Temporal!triageIssues that Temporal folk need to look atziggy reviewedPre-screened by ZiggyBot

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions