A Practical Guide to Building Agents with Closed-Source LLMs
This article explains how to engineer agentic systems on top of closed-source large language models, where training details and weights are unavailable and the engineering focus shifts from modifying the model to hardening everything around it. It covers capability boundaries, externalizing policies as configuration, the plan-execute-observe-correct loop with a scheduler, multi-agent collaboration and dynamic workflows, reusable skills, enterprise integration, layered evaluation and observability, cost governance, and risk and compliance controls.
1. Introduction: From Chatting to Getting Work Done
Early large language models delivered value mainly through text generation and question answering. What engineering teams care about is whether a model can complete multi-step tasks in a controlled environment: reading documents, calling tools, validating results, and writing back to systems.
Closed-source models do not expose training details or weights, so users cannot modify the model internals. The engineering focus therefore shifts from “changing the model” to “changing the surrounding system”: prompt and context engineering, tool orchestration, state management, and permissions and auditing. This article takes a general technical view of how such systems should be designed.
2. A Clear View of Capability Boundaries
Closed-source models offer stable general reasoning and language understanding, with iteration handled by the vendor. The trade-offs are weak observability, possible behavioral drift between versions, and per-call cost that needs careful accounting. Three principles should guide the architecture:
- The model only makes judgments and generates content; deterministic logic stays in code.
- All external side effects must go through the tool layer; the model is never allowed to touch production systems directly.
- Critical paths keep fallback rule branches and human confirmation points.
3. Engineering Constraints from Alignment Methods
Training approaches that constrain model behavior with rule sets (commonly described in the industry as principle-based alignment) show up in engineering as “declarable policies”: the system prompt states prohibited actions, data usage boundaries, and refusal conditions. In practice, keep policies external as configuration rather than scattered across prompt strings:
policy:forbid_actions: [delete_data, send_external_mail]pii_handling: mask_before_promptrequire_human_approval: [payment, publish]refusal_template: "This operation exceeds the authorized scope and has been terminated."
This makes policies versionable, gradually rollable out, and auditable, and prompts do not need to be rewritten when the model is upgraded.
4. Agents and Task Execution: Orchestration Is the Core
A single-turn call cannot cover real business work. You need a “plan-execute-observe-correct” loop. Typically a scheduler maintains task state while the model only emits a structured next action:
{"step": 3, "action": "query_metric", "args": {"window": "7d"}, "expect": "schema"}
The scheduler validates the arguments, runs the tool, trims the result, and feeds it back into the context before the next round. To prevent infinite loops, set a maximum step count, timeouts, and repeated-action detection; retry failed steps a limited number of times with backoff, and record failure reasons in a structured form for later attribution.
5. Multi-Agent Collaboration and Dynamic Workflows
Complex tasks can be split into a main controller agent plus several specialized sub-agents, for example retrieval, computation, and validation agents. The value of a dynamic workflow is deciding concurrency at runtime based on task size instead of hard-coding the flow. Key implementation points:
- Task decomposition must produce unambiguous sub-tasks that can be accepted independently.
- Sub-agents exchange intermediate artifacts through a shared blackboard or message queue to avoid cross-contaminating each other’s context.
- The aggregation stage must include arbitration logic (voting, confidence thresholds, or rule checks) so errors are not amplified.
- Concurrency is tied to quotas, with rate limiting and priority queues so critical business is not crowded out.
6. Skill Reuse and Knowledge Accumulation
Packaging reusable operations as “skills” is the key to lowering marginal cost. A skill usually has four parts: trigger conditions, input schema, execution steps, and acceptance criteria. Describe it in a declarative file, put it under version control, and add regression tests. Teams can record and replay in a sandbox first, then publish to the production namespace once it is stable, keeping a rollback version.
7. Enterprise Integration and Efficiency
Model capability has to be embedded into business systems through standard interfaces. A common approach is integrating with workflow platforms, data warehouses, ticketing and collaboration tools, using a unified tool gateway for authentication, masking, caching, and metering. Efficiency measures include prompt prefix caching, retrieval result compression, batch and asynchronous calls, selecting different model sizes by task difficulty, and routing high-frequency read-only requests through a semantic cache. If you use general cloud capabilities, you can combine object storage, message queues, container platforms, logging services, and monitoring and alerting into an elastic pipeline.
8. Evaluation, Observability, and Cost Governance
Before launch, build three layers of evaluation: unit level (tool call accuracy), scenario level (end-to-end task completion rate), and security level (resistance to privilege escalation and prompt injection). In production, use full-chain tracing to record an input summary, tool arguments, latency, and result status for every call. Track success rate, average steps, human takeover rate, and cost per task. Cost governance relies on quotas, budget alerts, and tiered model routing.
9. Risk and Compliance
The main risks are prompt injection, sensitive data leakage, and unexpected external side effects. Mitigations include input-side filtering and source labeling, least privilege and allowlists on the tool side, output-side review of sensitive information, and complete audit logs to meet traceability requirements. For any action that publishes externally, insist on human confirmation.
10. Conclusion
The deciding factor in productionizing closed-source LLMs is not the model itself but how rigorous the surrounding system is: policies that can be declared, flows that can be orchestrated, results that can be verified, and cost that can be measured. Get these right, and agents can move from demo to production.
