How to Integrate AutoGen for fintech with Docker for AI agents
Combining AutoGen for fintech with Docker gives you a clean way to run agent workflows that touch regulated data without turning your local machine into the execution environment. AutoGen handles the agent orchestration and tool calling, while Docker gives you isolation, repeatability, and a hard boundary around what each agent can access.
This is the pattern I use when building AI systems for banking and insurance teams: keep the LLM orchestration in Python, push risky or stateful work into containers, and make every step observable.
Prerequisites
- •Python 3.10+
- •Docker Desktop or Docker Engine installed and running
- •
piporuv - •Access to an OpenAI-compatible model endpoint used by AutoGen
- •A working AutoGen installation:
- •
pip install pyautogen
- •
- •Docker SDK for Python:
- •
pip install docker
- •
- •A local project with permission to run containers
- •Environment variables configured:
- •
OPENAI_API_KEY - •Any model endpoint variables your AutoGen setup requires
- •
Integration Steps
- •Install the Python dependencies and verify Docker access from Python.
import docker
client = docker.from_env()
print(client.ping())
print(client.version()["Version"])
If this fails, fix Docker first. AutoGen can only orchestrate containerized tools if the host can actually start containers.
- •Create a Dockerized fintech worker that your agents can call.
Use a small container that exposes one deterministic task, like validating a payment payload or checking an account reference. Keep the container stateless.
import docker
from pathlib import Path
client = docker.from_env()
dockerfile = """
FROM python:3.11-slim
WORKDIR /app
COPY worker.py /app/worker.py
CMD ["python", "/app/worker.py"]
"""
worker_py = """
import json
payload = {"status": "ok", "risk_flag": False, "message": "payload validated"}
print(json.dumps(payload))
"""
Path("worker.py").write_text(worker_py)
Path("Dockerfile").write_text(dockerfile)
image, logs = client.images.build(path=".", tag="fintech-worker:latest")
print(image.tags)
This pattern is useful because the agent never runs business logic directly. It calls a containerized tool with a narrow contract.
- •Wire AutoGen to call the Docker-backed tool as a function.
AutoGen’s AssistantAgent can call registered tools through register_function. You define a Python wrapper that starts the container and returns its output to the agent.
import json
import docker
from autogen import AssistantAgent, UserProxyAgent, register_function
client = docker.from_env()
def run_fintech_worker(payload: dict) -> dict:
container = client.containers.run(
image="fintech-worker:latest",
detach=True,
remove=True,
)
result = container.logs().decode("utf-8").strip()
return json.loads(result)
assistant = AssistantAgent(
name="fintech_assistant",
llm_config={
"model": "gpt-4o-mini",
"api_key": os.environ["OPENAI_API_KEY"],
},
)
user_proxy = UserProxyAgent(
name="user_proxy",
human_input_mode="NEVER",
code_execution_config=False,
)
register_function(
run_fintech_worker,
caller=assistant,
executor=user_proxy,
name="run_fintech_worker",
description="Run a containerized fintech validation job and return structured JSON.",
)
The important part here is that AutoGen sees a normal callable, but the actual work happens inside Docker. That gives you isolation without losing agentic orchestration.
- •Add an AutoGen conversation that invokes the Docker tool.
Keep the prompt explicit about when to call the tool and what shape of output you expect back.
message = """
Validate this fintech request using the containerized worker:
{
"customer_id": "CUST-1029",
"amount": 2500,
"currency": "USD"
}
Return only structured JSON.
"""
result = user_proxy.initiate_chat(
assistant,
message=message,
)
print(result.summary)
In production, I’d typically add stricter schemas with Pydantic before passing payloads into the container. That keeps malformed requests out of your execution path.
- •Make the integration production-safe with explicit input validation and container controls.
Don’t let agents launch arbitrary images or pass unsanitized payloads. Pin images, limit resources, and validate inputs before calling Docker APIs.
from pydantic import BaseModel, Field
import docker
client = docker.from_env()
class PaymentRequest(BaseModel):
customer_id: str = Field(min_length=3)
amount: int = Field(gt=0)
currency: str = Field(pattern=r"^[A-Z]{3}$")
def safe_run_fintech_worker(request: dict) -> dict:
payload = PaymentRequest(**request).model_dump()
container = client.containers.run(
image="fintech-worker:latest",
command=["python", "/app/worker.py"],
detach=False,
remove=True,
network_disabled=True,
mem_limit="256m",
cpu_quota=50000,
environment={"PAYLOAD": json.dumps(payload)},
)
return json.loads(container.decode("utf-8"))
That combination is what makes this usable in regulated environments: schema validation on ingress, isolated execution in Docker, and agent orchestration on top.
Testing the Integration
Run a quick end-to-end check by calling the wrapper directly before putting it behind an agent loop.
test_request = {
"customer_id": "CUST-1029",
"amount": 2500,
"currency": "USD",
}
output = safe_run_fintech_worker(test_request)
print(output)
Expected output:
{
"status": "ok",
"risk_flag": false,
"message": "payload validated"
}
If you get that response consistently, your Python layer can talk to Docker correctly, and your container contract is stable enough for AutoGen to orchestrate around it.
Real-World Use Cases
- •
Payment validation agents
- •An AutoGen agent collects transaction details.
- •Docker runs a hardened validator that checks limits, formats, and policy rules.
- •The agent returns a decision trail instead of raw free-form text.
- •
Claims triage workflows
- •One agent extracts claim fields from documents.
- •Another calls a Dockerized fraud-scoring service.
- •The system routes low-risk claims automatically and escalates edge cases.
- •
KYC / AML review assistants
- •The agent coordinates document parsing, sanctions checks, and enrichment jobs.
- •Each external check runs in its own container with pinned dependencies.
- •You get reproducible behavior across dev, staging, and production.
Keep learning
- •The complete AI Agents Roadmap — my full 8-step breakdown
- •Free: The AI Agent Starter Kit — PDF checklist + starter code
- •Work with me — I build AI for banks and insurance companies
By Cyprian Aarons, AI Consultant at Topiax.
Want the complete 8-step roadmap?
Grab the free AI Agent Starter Kit — architecture templates, compliance checklists, and a 7-email deep-dive course.
Get the Starter Kit