Skip to main content

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:

tip

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
<your_flux0>/my_agent/agent.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:

<your_flux0>/my_agent/__init__.py
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.