Working with Tools
Tools are functions that agents invoke to perform specific operations. The SDK supports four tool types: custom Python tools (MCP), inline JavaScript tools, platform tool library references, and knowledge tools.Prerequisites
- AgenticAI Core SDK installed and configured.
- Python 3.8+ for custom tool development.
- Familiarity with
async/awaitin Python.
Tool types
Custom tools (MCP)
Create Python functions using the@Tool.register decorator. These tools register automatically to ToolsRegistry and support request context, logging, tracing, and type-safe parameters:
Inline tools
Define tools directly in configuration with JavaScript code:Tool library
Reference pre-built platform tools:Knowledge tools
Access knowledge bases and RAG systems:Use request context
Access request metadata inside any tool usingRequestContext:
Memory operations
Usecontext.get_memory() to store and retrieve session data:
result.success before accessing data. Provide fallback values for missing data and use projections to retrieve only the fields you need.
Logging
Use theLogger class for structured logging. Initialize it with a tool name and call the appropriate log level method:
| Level | Use for |
|---|---|
DEBUG | Detailed diagnostic information. |
INFO | General execution flow. |
WARNING | Potentially problematic situations. |
ERROR | Serious failures. |
Distributed tracing
Decorate tools with@tracer.observe to capture execution spans:
Add tools to agents
Pass tools toAgentBuilder during configuration. Custom tools registered with @Tool.register are available automatically at runtime:
Best practices
- Tool design: Keep tools focused on a single operation. Write clear, detailed descriptions — the agent uses these to decide when to call a tool. Use meaningful parameter names. Handle errors explicitly.
- Logging: Log tool entry, exit, and parameter values. Log errors with enough context to diagnose the issue. Use the appropriate log level for each message.
- Memory: Always check
result.successbefore using returned data. Use projections to fetch only required fields. Handle missing or null data with fallback values. - Error handling: Catch and log exceptions. Return meaningful error messages. Avoid exposing sensitive data in error responses.
- Performance: Keep tools lightweight and focused. Use
async/awaitcorrectly — avoid blocking calls. Monitor execution times with distributed tracing.