Tools¶
Sikka Agent provides a variety of tools that extend the capabilities of your agents. These tools are designed to be modular and can be combined to create powerful agents.
How LLMs Determine Function Parameters and Select Tools¶
When a user sends a message to an agent, the LLM analyzes the content to determine which tool to use and how to fill in the required parameters. Here's a simple example:
from sikkaagent.agents.chat_agent import ChatAgent
from sikkaagent.models.model_configure import ModelConfigure
from sikkaagent.storages.in_memory import InMemoryStorage
from sikkaagent.tools.weather_toolkit import WeatherToolkit
from sikkaagent.utils.enums import ModelPlatformType, ModelType
agent = ChatAgent(
model=ModelConfigure(
model=ModelType.GPT_4_TURBO,
model_platform=ModelPlatformType.OPENAI,
config={"temperature": 0.7}
),
memory=InMemoryStorage(),
tools=[*WeatherToolkit().get_tools()]
)
# User message doesn't explicitly mention parameter names
response = agent.step(message="What's the weather like in New York today?")
In this example:
- The user message doesn't explicitly say "city=New York" but the LLM understands that "New York" is the location parameter
- The LLM automatically extracts "New York" as the city parameter for the weather tool
- The LLM determines that the WeatherToolkit's get_current_weather tool is appropriate because the message is asking about current weather conditions
When multiple tools are available, the LLM selects the most appropriate one based on:
- The specific request in the user's message
- The tool descriptions and parameter requirements
- The context of the conversation
For example, if both weather and terminal tools are available, and the user asks about weather, the LLM will choose the weather tool rather than trying to execute a terminal command to get weather information.
Available Toolkits¶
Sikka Agent includes several pre-built toolkits:
MLXTranscribeToolkit¶
A toolkit for audio transcription using Apple's MLX framework, optimized for Apple Silicon processors.
import os
from sikkaagent.agents.chat_agent import ChatAgent
from sikkaagent.models.model_configure import ModelConfigure
from sikkaagent.storages.in_memory import InMemoryStorage
from sikkaagent.tools.mlx_transcribe_toolkit import MLXTranscribeTools
from sikkaagent.utils.enums import ModelPlatformType, ModelType
# Set the base directory for audio files
base_dir = os.path.dirname(os.path.abspath(__file__))
agent = ChatAgent(
model=ModelConfigure(
model=ModelType.LLAMA_3_1_70B_INSTRUCT,
model_platform=ModelPlatformType.AWS_BEDROCK,
config={
"temperature": 0.7,
"max_tokens": 1000,
}
),
role_name="Assistant",
memory=InMemoryStorage(),
tools=[*MLXTranscribeTools(base_dir=base_dir).get_tools()],
)
# Transcribe an audio file
response = agent.step(message=f"Transcribe the audio file `harvard.wav` and summarize its content")
TerminalToolkit¶
A toolkit for executing shell commands and interacting with the terminal.
import os
from sikkaagent.agents.chat_agent import ChatAgent
from sikkaagent.models.model_configure import ModelConfigure
from sikkaagent.storages.in_memory import InMemoryStorage
from sikkaagent.tools.terminal_toolkit import TerminalToolkit
from sikkaagent.utils.enums import ModelPlatformType
agent = ChatAgent(
model=ModelConfigure(
model="qwen2.5-coder:14b",
model_platform=ModelPlatformType.OLLAMA,
config={
"temperature": 0.7,
"max_tokens": 500
}
),
role_name="Assistant",
memory=InMemoryStorage(),
tools=[*TerminalToolkit().get_tools()],
)
base_dir = os.path.dirname(os.path.abspath(__file__))
response = agent.step(message=f"Create a 'logs' directory in '{base_dir}'")
Crawl4AIToolkit¶
A toolkit for web crawling and data extraction using the Crawl4AI library.
from sikkaagent.agents.chat_agent import ChatAgent
from sikkaagent.models.model_configure import ModelConfigure
from sikkaagent.storages.in_memory import InMemoryStorage
from sikkaagent.tools.crawl4ai_toolkit import Crawl4AIToolkit
from sikkaagent.utils.enums import ModelPlatformType, ModelType
agent = ChatAgent(
model=ModelConfigure(
model=ModelType.GPT_4_TURBO,
model_platform=ModelPlatformType.OPENAI,
config={
"temperature": 0.7,
"max_tokens": 1000,
}
),
role_name="Web Crawler Assistant",
memory=InMemoryStorage(),
tools=[*Crawl4AIToolkit().get_tools()],
)
# Perform a deep crawl on a website
response = agent.step(
message="Crawl the website 'https://example.com' with a max depth of 2 and look for pages containing the keywords 'privacy' and 'policy'"
)
# Use HTTP crawler for faster, more memory-efficient crawling
response = agent.step(
message="Use the HTTP crawler to fetch the content from 'https://example.com/about'"
)
# Process a PDF file from a URL
response = agent.step(
message="Extract text and metadata from the PDF at 'https://example.com/document.pdf'"
)
Other Toolkits¶
Sikka provides a comprehensive set of toolkits for various use cases:
- SearchToolkit: For performing web searches
- RetrievalToolkit: For retrieving information from documents
- BrowserToolkit: For web browsing and interaction
- MathToolkit: For mathematical calculations
- ExcelToolkit: For working with spreadsheets
- PDF OCR Toolkit: For extracting text from PDFs using OCR
- TerminalToolkit: For executing shell commands
- FileWriteToolkit: For writing data to files
- WeatherToolkit: For fetching weather information
- GitHubToolkit: For GitHub API interactions
- GoogleCalendarToolkit: For Google Calendar integration
- GoogleSheetsToolkit: For Google Sheets operations
- ImageAnalysisToolkit: For analyzing images
- JiraToolkit: For Jira issue management
- LinkedInToolkit: For LinkedIn interactions
- NotionToolkit: For Notion database operations
- PIISanitizeToolkit: For removing personal information
- SlackToolkit: For Slack messaging
- SQLToolkit: For database queries
- TwilioToolkit: For SMS and voice communications
- DockerToolkit: For Docker container and image management
- WebsiteToolkit: For website content extraction and knowledge base integration
- MLXTranscribeToolkit: For audio transcription using Apple's MLX framework
Reference: The toolkits are found in the sikkaagent/tools/
directory with files like browser_toolkit.py
, terminal_toolkit.py
, etc.
Creating Custom Tools¶
You can create custom tools by extending the BaseToolkit
class or by using the FunctionTool
class to convert any Python function into a tool.
from sikkaagent.tools import FunctionTool, BaseToolkit
def my_custom_function(input_text: str) -> str:
# Function implementation
return f"Processed: {input_text}"
# Create a tool from the function
my_tool = FunctionTool(my_custom_function)
# Or create a toolkit with multiple tools
class MyCustomToolkit(BaseToolkit):
def __init__(self):
# Initialize your toolkit
pass
Tools should handle errors gracefully and provide meaningful error messages:
def process_data(data: str) -> str:
try:
# Process the data
result = complex_process(data)
return result
except Exception as e:
log_error(f"Error processing data: {e}")
return f"Error: {str(e)}"
Documentation¶
Document your tools thoroughly using docstrings and type annotations:
def analyze_text(text: str, max_length: int = 100) -> Dict[str, Any]:
"""
Analyze the given text and return various metrics.
Args:
text (str): The text to analyze
max_length (int, optional): Maximum text length to process. Defaults to 100.
Returns:
Dict[str, Any]: A dictionary containing the analysis results
"""
# Implementation
pass