AgentMonitor class is the core component of the AI Agents House SDK, providing comprehensive monitoring capabilities for AI agents. It handles event tracking, agent registration, compliance monitoring, and data transmission to the AI Agents House platform.
Constructor
AgentMonitor(config)
Creates a new instance of the AgentMonitor with the specified configuration.AgentMonitoringConfig
required
Configuration object for the monitor instance.
Agent Registration
registerAgent(agent)
Registers an agent with the monitoring system before tracking its interactions.AgentInfo
required
Agent information and configuration.
Promise<void>
Example:
Event Tracking Methods
trackConversationStart(agentId, sessionId, userId?, metadata?)
Tracks the beginning of a new conversation session.string
required
The ID of the agent handling the conversation.
string
required
Unique identifier for the conversation session.
string
Optional identifier for the user initiating the conversation.
object
Optional metadata object with additional context.
trackUserMessage(agentId, sessionId, content, userId?, metadata?)
Tracks a message from the user to the agent.string
required
The ID of the agent receiving the message.
string
required
The conversation session identifier.
string
required
The content of the user’s message.
string
Optional user identifier.
object
Optional metadata with additional context.
trackAgentResponse(agentId, sessionId, content, metadata?, options?)
Tracks a response from the agent to the user.string
required
The ID of the responding agent.
string
required
The conversation session identifier.
string
required
The content of the agent’s response.
object
Optional metadata including performance and quality metrics.
MonitoringOptions
Optional monitoring configuration for this specific interaction.
trackToolCall(agentId, sessionId, toolName, parameters, result?, executionTime?, metadata?)
Tracks when an agent uses a tool or external function.string
required
The ID of the agent making the tool call.
string
required
The conversation session identifier.
string
required
The name of the tool being called.
any
required
The parameters passed to the tool.
any
The result returned by the tool (if available).
number
Time taken to execute the tool in milliseconds.
object
Optional metadata with additional context.
trackError(agentId, sessionId, error, metadata?)
Tracks errors that occur during agent interactions.string
required
The ID of the agent where the error occurred.
string
required
The conversation session identifier.
string | Error
required
The error message or Error object.
object
Optional metadata with error details.
trackConversationEnd(agentId, sessionId, metadata?)
Tracks the end of a conversation session.string
required
The ID of the agent ending the conversation.
string
required
The conversation session identifier.
object
Optional metadata with conversation summary.
track(agentId, event, options?)
Generic method for tracking any type of interaction event.string
required
The ID of the agent associated with the event.
InteractionEvent
required
The event object to track.
MonitoringOptions
Optional monitoring configuration.
Utility Methods
flush()
Forces immediate transmission of all pending events to the platform. Returns:Promise<void>
Example:
shutdown()
Gracefully shuts down the monitor, flushing any remaining events and cleaning up resources. Returns:Promise<void>
Example:
Properties
complianceEngine
Access to the compliance engine instance (if enabled). Type:ComplianceEngine | undefined
Example:
Error Handling
The AgentMonitor class handles errors gracefully and provides detailed error information:Best Practices
Event Tracking
Event Tracking
- Use consistent session IDs across related interactions
- Include relevant metadata for better analytics
- Track errors with sufficient context for debugging
- Use meaningful agent IDs and descriptions
Performance
Performance
- Configure appropriate batch sizes for your volume
- Use suitable flush intervals based on latency requirements
- Monitor memory usage with large event volumes
- Call shutdown() during application cleanup
Error Handling
Error Handling
- Wrap critical operations in try-catch blocks
- Monitor failed requests and adjust retry settings
- Use graceful degradation when monitoring fails
- Log monitoring errors for debugging
Configuration
Configuration
- Use environment variables for sensitive configuration
- Adjust settings based on deployment environment
- Enable compliance checks for regulated environments
- Configure logging appropriately for each environment
Next Steps
Compliance Engine
Learn about the ComplianceEngine class and custom rules
Type Definitions
Complete TypeScript type definitions
Integration Examples
Practical examples and integration patterns
Performance Guide
Optimization strategies for high-volume scenarios
