Instrument Your Agents
Replace parts of your existing agent with xpander’s backend capabilities
What is Agent Instrumentation?
Agent instrumentation is the process of enhancing your existing AI agent by integrating xpander’s backend capabilities. Rather than rebuilding your agent from scratch, you selectively replace key components with xpander’s services to gain advanced features like persistent memory, robust tool management, and multi-channel connectivity.
The Three Components to Instrument
When instrumenting your agent, focus on replacing these three essential components:
Message Management
Replace your conversation memory with xpander’s system: Thread-based chats, cross-session memory, and structured storage.
Tools Management
Replace your tool system with xpander’s: LLM provider conversion, built-in tools, and consistent patterns.
Event Handling
Replace your event handling with xpander’s: Multi-channel support, structured events, and agent communication.
Benefits of Instrumentation
By instrumenting your agent with xpander, you gain:
- Persistent Memory: Conversations are stored across sessions and accessible via API
- Powerful Tools: Access to xpander’s tool library and execution framework
- Multi-Interface Access: Connect to Slack, Discord, MCP, and other channels
- Execution Monitoring: Track agent activity and performance
- Agent Collaboration: Enable agent-to-agent delegation and communication
Set Up Your Environment
- Install the xpander CLI:
The SDK using JSII which allows code in any language to naturally interact with JavaScript class. Please make sure to use Node version 22 and above.
-
Install required Python packages:
-
Authenticate with xpander:
-
Configure your environment: Create a
.env
file with:
Create Your Agent Project
Run the agent creation wizard:
This command will guide you through creating a new agent and loading it into your current directory. The CLI generates a complete project structure:
Implementing Your Custom Agent
After setting up your project, you need to customize two key files:
1. Create Your Custom Agent Class
Create a file (e.g., myagent.py
) that implements your agent’s core logic while leveraging xpander’s backend services:
For detailed information on tool execution patterns, see the Tools and APIs guide.
2. Customize the Event Handler
Edit the xpander_handler.py
file generated by the CLI to integrate your custom agent:
Testing Your Instrumented Agent
To test your agent:
-
Run locally:
-
Access via web: Once running, your agent will be available at the URL displayed in the console.
-
Interact with your agent:
- Send messages through the web interface
- Watch as they’re processed locally with your custom logic
- Observe the real-time logs in your terminal
Cloud Deployment
When you’re ready to deploy your agent to the cloud:
This command packages your agent as a container and deploys it to the xpander cloud platform, making it accessible through all configured channels. You can monitor your deployed agent with: