Skip to main content

Overview

Integrate Freeplay with LangGraph to add observability, prompt management, and evaluation capabilities to your LangGraph applications. This comprehensive guide covers everything from basic setup to advanced agent workflows with state management, streaming, and human-in-the-loop patterns.

Prerequisites

Before you begin, make sure you have:
  • A Freeplay account with an active project
  • Python 3.10 or higher installed
  • Basic familiarity with LangGraph and LangChain

Quick Start with Observability

Installation

Install the Freeplay LangGraph SDK along with your preferred LLM provider. For advanced use, please refer to the documentation on PyPi.

Configuration

Set Up Your Credentials

Configure your Freeplay credentials using environment variables:
You can find your API key and Project ID in your Freeplay project settings.

Initialize the SDK

Create a FreeplayLangGraph instance in your application:
With this setup, your LangGraph application is now automatically instrumented with OpenTelemetry, sending traces and spans to Freeplay for observability.
Note: It is recommended to manage your prompts within Freeplay to support better prompt development lifecycle. Continue following this guide to get your prompts configured within LangGraph.

Prompt Management

Freeplay’s integration requires that you have your prompts configured in Freeplay. By default, FreeplayLangGraph fetches prompts from the Freeplay API. This requires you to have prompts configured in Freeplay for use. To learn more, see our Prompt Management guide here. Once configured you will need the prompt names for use in the code. Managing prompts in Freeplay separates your prompt engineering workflow from your LangGraph application. Instead of hardcoding prompts in your agent code, your team can iterate on prompt templates, test different versions , new models and deploy changes through Freeplay without modifying or redeploying your LangGraph application. This enables your team to test agent behavior, maintain different prompt versions across environments (development, staging, production), and experiment with variations.

Optional - Prompt Bundling

Once your prompts are saved in Freeplay, you can use bundled prompts stored locally with your application, you can provide a custom template resolver:
This is useful for offline environments, testing, or when you want to version control your prompts alongside your code. See our Prompt Bundling Guide to learn more.

Core Concepts

Freeplay provides two primary ways to work with LangGraph:
  1. create_agent() - For building full LangGraph agents with tool calling, ReAct loops, and state management
  2. invoke() - For simple, stateless LLM invocations when you don’t need agent capabilities
Both methods support the same core features: conversation history, tool calling, structured outputs and running tests. Choose create_agent() when you need the full power of LangGraph’s agent framework, and invoke() for simpler use cases.

Building LangGraph Agents

The create_agent method provides full support for LangGraph’s agent capabilities including the ReAct loop, tool calling, state management, middleware, and streaming.

Basic Agent Creation

Create an agent that uses a Freeplay-hosted prompt with automatic model instantiation. You have the ability to pass variables at the creation and invocation of the agent, both are optional depending on your flow:
Using create_agent gives you access to LangGraph’s full agent capabilities, including tool calling with the ReAct loop, state persistence, and advanced execution control.

Adding Tools

Bind LangChain tools to your agent for agentic workflows. The agent automatically decides when to call tools:
The agent handles the tool-calling cycle through LangGraph’s ReAct loop, deciding when to use tools and when to respond directly to the user.

Conversation History

Maintain conversation context across multiple turns with conversation history:
For persistent conversations across multiple invocations, use state persistence with checkpointers (covered in State Management section).

Structured Output

Get structured, typed responses from your agents using ToolStrategy or ProviderStrategy:
Structured output ensures your agent returns data in a predictable format, making it easier to integrate with downstream systems, databases, or UIs.

Automatic Observability

Once initialized, the Freeplay SDK automatically instruments your LangGraph application with OpenTelemetry. This means every LangChain and LangGraph operation is traced and sent to Freeplay without any additional code.

What Gets Tracked

Freeplay automatically captures:
  • Prompt invocations: Template, variables, and generated content
  • Model calls: Provider, model name, tokens used, latency
  • Tool executions: Which tools were called and their results
  • Agent flows: Multi-step reasoning and decision paths
  • Conversation flows: Multi-turn interactions and state transitions
  • Errors and exceptions: Failed invocations with stack traces
  • Metadata: Test run IDs, test case IDs, environment names, and custom tags
All metadata is injected automatically through LangChain’s RunnableBindingBase pattern, ensuring comprehensive observability without manual instrumentation.

Viewing Traces

You can view all of this data in the Freeplay dashboard, making it easy to:
  • Debug issues and understand failure patterns
  • Optimize performance and reduce latency
  • Understand how your application behaves in production
  • Track token usage and costs across environments
  • Measure impact of prompt changes over time

Simple Prompt Invocations

For simpler use cases that don’t require the full agent loop, use the invoke method. This is ideal for one-off completions, quick classifications, or any scenario where you don’t need agent state management or the ReAct loop.

Basic Invocation

Call a Freeplay-hosted prompt with automatic model instantiation:
Using invoke gives you quick access to Freeplay-managed prompts without the overhead of agent state or tool calling. This is perfect for classification tasks, content generation, or any stateless LLM operation.

Adding Tools

Bind LangChain tools for basic tool calling without the full agent loop:

Conversation History

Maintain conversation context across multiple turns:
By passing conversation history, your prompts can maintain context across multiple turns without needing full agent state management.

Test Execution Tracking

Track test runs for evaluation workflows by pulling test cases from Freeplay and executing them with automatic tracking. By associating invocations with test runs and test cases, you can analyze performance across your test suite, identify regressions, and measure the impact of prompt changes in Freeplay’s evaluation dashboard. See more about running end to end test runs here.

Creating Test Runs

Executing Test Cases with Simple Invocations

For simple prompt invocations, use the test tracking parameters directly:

Executing Test Cases with Agents

For LangGraph agents, pass test tracking metadata via config to reuse the agent efficiently:

Using Custom Models

Provide your own pre-configured LangChain model for more control:

Async Support

All methods in the Freeplay SDK support async/await for better performance in async applications:

Async Agent Invocation

Async Simple Invocations

Async State Management

Using async methods improves throughput and reduces latency in applications that handle multiple concurrent requests, such as web servers or API endpoints.

Supported LLM Providers

Freeplay’s LangGraph SDK supports automatic model instantiation for multiple providers. Install the corresponding LangChain integration package for your provider:

OpenAI

Anthropic

Vertex AI (Google)

The SDK automatically detects which provider your Freeplay prompt is configured to use and instantiates the appropriate model with the correct parameters.