To solve real-world problems, AI agents need to choose the correct tool to use. The aim of this project is to engineer an ecosystem of AI agents and tools to support intuitive conversational execution of statistical functions.
The current implementation is an AI agent that can produce random numbers from various probability distributions. It's made with industry-standard components, representing a foundation for building natural language interfaces for complex workflows.
We use Docker Compose to connect an Agent Development Kit client to an MCP server from the mcptools package running in an R environment.
- Model Context Protocol (MCP) allows AI agents to interact with external tools in a client-server setup.
- Docker Compose supports definitions of containerized AI agents and one or more MCP servers (through Docker MCP Gateway) for scalable and secure deployment.
- R offers many statistical functions that can be exposed through an MCP server with the mcptools package.
"invent" was chosen as the Docker Compose project name to make it easier to find in log messages, image names, etc.
To use gpt-4o-mini as the LLM, put your OpenAI API key (sk-proj-...
) in secret.openai-api-key
, then run this command.
docker compose build
This creates a compose project and three images:
docker compose ls -a
: inventdocker images
: invent-tools, invent-agent, docker/mcp-gateway
Now it's time to run the project!
docker compose up
You can access the ADK Dev UI at http://localhost:8080.
In case you want to use a different model, change it in entrypoint.sh
.
To use a local LLM running on your GPU, install Docker Model Runner before running this command.
docker compose -f compose.yaml -f model-runner.yaml up
The LLM used here is Gemma 3; this can be changed in model-runner.yaml
.
With this command, changes you make to the R and Python code on the host computer are immediately reflected in the running project.
docker compose watch
Alternatively, start the project with one of the previous commands and press w
to start watching file changes.
Make sure to install the packages listed in requirements.txt
.
Start the MCP Gateway:
docker mcp gateway run --catalog=./catalog.yaml --servers=r-mcp --transport=sse --port=8811
Start the ADK web UI:
export MCPGATEWAY_ENDPOINT=http://127.0.0.1:8811
export OPENAI_MODEL_NAME=gpt-4o-mini
OPENAI_API_KEY=your-api-key adk web --reload_agents
- The
invent-tools
image is based on rocker/v-verserver.R
defines 18 tools to generate random numbers from various probability distributions
- The
invent-agent
image is based on Docker Python slimrandom-agent/agent.py
defines an MCPToolset that is passed to the LLM along with instructions for using the toolsrandom-agent/__init__.py
has code to reduce log verbosity and is modified from docker/compose-for-agents
- The Docker MCP Gateway routes requests to MCP servers (just one in our case)
- A custom
catalog.yaml
makes our R MCP server visible to the MCP Gateway - For more options, see MCP Gateway docs and Docker MCP Catalog for the default
catalog.yaml
- A custom
- Specific actions are used for Docker Watch:
action: rebuild
is used forserver.R
because we need to restart the MCP server if the R code changesaction: sync
is used forrandom-agent
because the ADK web server supports hot reloading with the--reload_agents
flag
In these examples, the user describes the problem and the agent chooses a distribution and calls the correct tool.
- Uniform distribution
- Hypergeometric distribution
The following distributions are available for generating random numbers. See the R help page on Distributions for more information.
Discrete Distributions:
Binomial Distribution, Poisson Distribution, Geometric Distribution, Hypergeometric Distribution, Multinomial Distribution, Negative Binomial Distribution
Continuous Distributions:
Normal Distribution, Uniform Distribution, Exponential Distribution, Chi-Squared Distribution, Student's t Distribution, Gamma Distribution, Beta Distribution, Cauchy Distribution, F Distribution, Log-Normal Distribution, Weibull Distribution