Supercharge your agents with powerful capabilities. Tools let your AI agents interact with the real world - from databases to APIs to custom business logic.
Think of tools as your agent’s superpowers! While agents are great at conversation, tools let them actually do things - like looking up orders, sending emails, or integrating with your favorite APIs. It’s like giving your AI a Swiss Army knife!
The AgentContext is your tool’s memory bank! It lets you access session info, store state between calls, and maintain context across conversations.
Using AgentContext
public function execute(array $arguments, AgentContext $context): string{ // Get session ID $sessionId = $context->getSessionId(); // Access state $previousOrder = $context->getState('last_order_id'); // Store state for future use $context->setState('last_order_id', $orderId); // Access user information if available $userId = $context->getState('user_id'); $userEmail = $context->getState('user_email'); // Your tool logic here... return json_encode(['status' => 'success']);}
Reading State
Use getState() to retrieve previously stored values
Writing State
Use setState() to persist data for future tool calls
Check for user authentication and access user-specific data safely:
User Context Validation
public function execute(array $arguments, AgentContext $context, AgentMemory $memory): string{ // Check if user context is available $userId = $context->getState('user_id'); if (!$userId) { return json_encode([ 'status' => 'error', 'message' => 'User authentication required', ]); } // Get user data from context $userData = $context->getState('user_data'); $userEmail = $context->getState('user_email'); // Store user-specific information if ($userEmail && !$memory->getFacts()->contains('content', "User email: {$userEmail}")) { $memory->addFact("User email: {$userEmail}", 1.0); } // Process with user context return json_encode(['status' => 'success']);}
Every Tool Gets Memory Access! - All tools now receive the agent’s memory as a third parameter. Build personalized experiences by reading and writing to memory!
The execute method now includes AgentMemory:
app/Tools/UserProfileTool.php
<?phpnamespace App\Tools;use Vizra\VizraADK\Contracts\ToolInterface;use Vizra\VizraADK\System\AgentContext;use Vizra\VizraADK\Memory\AgentMemory;class UserProfileTool implements ToolInterface{ public function definition(): array { return [ 'name' => 'manage_user_profile', 'description' => 'Update or retrieve user profile information from memory', 'parameters' => [ 'type' => 'object', 'properties' => [ 'action' => [ 'type' => 'string', 'description' => 'Action to perform', 'enum' => ['update_fact', 'add_preference', 'get_profile'] ], 'key' => ['type' => 'string'], 'value' => ['type' => 'string'] ], 'required' => ['action'] ] ]; } public function execute( array $arguments, AgentContext $context, AgentMemory $memory // Now included in all tools! ): string { switch ($arguments['action']) { case 'update_fact': $memory->addFact( "{$arguments['key']}: {$arguments['value']}", 1.0 ); return json_encode(['success' => true]); case 'add_preference': $memory->addPreference( $arguments['value'], $arguments['key'] ?? 'general' ); return json_encode(['success' => true]); case 'get_profile': return json_encode([ 'summary' => $memory->getSummary(), 'facts' => $memory->getFacts()->pluck('content'), 'preferences' => $memory->getPreferences() ]); } }}
Memory Methods Available
addFact() - Store immutable facts
addLearning() - Track insights
addPreference() - Store preferences
updateSummary() - Update user profile
Use Cases
Update user preferences from form submissions
Store discovered facts during conversations
Build comprehensive user profiles over time
Sync memory across different tools
Pro Tip: Simple Memory Usage - Every tool automatically receives the agent’s memory! Use it to store learnings, facts, and preferences. The memory persists across sessions, enabling truly personalized experiences.