How to Integrate AutoGen for retail banking with Docker for RAG

By Cyprian AaronsUpdated 2026-04-21
autogen-for-retail-bankingdockerrag

Combining AutoGen for retail banking with Docker gives you a clean way to run retrieval-augmented banking agents in isolated, reproducible containers. That matters when your agent needs to answer customer servicing questions, pull policy docs, and stay auditable while running the same way in dev, staging, and production.

Prerequisites

  • Python 3.10+
  • Docker Desktop or Docker Engine installed and running
  • Access to the AutoGen for retail banking SDK/package you use in your environment
  • A working LLM endpoint configured for AutoGen
  • A document corpus for RAG, such as:
    • product FAQs
    • fee schedules
    • loan policy PDFs
    • call center scripts
  • pip access to install:
    • autogen
    • docker
    • chromadb or another vector store client
    • openai or your model provider SDK

Integration Steps

  1. Install the Python dependencies and verify Docker connectivity

    Start by installing the SDKs your agent will use. The Docker Python SDK is what lets your orchestration code create containers, mount volumes, and inspect logs.

    pip install autogen docker chromadb openai
    

    Then verify that Python can talk to the local Docker daemon:

    import docker
    
    client = docker.from_env()
    print(client.ping())
    
  2. Build a retrieval index for retail banking documents

    Your RAG layer should live outside the agent logic. Keep it as a separate indexing step so you can refresh documents without touching agent code.

    import chromadb
    from chromadb.config import Settings
    
    client = chromadb.PersistentClient(path="./chroma_bank")
    collection = client.get_or_create_collection(name="retail_banking_docs")
    
    docs = [
        {
            "id": "fee_schedule_001",
            "text": "Overdraft fee is $35 per item. Monthly maintenance fee is waived with direct deposit."
        },
        {
            "id": "mortgage_policy_001",
            "text": "Mortgage pre-approval requires income verification, credit check, and two months of bank statements."
        },
        {
            "id": "card_dispute_001",
            "text": "Card disputes must be filed within 60 days of the statement date."
        }
    ]
    
    collection.add(
        ids=[d["id"] for d in docs],
        documents=[d["text"] for d in docs]
    )
    
  3. Create an AutoGen assistant that retrieves context before answering

    In AutoGen, you typically define an assistant agent and wire in tools or a custom reply flow. For retail banking, keep the assistant constrained: retrieve relevant context first, then answer only from retrieved content.

    from autogen import AssistantAgent, UserProxyAgent
    
    def retrieve_context(query: str) -> str:
        results = collection.query(
            query_texts=[query],
            n_results=2
        )
        chunks = results["documents"][0]
        return "\n".join(chunks)
    
    llm_config = {
        "model": "gpt-4o-mini",
        "api_key": "${OPENAI_API_KEY}",
        "temperature": 0,
    }
    
    assistant = AssistantAgent(
        name="retail_banking_assistant",
        llm_config=llm_config,
        system_message=(
            "You are a retail banking support agent. "
            "Answer only using retrieved policy context. "
            "If context is missing, say you do not have enough information."
        ),
    )
    
    user_proxy = UserProxyAgent(
        name="customer_proxy",
        human_input_mode="NEVER",
        max_consecutive_auto_reply=3,
        code_execution_config=False,
    )
    
  4. Run the agent inside Docker for isolation and repeatability

    Use Docker to package the runtime so your RAG dependencies and model clients behave consistently across environments.

     import docker
    
     client = docker.from_env()
    
     container = client.containers.run(
         image="python:3.11-slim",
         command="python /app/run_agent.py",
         detach=True,
         remove=True,
         environment={
             "OPENAI_API_KEY": "${OPENAI_API_KEY}"
         },
         volumes={
             "/absolute/path/to/app": {"bind": "/app", "mode": "rw"},
             "/absolute/path/to/chroma_bank": {"bind": "/data/chroma_bank", "mode": "rw"},
         },
         working_dir="/app"
     )
    
     print(container.id)
    

    Inside /app/run_agent.py, call the retrieval function before handing context to AutoGen:

    query = "What is the overdraft fee?"
    context = retrieve_context(query)
    
    prompt = f"""
    Context:
    {context}
    
    Customer question:
    {query}
    """
    
    response = assistant.generate_reply(messages=[{"role": "user", "content": prompt}])
    print(response)
    
  5. Expose the containerized agent as a service

    For production use, wrap this in a small API so your banking channel can call it from web chat or CRM workflows.

    from fastapi import FastAPI
    import docker
    
    app = FastAPI()
    docker_client = docker.from_env()
    
    @app.post("/ask")
    def ask(question: str):
        context = retrieve_context(question)
        prompt = f"Context:\n{context}\n\nQuestion:\n{question}"
        reply = assistant.generate_reply(messages=[{"role": "user", "content": prompt}])
        return {"answer": reply}
    

Testing the Integration

Use a direct query that should hit one of your indexed policy chunks.

query = "How much is the overdraft fee?"
context = retrieve_context(query)

print("Retrieved context:")
print(context)

response = assistant.generate_reply(
    messages=[{"role": "user", "content": f"Context:\n{context}\n\nQuestion: {query}"}]
)

print("\nAssistant response:")
print(response)

Expected output:

Retrieved context:
Overdraft fee is $35 per item. Monthly maintenance fee is waived with direct deposit.

Assistant response:
The overdraft fee is $35 per item.

If Docker is wired correctly, your container should start without errors and the same code should run identically on another machine with the same mounted data path.

Real-World Use Cases

  • Retail banking FAQ bot

    • Answer card fees, account opening rules, dispute timelines, and loan eligibility using only approved policy docs.
  • Branch support copilot

    • Give employees fast answers during customer calls while keeping execution isolated in Docker containers.
  • Compliance-aware servicing workflows

    • Route sensitive questions through a controlled AutoGen agent that retrieves policy snippets before generating responses.

Keep learning

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

Related Guides