LogoFreestyle
AI Integrations

Langgraph Python

Code execution for Langgraph Python SDK

You are viewing legacy Freestyle documentation. See the new documentation for the latest guides and API reference.

Install the required dependencies

pip install langgraph langchain_anthropic freestyle

Get your Freestyle API Key from the Freestyle Dashboard

Set up the Code Executor

The simplest code executor looks like this

import os
from freestyle.langgraph import execute_tool

execute_tool(
  os.environ.get("FREESTYLE_API_KEY"),
)

If you want to add node modules & environment variables, you can do so like this

import os
from freestyle.langgraph import execute_tool
import freestyle


(definition, runner) = freestyle.openai.execute_tool(
  os.environ.get("FREESTYLE_API_KEY"),
  freestyle.FreestyleExecuteScriptParamsConfiguration(
    nodeModules={"mathjs": "14.3.1"},
    envVars={"SUPER_SECRET_KEY": os.environ.get("SUPER_SECRET_KEY")},
  ),
)

Add it to your Agent

from langchain_anthropic import ChatAnthropic

llm = ChatAnthropic(model="claude-3-5-sonnet-20240620")

llm_with_tools = llm.bind_tools([execute_tool])

On this page

Freestyle AI

Documentation assistant

Experimental: AI responses may not always be accurate—please verify important details with the official documentation.

How can I help?

Ask me about Freestyle while you browse the docs.