First Agent
Welcome to your first step with Flux0 agents! This guide will walk you through creating and running a minimal agent in your local environment using LangChain and OpenAI.
Flux0 doesnβt lock you into any specific AI framework β while it natively supports LangChain, LangGraph, and PydanticAI, youβre free to use any Pythonic LLM framework of your choice.
π‘ This follows the PyPI installation instructions guide. For container deployment see Docker deployment.
π₯ Step1: Install Dependenciesβ
Before writing code, install the required libraries:
cd <my_flux0>
pip install langchain "langchain[openai]"
π§ Step2: Define Your Agent Logicβ
Start by writing your agent logic. In Flux0, an agent is defined by implementing a runner β a class that encapsulates how to handle the agent's execution and stream events to the client. Runners don't manage sessions directly but are triggered per session execution.
You can annotate your runner using @agent_runner
, which registers it with Flux0 by name. Hereβs an example using LangChain to translate input text:
You can download the files via curl (or copy & paste the code below)
mkdir my_agent
curl https://raw.githubusercontent.com/flux0-ai/flux0/develop/examples/langchain_simple/agent.py -o my_agent/agent.py
curl https://raw.githubusercontent.com/flux0-ai/flux0/develop/examples/langchain_simple/__init__.py -o my_agent/__init__.py
loading...
π¦ Step 3: Register the Moduleβ
Your runner must be registered in a Python module so Flux0 can load it.
In your my_agent
directory, create an __init__.py
file like this:
loading...
π Step 4: Run the Serverβ
Start the Flux0 server locally:
PYTHONPATH=. FLUX0_MODULES=my_agent OPENAI_API_KEY=<your_key> flux0-server
Your agent will now be available through the API and ready to receive interactions.
π§Ύ Step 5: Register the Agentβ
Once your runner is defined and your module is registered, you can create the agent entry in the database:
flux0 agents create --name "Translation Agent" --type langchain_simple
This defines metadata about the agent and links it to the runner by name. The --type
refers to the name you gave in @agent_runner("...")
.
π¬ Step 6: Talk to Your Agentβ
Start chatting with your agent at http://localhost:8080/chat
π Whatβs Next?β
- Ready to go beyond Hello World? Jump into the Examples to explore powerful agent use cases!
- Want to build your own UI to interact with your agent? see Flux0-React.