It's about clear responsibility. Here you can see a so-called anti-pattern of a guard agent when in case of designing a code writing system against a contract code writing system. This agent is responsible for code review, for quality, for security checks, for test coverage. As a result, we have more than 3000 plus tokens trying to solve all existing problems. What can we propose as an alternative, what is the best practice? Try to apply bounded context, try to split this mess into a separate context, for instance, quality context, security context, and so on. Each context is responsible for a separate task. Each context provides a separate artifact. For instance, quality context answers the question whether this code is well-crafted security, whether this code is secure enough, and as an artifact, each context provides a separate artifact, for instance, quality, some kind of quality reports, security reports, and CV checks, and risk levels, and as a result, we have a significant decrease of a complexity of our initial prompt from thousands of tokens to a measurable hundred of tokens. And as a first rule, as a first outcome, we have is try to apply bounded context, one agent is one bounded context, one responsibility.
The second pattern is a contract as a schema. The problem is that without contracts, agent's output is unstructured, and every agent which receives this output can parse it and interpret it in a different way. What can we propose as an alternative? Apply contracts, apply structurized schemas, and, for instance, treat it as a pedantic model. So, for instance, a pedantic model can represent your contract, which represents this integration between contexts, which help us explicitly define the expectation from an agent's output and shape it in a structured way. Also, can give us the opportunity of benefits of self-documenting, because schema is a document, it can be automatically validated by, for instance, pedantic, it can be versions explicitly, and we don't even need any parsing logic because of this structure from day one. That's why we have a second rule. We need to stop using natural language as our API. We should use structured schemas as our contracts.
But let's look how to make this contract's production ready. To do this, we have two patterns, so-called port and adapters of hexagonal architecture and CI gates. Ports will define what our agent needs. It's in a contract. Adapter just translates external system to our domain. And it means that agent does not know about external format, because adapter just absorbs this complexity. When something changes in external system, we just need to update our adapter and the domain still stay protected and staying safe. And since our contracts are standardized and structured, we can automate pre- and post-deployment checks, tests and validations around these contracts with the help of respective CI gates. So contracts define correctness and CI gates just enforce it. Okay, the third pattern, it's a so-called anti-corruption layer. We can consider, we can treat it as a semantic firewall. The main problem is that in different contexts, in different boundaries, the same term can have different meaning, different definition. For instance, for code generation contract, function is a signature plus implementation.
Comments