Test AI agents running on your local endpoints or any HTTP-accessible service using the Maxim SDK’s Yields 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 the Yields 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}")

Next Steps