How to test local endpoints?
Test AI agents running on your local endpoints or any HTTP-accessible service using the Maxim SDK’sYields Output function. This approach gives you full control over how your agent is called and how the output is processed.
Basic Local Endpoint Testing
Use theYields Output function to call your agent’s HTTP endpoint for each test case (For demonstration purposes, here’s an example using the Postman Echo service):
import requests
from maxim import Maxim
from maxim.models import YieldedOutput
# Initialize Maxim SDK
maxim = Maxim({"api_key": "your-api-key"})
# Define test data
test_data = [
{
"input": "What are the benefits of renewable energy?",
"expected_output": "Renewable energy provides clean, sustainable power sources that reduce carbon emissions and environmental impact.",
"context": "Environmental sustainability",
},
{
"input": "How does machine learning work?",
"expected_output": "Machine learning algorithms learn patterns from data to make predictions or decisions without explicit programming.",
"context": "Technology education",
},
]
def call_local_agent(data):
"""Function to call your local agent endpoint"""
try: # Call your local agent endpoint
response = requests.post(
"https://postman-echo.com/post", # Your local endpoint
json={
"query": data["input"],
"context": data.get("context", ""),
"output": data.get("expected_output", ""),
},
headers={
"Content-Type": "application/json",
"Authorization": "Bearer your-local-api-key",
},
timeout=30,
)
if response.status_code == 200:
result = response.json()
data = result.get("data", "")
# Return the agent's response
return YieldedOutput(
data=data.get("output", ""),
retrieved_context_to_evaluate=data.get("context", ""),
)
else:
raise Exception(f"Error: HTTP {response.status_code} - {response.text}")
except requests.RequestException as e:
raise Exception(f"Error: HTTP {response.status_code} - {response.text}")
# Create and run the test
result = (
maxim.create_test_run(
name="Local Agent Endpoint Test", in_workspace_id="your-workspace-id"
)
.with_data_structure(
{
"input": "INPUT",
"expected_output": "EXPECTED_OUTPUT",
"context": "CONTEXT_TO_EVALUATE",
}
)
.with_data(test_data)
.with_evaluators("Bias")
.yields_output(call_local_agent)
.run()
)
print(f"Test run completed! View results: {result.test_run_result.link}")
import {
createDataStructure,
Maxim,
type Data,
type YieldedOutput,
} from '@maximai/maxim-js';
// Initialize Maxim SDK
const maxim = new Maxim({
apiKey: 'your-api-key',
});
const dataStructure = createDataStructure({
input: 'INPUT',
expectedOutput: 'EXPECTED_OUTPUT',
context: 'CONTEXT_TO_EVALUATE',
});
// Define test data
const testData: Data<typeof dataStructure>[] = [
{
input: 'What are the benefits of renewable energy?',
expectedOutput:
'Renewable energy provides clean, sustainable power sources that reduce carbon emissions and environmental impact.',
context: 'Environmental sustainability',
},
{
input: 'How does machine learning work?',
expectedOutput:
'Machine learning algorithms learn patterns from data to make predictions or decisions without explicit programming.',
context: 'Technology education',
},
];
// Function to call your local agent endpoint
async function callLocalAgent(
data: Data<typeof dataStructure>
): Promise<YieldedOutput> {
// Call your local agent endpoint
const response = await fetch('https://postman-echo.com/post', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer your-local-api-key',
},
body: JSON.stringify({
query: data.input,
context: data.context || '',
output: data.expectedOutput,
}),
});
if (response.ok) {
const result = (await response.json()) as unknown;
const data =
result &&
typeof result === 'object' &&
'data' in result &&
typeof result.data === 'object'
? result.data
: null;
// Return the agent's response
return {
data: data && 'output' in data ? String(data.output) : '',
retrievedContextToEvaluate:
data && 'context' in data
? Array.isArray(data.context)
? data.context.join('\n')
: String(data.context)
: '',
};
} else {
return {
data: `Error: HTTP ${response.status} - ${await response.text()}`,
};
}
}
// Create and run the test
const result = await maxim
.createTestRun('Local Agent Endpoint Test', 'your-workspace-id')
.withDataStructure(dataStructure)
.withData(testData)
.withEvaluators('Faithfulness', 'Clarity', 'Bias')
.yieldsOutput(callLocalAgent)
.run();
console.log(`Test run completed! View results: ${result.testRunResult.link}`);
Next Steps
- Endpoint on Maxim - Use workflows stored on the Maxim platform
- CI/CD Integration - Automate agent testing in your CI/CD pipeline