Temporal

Temporal is a durable execution platform that guarantees application code runs to completion despite failures. The platform provides reliability, scalability, and visibility for long-running workflows and distributed applications.

This guide covers routing telemetry from Temporal workflows to InteractiveAI for monitoring, debugging, and evaluating AI agents and LLM-powered applications.

Prerequisites

  • InteractiveAI account with API credentials

  • Temporal server (Cloud or local development server)

  • OpenAI API key


Installation

pip install temporalio openai openai-agents interactiveai openinference-instrumentation-openai-agents

Configuration

Set environment variables for InteractiveAI, Temporal, and OpenAI:

import os

# InteractiveAI credentials
# Obtain keys from Settings > API Keys in the dashboard
os.environ["INTERACTIVEAI_PUBLIC_KEY"] = "pk-ia-..."
os.environ["INTERACTIVEAI_SECRET_KEY"] = "sk-ia-..."
os.environ["INTERACTIVEAI_HOST"] = "https://app.interactiveai.com"

# OpenAI credentials
os.environ["OPENAI_API_KEY"] = "sk-proj-..."

# Temporal server configuration
os.environ["TEMPORAL_HOST"] = "localhost:7233"
os.environ.setdefault("TEMPORAL_NAMESPACE", "default")
os.environ.setdefault("TEMPORAL_TASK_QUEUE", "agents-task-queue")

Enabling Trace Capture

Initialize the OpenAI Agents instrumentor to capture LLM operations:

Initialize the InteractiveAI client:


Example: Building a Research Pipeline

The following sections walk through a complete implementation of a multi-step research pipeline. Temporal handles workflow orchestration and failure recovery, while OpenAI agents perform the actual research tasks. InteractiveAI captures telemetry from both layers.

The pipeline works in three stages:

  1. Planning - An agent analyzes the research query and generates search terms

  2. Searching - Multiple agents execute web searches in parallel and summarize findings

  3. Writing - A final agent synthesizes all results into a comprehensive report

Each section below builds on the previous one, starting with data models, then agent definitions, workflow logic, and finally execution.

Step 1: Define Data Models

These Pydantic models define the structure for data passed between agents. The planner outputs search items, and the writer produces the final report.

Step 2: Create Agent Factories

Each factory function returns a configured agent for a specific task. Separating these into functions allows the workflow to create fresh agent instances as needed.

Step 3: Build the Research Manager

The ResearchManager class coordinates the three-stage pipeline. It creates agents, runs them in sequence, and handles parallel search execution.

Step 4: Define the Temporal Workflow

The workflow decorator registers ResearchWorkflow with Temporal. When triggered, it creates a ResearchManager and runs the pipeline.

Step 5: Execute the Workflow

Before running, start a local Temporal development server:

Then execute the workflow:


Trace Visibility

The InteractiveAI dashboard displays:

  • Workflow execution with timing and completion status

  • Activity spans for each pipeline stage as nested traces

  • LLM calls with prompts, completions, and token usage

  • Cost estimates based on token consumption

  • Latency breakdown across all components

Last updated

Was this helpful?