What you’ll need
- OpenAI API key
- Splunk Agent Observability API key
- Python environment with required packages
- Basic understanding of agentic AI concepts
Setup instructions
1
Set Up Your Environment
Create a
.env file with your API keys:2
Install Dependencies
Install required dependencies:
requirements.txt
3
Create Tool Definitions
Create a
tools.json file with tool definitions:tools.json
4
Running and Monitoring
Execute the application:Use Splunk Agent Observability to monitor:
- Tool usage patterns
- Query processing performance
- Error rates and types
- System performance evaluators
Implementation guide
Let’s break down the implementation into manageable sections:1. setting up the environment
First, we’ll set up our imports and initialize our environment:app.py
- Imports necessary libraries including Splunk Agent Observability components
- Loads environment variables
- Sets up rich console output
- Initializes the OpenAI client with Splunk Agent Observability integration
2. defining Pydantic models for structured output
app.py
- Uses Pydantic for data validation
- Defines clear models for structured outputs
- Loads tool definitions from external JSON file
3. implementing agent tools
The agent has two main tools, each decorated with Splunk Agent Observability’s logging:app.py
- Uses
@logdecorator with thetoolspan type for Splunk Agent Observability - Implements text-to-number conversion using LLM
- Implements a calculator for arithmetic operations
- Includes robust error handling and fallback mechanisms
4. query processing logic
The core agent functionality:app.py
- Loads tool definitions
- Constructs a clear system prompt with instructions
- Provides examples for the LLM to follow
- Makes the initial API call with tools
5. processing tool calls
The agent processes tool calls and manages the conversation flow:app.py
- Processes tool calls from the LLM
- Maintains conversation history
- Executes the appropriate tool functions
- Tracks the state of the conversation
6. handling incomplete sequences
The agent ensures that calculations are completed:app.py
- Detects incomplete calculation sequences
- Prompts the LLM to complete the calculation
- Processes additional tool calls
- Handles error cases
7. main application loop
The interactive interface:app.py
- User-friendly terminal interface
- Splunk Agent Observability context for request tracking
- Interactive question-answer loop
- Error handling and graceful exits
Key features
- Tool-Based Architecture: Modular design with specialized tools
- Splunk Agent Observability: Track tool usage and performance
- Robust Error Handling: Graceful handling of API and runtime errors
- Conversation Management: Proper tracking of conversation state
- Interactive Experience: User-friendly terminal interface
Next steps
- Add more sophisticated tools for complex operations
- Implement memory for multi-turn conversations
- Add evaluators for agent performance
- Integrate advanced Splunk Agent Observability logging features
- Implement parallel tool execution for efficiency