Overview
Tool functions provide agents with capabilities to query structured databases and search unstructured knowledge bases. All tools are wrapped with LangSmith’straceable decorator for observability.
Database Tools
queryDatabase()
Executes SQL queries against a SQLite database and returns results as JSON.string
required
SQL query to execute. The agent should first discover the schema using
PRAGMA table_info() or SELECT name FROM sqlite_master WHERE type='table'string
required
File path to the SQLite database file
string
JSON-stringified array of query results, or error message if query fails
Usage Example
Schema Discovery Pattern
The tool description instructs the agent to always discover the schema first:Knowledge Base Tools
searchKnowledgeBase()
Searches the knowledge base using semantic similarity with embeddings.string
required
Natural language search query or question
number
default:2
Number of top results to return
string
Formatted string containing the most relevant documents with relevance scores, or error if knowledge base not loaded
Usage Example
Chunking Strategy (v3)
Agent version 3 implements text chunking for better retrieval:Embeddings Cache Management
embeddingsAreStale()
Checks if cached embeddings need regeneration by comparing modification times.string
required
Path to knowledge base documents directory
string
required
Path to embeddings cache file
boolean
True if embeddings need regeneration, false if cache is valid
generateAndCacheEmbeddings()
Generates embeddings for all knowledge base documents and caches them.string
required
Path to knowledge base documents directory
string
required
Path where embeddings cache should be saved
Tool Integration in Agent
Tools are integrated into the agent using OpenAI’s function calling:Best Practices
Database Queries
- Always discover schema first - Don’t assume table or column names
- Handle errors gracefully - Return error messages as strings
- Limit result sets - Use
LIMITto prevent overwhelming responses
Knowledge Base Search
- Load knowledge base on startup - Embeddings generation is expensive
- Use caching - Check for stale embeddings before regenerating
- Tune topK parameter - Balance context size vs. relevance
- Consider chunking - For large documents, chunk before embedding
Traceability
Both tools use LangSmith’straceable wrapper for observability:
- Automatic trace logging
- Performance monitoring
- Debugging and error tracking
- Cost analysis