Overview
In the rapidly evolving landscape of software architecture, the rise of agentic AI—systems where large language models (LLMs) autonomously reason and act—demands a fundamental shift in how we design and build applications. The key insight, as discussed by Michael Stiefel and Baruch Sadogursky, is that context is the cornerstone. LLMs are stochastic reasoning machines: they can interpret human ambiguity but need rigorous guardrails. By providing precise context artifacts—specifications, constraints, and examples—you can transform software specifications into the source of truth, relegating code to a disposable intermediate language. This tutorial guides you through implementing this paradigm.

Prerequisites
Before diving in, ensure you have:
- Basic understanding of LLMs (e.g., GPT, Claude) and their stochastic nature.
- Familiarity with software architecture concepts (specifications, code generation).
- Working knowledge of a programming language (e.g., Python) and API usage.
- Access to an LLM API (e.g., OpenAI, Anthropic) for practical steps.
Step-by-Step Instructions
1. Define Context Artifacts
Context artifacts are structured inputs that control the LLM’s reasoning. They replace ad-hoc prompts with formal specifications. Start by creating a specification document that describes the desired system behavior, including:
- Functional requirements: What the system should do (e.g., “process orders and update inventory”).
- Non-functional constraints: Performance, security, or compliance rules.
- Examples: Input-output pairs that illustrate expected behavior.
Store these artifacts in a versioned repository (e.g., Git). The spec becomes the source of truth—any change starts here.
2. Design LLM Interaction Patterns
The LLM interprets the specification and generates code (or other outputs). To manage stochasticity:
- Use structured prompts: Wrap context artifacts in a clear format, e.g., using JSON or markdown sections.
- Set a reasoning temperature: Lower values (0.0–0.3) produce deterministic outputs; higher values encourage creativity but increase variance.
- Chunk context: If the specification is large, split into logical modules and feed them sequentially.
Example prompt template:
"""
You are an expert software engineer. Based on the following specification, generate the corresponding code.
Specification:
{spec_json}
Constraints: {constraints}
Output only valid code in {language}.
"""
3. Implement Spec-as-Truth, Code-as-Disposable
In this architecture, the code is regenerated from the spec each time the spec changes or when the LLM is invoked. This implies:
- No manual code edits (except for debugging the spec-to-code pipeline).
- Automated validation: After code generation, run tests derived from the spec (e.g., unit tests from examples).
- Version both artifacts: Track spec versions and generated code versions to roll back if needed.
Workflow:
- Update specification.
- Run generation script that sends spec to LLM API.
- Validate generated code against spec.
- If validation fails, refine context artifacts (e.g., add edge case examples) and repeat.
4. Iterate and Test
Because LLMs are stochastic, you must treat code generation as a continuous refinement process:
/presentations/game-vr-flat-screens/en/smallimage/thumbnail-1775637585504.jpg)
- Unit tests for spec adherence: Write tests that check behavioral equivalence, not code structure.
- Regression testing: Re-generate code from unchanged spec to ensure consistency (expect minor variations, but functionally correct).
- Monitor for drift: If the LLM starts producing faulty code, update context artifacts (e.g., new examples) to steer it back.
Common Mistakes
Over-relying on the LLM Without Context
Many developers treat the LLM as a black box with a simple prompt. Without rigorous context artifacts, the output becomes unpredictable and untestable. Always provide structured, versioned specifications.
Ignoring Stochasticity
LLMs are not deterministic. Expect slight variations in code quality and style. Mitigate this by setting low temperature and using multiple generation passes with voting (e.g., generate 3 versions, pick the one that passes tests).
Failing to Validate Outputs
Generated code must be validated against the specification. Relying on the LLM’s own output as correct invites bugs. Implement automated validation pipelines that verify functional correctness.
Mixing Code and Spec Edits
If you manually edit generated code, you break the “spec as source of truth” principle. Always edit the specification, then regenerate. If urgent fixes are needed, treat them as spec changes first.
Summary
Context-driven agentic architecture leverages LLMs as reasoning engines by placing rigorous context artifacts—specifications, constraints, examples—at the core. The software specification becomes the single source of truth, while code is treated as an intermediate, disposable output. By following the steps of defining context artifacts, designing structured interaction patterns, implementing a spec-first workflow, and iterating with validation, you can build robust, adaptive systems that harness the stochastic power of LLMs without losing control. Remember: context is the key.
Back to Prerequisites