The gap between a slick AI agent demo and a reliable production system is wide enough to drive a truck through, according to new analysis by developer Martin Persson. In a recent post on DEV.to, Persson dismantles the hype around rapid prototyping, arguing that the real engineering challenge isn't connecting an LLM to an API, but defining strict boundaries for when those APIs fail. His solution? Leverage Effect.ts, a TypeScript functional programming library, to treat agent tools with the same rigor as any other backend service.
The Fragility of 'Just Prompt It'
Persson identifies a critical failure mode in modern agentic workflows: the blind trust of external data. When an agent retrieves a ticket from a project management system, most developers pass the raw JSON directly into the model's context window. This is dangerous. Persson advocates for using Effect's Schema to validate data structures before they ever touch the LLM. By enforcing types on fields like id, title, and area, the system prevents hallucinations born from malformed or unexpected API responses. If the data doesn't fit the schema, the agent doesn't guess; it fails explicitly.
Explicit Failure Modes in Type Signatures
The core of Persson's argument rests on making failure states visible in the code itself. Instead of wrapping API calls in generic try/catch blocks that swallow errors, he uses Effect's Data.TaggedError to define specific failure scenarios, such as TicketNotFound or InvalidTicket. These errors are part of the function's return type, forcing the developer to handle them explicitly. This approach transforms the agent's tool execution from a black box into a transparent pipeline where every potential crash point is known and managed before the model even generates a response.
Context as a Service, Not a Chat History
A recurring pain point in agentic development is context management. Persson rejects the practice of pasting static documentation into every prompt. Instead, he proposes a ContextService that dynamically retrieves relevant engineering guidelines based on the ticket's area (e.g., backend vs. frontend). This service ensures that the agent operates with up-to-date, team-specific knowledge without bloating the context window. By decoupling knowledge retrieval from the model interaction, the system remains testable and maintainable, allowing developers to update guidelines without retraining or re-prompting the entire stack.
The Illusion of Determinism
Persson is clear-eyed about what Effect.ts does and does not solve. It does not make the LLM deterministic; the model remains a probabilistic engine. However, it makes the deterministic parts of the systemβdata validation, error handling, and context retrievalβpredictable. He argues that testing should focus on these deterministic layers first. Can the system correctly reject a malformed ticket? Does it fetch the right guidelines? These questions can be answered without spending tokens on API calls, creating a faster feedback loop for developers building agent infrastructure.
Key Takeaways
- Validate all external data entering the agent's context using strict schemas to prevent garbage-in-garbage-out.
- Use typed errors (like Effect's
Data.TaggedError) to make failure modes explicit and handleable in the type system. - Abstract context retrieval into services rather than hardcoding prompts, enabling dynamic updates and easier testing.
- Separate deterministic logic from LLM inference to build a testable foundation that doesn't rely on model consistency.
- Start with read-only tools and minimal surface areas before expanding agent autonomy to mutation-heavy workflows.
The Bottom Line
If your agent can't handle a 404 without hallucinating a solution, it isn't ready for production. Effect.ts doesn't fix the model, but it builds the walls that keep the model from burning down the house.