Defining and Using Tools
Tools in AgentScope AI are modular, reusable functions that extend the capabilities of agents. They allow agents to interact with external APIs, perform computations, and handle specific tasks efficiently. Each tool consists of a defined schema, execution logic, and integration with external resources.
Creating a Tool
To define a tool, follow these steps:
Define the tool schema using
zod
for input validation.Implement the tool’s execution logic.
Register the tool with AgentScope AI.
Example: Creating a Weather Information Tool
The following example demonstrates how to create a tool that fetches weather data for a given city.
src/tools/weatherInfo.ts
Adding a Tool to an Agent
Once a tool is created, it must be assigned to an agent for usage.
Example: Adding weatherInfo
to an Agent
weatherInfo
to an Agentsrc/agents/weatherAgent.ts
Registering the Agent with AgentScope AI
To activate the agent with its tools, it must be registered within the system.
src/index.ts
This ensures that the agent is available within the AgentScope AI environment.
Calling an Agent with a Tool
Agents use tools dynamically based on requests. Here’s how to interact with the weatherAgent
.
src/index.ts
Debugging and Testing Tools
Tools can be tested independently using unit tests to ensure they function as expected.
Example: Unit Test for weatherInfo
Tool
Last updated