Tool Integration Principles
The VoltAgent is available through thecreateTool
APIs encapsulate external services as standard tools that intelligences can call upon as needed to accomplish real-world tasks.
Typical Application Scenarios
- E-commerce customer service: Connect to the order system to check the logistics status
- data analysis: Interface with GitHub API to get repository information
- office automation: Integrate Calendar API to manage scheduling
Example of implementation
Below is the definition of the tool that connects to the GitHub API to get the number of stars:
const fetchRepoStarsTool = createTool({ name: "fetchRepoStars", description: "获取GitHub仓库星标数", execute: async ({ repo }) => { const response = await fetch(`https://api.github.com/repos/${repo}`); const data = await response.json(); return { stars: data.stargazers_count }; }, });
Binding method
Intelligentsia are created with thetools
Parameter registration tool:
const agent = new Agent({ tools: [fetchRepoStarsTool], //...其他参数 });
Debugging Tips
The tool invocation process is fully documented in the debugging console, including information on request parameters, response data, and execution elapsed time.
This answer comes from the articleVoltAgent: TypeScript Open Source Framework for Rapidly Building AI IntelligentsiaThe