More at guides.raaf-ai.dev:

RAAF Tools Guide

This comprehensive guide covers the complete tool ecosystem in Ruby AI Agents Factory (RAAF). Tools transform AI agents from passive conversationalists into active system participants capable of real-world interactions and autonomous task completion.

After reading this guide, you will know:

  • The architectural significance of tools in AI systems
  • All available built-in tools and their optimal use cases
  • How to create custom tools that extend agent capabilities
  • Security patterns and best practices for tool deployment
  • Performance optimization strategies for tool execution
  • Real-world patterns learned from production deployments

1. Understanding Tools in AI Systems

Tools represent the fundamental bridge between AI reasoning and external action. They transform language models from information processors into system actors capable of retrieving data, executing operations, and completing workflows autonomously.

The presence of tools creates a paradigm shift in AI interaction. Without tools, agents can only describe what should be done. With tools, agents become participants in your systems, capable of verification, iteration, and task completion. This transformation from advisor to actor fundamentally changes how we design AI applications.

Consider the difference: An agent without tools might say "You should check the database for that customer's order." An agent with tools queries the database, retrieves the order, identifies any issues, and potentially resolves them—all within a single interaction. This capability transforms user expectations and system design patterns.

The architectural implications extend beyond individual capabilities. Tools enable agents to participate in existing workflows rather than requiring parallel systems. They provide feedback loops that allow agents to verify their actions and adjust their approach. Most importantly, they create accountability through audit trails of what was attempted, what succeeded, and what failed.

2. Built-in Tools Reference

Web search provides agents with access to current information beyond their training data. This capability transforms agents from static knowledge bases into dynamic research assistants capable of finding up-to-date information on any topic.

The knowledge recency challenge represents one of the fundamental limitations of traditional language models. Models trained on data up to a certain date cannot answer questions about events after that date. Web search eliminates this limitation, enabling agents to research current events, find recent documentation, verify facts, and discover emerging trends.

Effective web search usage requires understanding its strengths and limitations. The tool excels at finding factual information, current news, technical documentation, and general knowledge. However, search results require interpretation—agents must evaluate source credibility, synthesize multiple perspectives, and distinguish between authoritative information and speculation.

When implementing agents with web search, consider the search strategy carefully. Broad queries return diverse results but may lack specificity. Narrow queries find precise information but may miss important context. The most effective agents use iterative search strategies, starting broad to understand the landscape, then narrowing to find specific details.

Performance considerations matter significantly with web search. Each search operation involves network latency and API costs. Implement caching for common queries, but ensure cache invalidation for time-sensitive information. Consider implementing search result summaries to reduce the amount of data the agent must process.

2.2. File Operations

File operations enable agents to interact with local and remote file systems, creating a bridge between AI capabilities and document management. These tools transform agents into document processors capable of reading, analyzing, and generating files across various formats.

The file abstraction in RAAF handles complexity transparently. Agents work with file paths and content without concerning themselves with encoding, format detection, or access permissions. This abstraction enables agents to focus on business logic rather than technical implementation details.

Common file operation patterns include document analysis workflows where agents read multiple files to synthesize information, report generation where agents create structured documents from data analysis, and configuration management where agents read and update system configurations based on requirements.

Security considerations for file operations require careful attention. Implement path validation to prevent directory traversal attacks. Use whitelists for allowed file types and locations. Consider read-only access by default, requiring explicit permissions for write operations. Always validate file content before processing to prevent injection attacks.

Performance optimization for file operations focuses on minimizing I/O overhead. Implement streaming for large files rather than loading entire contents into memory. Use file metadata to make decisions before reading full content. Cache frequently accessed files, but ensure cache invalidation when files change.

2.3. Code Execution

Code execution tools provide agents with computational capabilities beyond natural language processing. This transforms agents from advisors into problem solvers capable of data analysis, algorithm implementation, and complex calculations.

The computational extension that code execution provides cannot be overstated. Language models excel at pattern recognition and generation but struggle with precise calculations, data transformations, and algorithmic operations. Code execution bridges this gap, enabling agents to perform exact computations, implement algorithms, and process structured data.

Security represents the primary concern with code execution. Every execution environment must be sandboxed to prevent malicious code from affecting the host system. Resource limits prevent runaway computations from consuming excessive CPU or memory. Network isolation prevents unauthorized external communications. These security measures must be non-negotiable in production deployments.

Common code execution patterns include data analysis where agents write Python code to process datasets, visualization where agents generate charts and graphs from data, algorithm implementation where agents solve computational problems, and validation where agents verify calculations or test hypotheses.

The feedback loop created by code execution enables iterative problem-solving. Agents can write code, execute it, observe results, and refine their approach. This capability transforms single-shot interactions into collaborative problem-solving sessions where agents and users work together to find solutions.

2.4. Database Operations

Database tools enable agents to interact with structured data stores, transforming them into data analysts and system operators. These tools bridge the gap between natural language queries and SQL operations, enabling non-technical users to access complex data through conversational interfaces.

The abstraction layer provided by database tools handles the complexity of SQL generation, query optimization, and result formatting. Agents can focus on understanding user intent and providing meaningful insights rather than wrestling with syntax and database specifics.

Security in database operations requires multiple layers of protection. Implement read-only access by default, requiring explicit permissions for write operations. Use parameterized queries to prevent SQL injection. Implement row-level security to ensure agents only access appropriate data. Always audit database operations for compliance and security analysis.

Performance considerations for database operations focus on query optimization and result management. Implement query timeouts to prevent long-running operations. Use pagination for large result sets. Consider implementing a query cache for frequently requested data, but ensure proper cache invalidation when data changes.

Common patterns include report generation where agents query multiple tables to create comprehensive summaries, data validation where agents verify data integrity across systems, and operational queries where agents help users find specific records or understand data relationships.

Vector search enables semantic information retrieval, transforming how agents find and use relevant information. Unlike keyword-based search, vector search understands meaning and context, finding conceptually related information even when exact terms don't match.

The semantic understanding provided by vector search represents a fundamental advancement in information retrieval. Traditional searches match keywords; vector search matches concepts. This capability enables agents to find relevant information based on meaning rather than specific word choices, dramatically improving retrieval quality.

Implementation patterns for vector search focus on building and maintaining high-quality vector stores. Document chunking strategies affect retrieval quality—too large and chunks contain irrelevant information, too small and they lack context. Embedding model selection impacts both quality and performance. Regular reindexing ensures the vector store remains current and relevant.

Performance optimization for vector search requires balancing accuracy with speed. Approximate nearest neighbor algorithms trade perfect accuracy for dramatic speed improvements. Filtering before vector search reduces the search space. Caching frequent queries improves response time while managing costs.

2.6. External System Integration

Integration tools connect agents to existing business systems, enabling participation in established workflows. These tools transform agents from isolated assistants into integrated team members capable of working within existing processes.

The integration challenge extends beyond technical API connections. Agents must understand business processes, follow established workflows, and respect system constraints. This requires careful tool design that encapsulates business logic while providing clear interfaces for agent interaction.

Authentication and authorization represent critical concerns for integration tools. Implement OAuth flows for user-specific access. Use service accounts for system-level operations. Always apply the principle of least privilege, granting only the minimum access required for specific operations.

Common integration patterns include CRM interactions where agents look up customer information and update records, ticketing systems where agents create and update support tickets, and communication platforms where agents send notifications and respond to queries.

3. Creating Custom Tools

Custom tools extend agent capabilities to match specific business requirements. The process of creating effective tools requires understanding both technical implementation and AI interaction patterns.

The tool contract forms the foundation of reliable agent-tool interaction. Every tool must clearly define its purpose, parameters, and expected outputs. This contract enables agents to understand when and how to use tools effectively. Ambiguous contracts lead to misuse and errors.

Parameter design significantly impacts tool usability. Parameters should reflect how users think about the task, not implementation details. A date parameter should accept natural formats like "tomorrow" or "next Monday" rather than requiring specific timestamp formats. This human-centric design improves both agent and user experience.

Error handling in tools requires special consideration for AI contexts. Rather than throwing exceptions that terminate execution, tools should return structured error information that agents can interpret and communicate. This enables graceful degradation where agents can try alternative approaches or request user assistance.

Testing custom tools involves both traditional unit tests and AI interaction tests. Unit tests verify correct behavior with known inputs. AI interaction tests verify that agents can discover, understand, and use tools effectively. This dual testing approach ensures tools work correctly in both isolation and integration.

4. Tool Security Patterns

Security in tool design requires defense-in-depth strategies that protect against both accidental misuse and deliberate attacks. Every tool represents a potential security boundary that must be carefully managed.

Input validation forms the first line of defense. Every parameter must be validated for type, format, and content. Path parameters require validation against directory traversal. Query parameters need protection against injection attacks. Even seemingly safe parameters can become attack vectors without proper validation.

Authentication and authorization must be explicit and auditable. Tools should never rely on implicit security contexts. Every operation should verify that the requesting agent has appropriate permissions. Audit logs should capture who requested what operation when, enabling both security analysis and compliance reporting.

Resource limits prevent both accidental and deliberate resource exhaustion. CPU timeouts prevent infinite loops. Memory limits prevent excessive allocation. Network limits prevent data exfiltration. These limits should be configurable but have secure defaults that protect system stability.

Sandboxing provides isolation between tool execution and the host system. Process isolation prevents tools from accessing unauthorized resources. Network isolation prevents unauthorized communications. Filesystem isolation limits access to approved directories. These isolation mechanisms must be mandatory, not optional.

5. Performance Optimization

Tool performance directly impacts user experience and system costs. Optimization requires understanding both individual tool performance and system-wide interactions.

Latency optimization focuses on reducing time-to-first-result. Implement connection pooling to avoid setup overhead. Use caching for frequently requested data. Consider implementing speculative execution for predictable operations. Every millisecond of latency compounds across complex agent workflows.

Throughput optimization enables handling increased load without proportional resource increases. Implement batching for operations that support it. Use asynchronous processing for non-blocking operations. Consider implementing circuit breakers to prevent cascade failures during high load.

Resource optimization reduces operational costs while maintaining performance. Implement lazy loading to defer expensive operations until needed. Use streaming for large data processing to reduce memory footprint. Consider implementing resource pooling to amortize setup costs across multiple operations.

Monitoring and profiling provide visibility into optimization opportunities. Track operation latency at percentiles, not just averages. Monitor resource consumption patterns to identify bottlenecks. Profile tool execution to understand where time is spent. Data-driven optimization yields better results than intuition-based changes.

6. Real-World Tool Patterns

Production deployments reveal patterns that emerge from real-world usage. Understanding these patterns helps design more effective tool strategies.

The tool orchestration pattern emerges when complex tasks require multiple tools working in sequence. Rather than exposing low-level tools, create higher-level abstractions that encapsulate common workflows. This reduces agent complexity while improving reliability.

The fallback pattern provides resilience when primary tools fail. Web search can fall back to cached results. External APIs can fall back to local approximations. This pattern ensures agents remain helpful even when some capabilities are unavailable.

The progressive enhancement pattern starts with basic capabilities and adds advanced features based on context. A file reading tool might start with plain text extraction but progressively add format-specific parsing, metadata extraction, and content analysis based on file type and user needs.

The audit trail pattern ensures every tool operation is traceable. This supports debugging, security analysis, and compliance requirements. Well-designed audit trails answer who did what, when, why, and what was the result.

7. Best Practices Summary

Effective tool design balances capability with safety, performance with flexibility. Tools should be powerful enough to be useful but constrained enough to be safe. They should be fast enough for interactive use but thorough enough for correctness.

Design tools for both human and AI users. Clear naming, intuitive parameters, and helpful error messages benefit both audiences. Documentation should explain not just what tools do but when and why to use them.

Test tools thoroughly in both isolation and integration. Unit tests verify correctness. Integration tests verify usability. Load tests verify scalability. Security tests verify safety. Comprehensive testing prevents production surprises.

Monitor tools continuously in production. Track usage patterns to understand how tools are actually used versus how they were designed to be used. Monitor performance metrics to identify optimization opportunities. Analyze error patterns to improve reliability.

Evolve tools based on usage patterns. The best tool designs emerge from understanding how agents and users actually work together. Be prepared to refactor tools as usage patterns become clear. The goal is tools that feel natural and powerful for their intended use cases.

8. Next Steps



Back to top