AI Agents in Banking: Architecture and Production Practices

    This article examines how AI agents move from demo projects to production systems in banking, a highly regulated environment with strict access control and latency requirements. It proposes a five-layer reference architecture, explains how to enforce metric consistency in data analysis, outlines security boundaries for coding assistants, and describes a three-tier evaluation approach. Readers will find orchestration and validation code examples, common anti-patterns, and governance principles for building auditable, permission-minimized agent systems.

    1. Industry Context: From Demo Conversations to Production Readiness

    Two trends are emerging in the industry. Some banks are rolling out AI coding and agent assistants for internal engineering and office workflows. Others, including financial institutions and data providers, are applying LLM agents to data analysis pipelines, while investor attention to technology companies continues to grow.

    Setting aside the specific organizations involved, both point to the same technical question: how do you make LLM agents produce reliable, usable results in financial environments defined by strict compliance, strict access control, and strict timing requirements?

    The demo stage asks whether the system can hold a conversation. The production stage asks four different questions: Are results reproducible? Can data sources be traced? Are permissions limited to what is strictly necessary? Are costs predictable? These four requirements drive architecture decisions, not the size of the model.

    2. Capability Layers: A Practical Reference Architecture

    Split the system into five layers that communicate through explicit contracts. This keeps prompts, business logic, and data access from collapsing into one place.

    1. Access layer: A unified session entry point handling authentication, tenant identification, rate limiting, and audit instrumentation.
    2. Orchestration layer: Task planning, step decomposition, retry on failure, and termination control. This is the core of controllability.
    3. Capability layer: Atomic capabilities such as retrieval, computation, SQL generation, report rendering, and code generation with a sandbox for execution.
    4. Data layer: Data warehouse or lakehouse, metadata, a metric definition repository, vector indexes, and access policies.
    5. Governance layer: Logging, monitoring and alerting, evaluation sets, cost accounting, and version rollback.

    The orchestration layer is the one most often underestimated. A robust approach is to define an explicit state machine rather than letting the model decide the flow freely:

    1. # Skeleton: orchestration with termination conditions and a budget constraint
    2. state = {"step": 0, "budget": 6, "evidence": []}
    3. while state["step"] < state["budget"]:
    4. plan = planner(state) # decide the next action
    5. if plan.action == "query":
    6. result = tool.query(plan.sql) # read-only account + row-level permissions
    7. elif plan.action == "search":
    8. result = retriever.search(plan.q) # retrieval with metadata filtering
    9. else:
    10. result = tool.exec(plan.payload) # execution inside a sandbox
    11. state["evidence"].append(result)
    12. if verifier(state, result): # consistency check passed
    13. break
    14. state["step"] += 1

    3. Data Analysis: Turning Natural Language into Trusted Metrics

    The hard part of a data analysis agent is not generating SQL. It is metric consistency. A single question such as “the number of active customers last month” can map to different filter conditions in different departments. Engineering needs three layers of constraints:

    • Metric semantic layer: Define business metrics as reusable objects (dimensions, filters, aggregations, time windows). The model may only reference registered metrics and cannot invent fields freely.
    • Retrieval augmentation: Build hybrid recall over table schemas, field descriptions, and historically similar questions using both vector and keyword indexes. Recall results carry metadata such as last update time, owner, and metric definition version.
    • Result validation: Run static checks before execution (do the tables and fields exist, is it a full table scan, is a time filter missing), then execute. After execution, check whether magnitudes and null values are reasonable; on anomalies, fall back and replan.

    Illustrative validation logic:

    1. def validate(sql, ctx):
    2. assert set(sql.tables) <= set(ctx.allowed_tables), "unauthorized table access"
    3. assert sql.has_time_filter(), "missing time range, scan cost too high"
    4. assert sql.metrics_registered(), "unregistered metric used"
    5. return True

    For output, return three things together: the conclusion, the supporting evidence, and the reproducible query. This lets business teams verify the result instead of receiving only a number.

    4. Engineering and Office Workflows: Security Boundaries for Coding Agents

    For engineering teams, the real value of an agent is compressing repetitive work: requirements into test cases, logs into root-cause localization, changes into review checklists. Boundaries are still mandatory:

    • Sandboxed execution: Use the isolated runtime provided by the container platform, with restricted network egress, filesystem, and CPU/memory quotas.
    • Least privilege: Use separate short-lived credentials for code repositories, build systems, and release systems, granted at task granularity.
    • Controlled changes: The agent produces only patches and explanations. Merging stays behind human confirmation and automated test gates.
    • Context governance: Filter code context retrieval by repository and branch to prevent cross-project leakage.

    5. Evaluation and Operations: No Evaluation Set, No Launch

    Build three tiers of evaluation:

    Tier Focus Typical metrics
    Component Retrieval hit rate, SQL correctness Recall, execution success rate
    Task End-to-end task completion First-pass rate, human takeover rate
    Runtime Stability and cost Latency percentiles, tokens and compute per task

    In production, collect metrics through logging and monitoring with alerting, and provide switches for human takeover and automatic degradation. Every change to prompts, models, or retrieval strategy runs against the same evaluation set, producing version records that can be rolled back.

    6. Common Anti-Patterns

    • Stuffing all logic into one extremely long prompt, which makes the system untestable and unreusable.
    • Letting the model connect directly to a production database for write operations, with no read-only or row-level permission isolation.
    • Evaluating only whether an answer sounds right, not whether the numbers are correct.
    • Ignoring metric definition governance, so the agent grows more confident while being wrong.

    7. Conclusion

    The requirements financial scenarios place on agents come down to four points: composable capabilities, traceable data, least privilege, and measurable results. Baidu AI Cloud offers general cloud building blocks such as a container platform, object storage, message queues, logging, and monitoring with alerting, which can serve as a common foundation for this kind of system. The actual implementation should still follow the layering and governance principles above, trading engineering constraints for business trust.