No history yet

Agentic Workflows

Building AI That Remembers

Large Language Models (LLMs) are incredibly powerful, but they have a fundamental weakness: they are stateless. Think of an LLM as a brilliant consultant with severe short-term memory loss. It can give you an amazing answer to a single question, but it forgets the entire conversation the moment you walk away. This poses a huge problem for building complex AI agents that need to handle multi-step tasks. What happens if the system crashes while the AI is halfway through booking your flight or analyzing a report? Without a memory, it has to start over from scratch, losing all progress.

This is where agentic workflows come into play, providing a robust framework to give these powerful AI brains a persistent memory and a structured way to work. By separating the 'thinking' from the 'doing' and ensuring the overall process is saved at every step, we can build AI systems that are reliable, resilient, and can pick up right where they left off, no matter what happens.

Workflows as Orchestrators

The key to building resilient agents is to distinguish between orchestration and operation. The orchestration logic—the step-by-step plan—must be reliable and stateful. The operations, like calling an LLM or an external tool, can be unpredictable and may fail. This is a perfect match for Temporal's architecture. We use a Temporal Workflow to act as the durable orchestrator. The Workflow's code contains the high-level logic of the agentic process. Because Workflows use , their state is automatically preserved and restored by the Temporal platform, making them immune to process crashes or server restarts.

The non-deterministic or failure-prone parts of our agent, such as calling an LLM API or interacting with a database, are defined as Activities. The Workflow is responsible for calling these Activities, handling their results, and deciding what to do next. This creates a clean separation of concerns.

Workflow: The deterministic, reliable blueprint of the task. Activity: The non-deterministic, potentially fallible action or thought process.

The Agentic Loop

An agent's life is a cycle of thinking and acting. This is often called the , and it fits perfectly into the Workflow/Activity model. The process typically looks like this:

  1. Input: The Workflow receives a user prompt (e.g., "Find the top three sci-fi movies from the 90s and summarize their plots.").
  2. Reason: The Workflow calls an LLM Activity, passing it the prompt and the conversation history. The LLM's goal is to decide on the next action. It might decide it needs to use a search tool.
  3. Act: If the LLM decided to use a tool, the Workflow calls the appropriate Tool Activity (e.g., searchAPI.execute("top sci-fi movies 1990s")).
  4. Observe: The result from the Tool Activity is passed back to the Workflow.
  5. Repeat: The Workflow loops, calling the LLM Activity again with the new information (the search results). The LLM now sees the movie list and decides its next action is to get the plot for each one, repeating the loop until the final answer is compiled.

During this entire process, the Workflow maintains the state—the conversation history, the results of tool calls, and the number of steps taken. If a Worker crashes while the LLM is 'thinking' or a network call fails, the Temporal platform ensures the Activity is retried. When it succeeds, the Workflow continues from the exact point it was interrupted, with all state intact.

// Workflow Interface: The deterministic orchestrator
@WorkflowInterface
public interface MovieAgentWorkflow {
    @WorkflowMethod
    String processRequest(String prompt);
}

// Activity Interface: The non-deterministic brain and tools
@ActivityInterface
public interface MovieAgentActivities {
    // LLM call to decide next action
    @ActivityMethod
    Action decideNextAction(List<String> history, String prompt);

    // Tool call to execute an action
    @ActivityMethod
    String executeSearch(String query);
}

Determinism in an AI World

A core rule of Temporal is that Workflow code must be deterministic. This means it must produce the same output given the same input, without relying on random numbers, system clocks, or external API calls. This sounds counterintuitive for AI, which is often unpredictable.

However, this rule only applies to the Workflow code itself—the orchestrator. The AI's 'brain' lives in the Activities, which are free to be non-deterministic. The Workflow's job is simply to react to the results of those Activities. If an LLM Activity returns USE_SEARCH_TOOL, the Workflow deterministically calls the search Activity. The decision was non-deterministic, but the Workflow's reaction to that decision is predictable.

This design pattern forces you to build robust systems. For an Activity to be retryable, it should be —meaning it can be executed multiple times with the same input and produce the same outcome without causing unintended side effects. For example, an Activity that charges a credit card should be designed to prevent duplicate charges on a retry.

By embracing this separation, you gain the power of durable execution for your agentic workflows. You can build AI applications that run for hours, days, or even weeks, surviving crashes and retrying failed steps, all while maintaining a perfect memory of their progress.

Quiz Questions 1/6

What is the fundamental weakness of Large Language Models (LLMs) that agentic workflows are designed to solve?

Quiz Questions 2/6

In a resilient agentic system using a framework like Temporal, where should you place failure-prone or non-deterministic operations like calling an LLM or an external API?