Best Practices & Patterns¶
This section describes architectural patterns and best practices for building robust, secure, and high-quality tools within the aifred-tk ecosystem.
Following these patterns ensures that your tools behave consistently across different execution environments (CLI, MCP, etc.) and provide the best possible experience for both users and the LLMs driving them.
Core Patterns¶
- Thinking (Reasoning): Strategies to improve LLM accuracy by encouraging step-by-step reasoning.
- Elicitation: Patterns for "human-in-the-loop" workflows using the elicitation API.
- LLM-Human-LLM Interrogation: Multi-turn loops where the agent "interviews" the user.
- XML Isolation: Protecting against prompt injection when handling untrusted data.
- Lazy Agent Instantiation: Ensuring plugins are "safe to load" by deferring heavy initialisation.
General Principles¶
- Environment Agnostic: Tools should work equally well in a terminal or inside an MCP client.
- Security First: Always assume external data (files, URLs, user input) is untrusted.
- Lazy Loading: Don't fail the entire toolkit just because one tool is missing a configuration key.
- Human-in-the-Loop: High-stakes decisions should always be validated by a human.