Skip to main content

Docker

Run your Flux0 agent in a portable, self-contained Docker environmentโ€”ideal for both local testing and production.

๐Ÿ’ก This follows the Docker installation instructions guide.

๐Ÿ“ฅ Step1: Install Dependenciesโ€‹

Before writing code, define the required libraries for your agent:

# Inherit from the flux0 image
FROM flux0ai/flux0:beta AS base

# Install extra dependencies based on your agent's requirements
RUN pip install langchain "langchain[openai]"

# Copy your agent code into the container
COPY ./modules /app/modules

๐Ÿง  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 -p modules/my_agent
curl https://raw.githubusercontent.com/flux0-ai/flux0/develop/examples/langchain_simple/agent.py -o modules/my_agent/agent.py
curl https://raw.githubusercontent.com/flux0-ai/flux0/develop/examples/langchain_simple/__init__.py -o modules/my_agent/__init__.py
<your_flux0>/my_agent/agent.py
loading...

๐Ÿ“ฆ 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:

docker build -t my-flux0 . && docker run --rm -e FLUX0_MODULES=my_agent -e OPENAI_API_KEY=<key> -p 8080:8080 my-flux0

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:

docker run --rm --network host my-flux0 \
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.