Skip to main content

A Python package for Veris AI tools

Project description

Veris AI Python SDK

A Python package for Veris AI tools with simulation capabilities and FastAPI MCP (Model Context Protocol) integration.

Quick Reference

Purpose: Tool mocking, tracing, and FastAPI MCP integration for AI agent development
Core Components: tool_mockobservabilityfastapi_mcpjaeger_interface
Deep Dive: Module ArchitectureTesting GuideUsage Examples
Source of Truth: Implementation details in src/veris_ai/ source code

Installation

# Base package
uv add veris-ai

# With optional extras
uv add "veris-ai[dev,fastapi,instrument]"

Installation Profiles:

  • dev: Development tools (ruff, pytest, mypy)
  • fastapi: FastAPI MCP integration
  • observability: OpenTelemetry tracing

Import Patterns

Semantic Tag: import-patterns

# Core imports (base dependencies only)
from veris_ai import veris, JaegerClient

# Optional features (require extras)
from veris_ai import init_observability, instrument_fastapi_app  # Provided by SDK observability helpers

Complete Import Strategies: See examples/README.md for five different import approaches, conditional features, and integration patterns.

Configuration

Semantic Tag: environment-config

Variable Purpose Default
VERIS_ENDPOINT_URL Mock server endpoint Required
VERIS_MOCK_TIMEOUT Request timeout (seconds) 90.0
ENV Set to "simulation" for mock mode Production
VERIS_SERVICE_NAME Tracing service name Auto-detected
VERIS_OTLP_ENDPOINT OpenTelemetry collector Required for tracing

Configuration Details: See src/veris_ai/tool_mock.py for environment handling logic.

SDK Observability Helpers

The SDK provides optional-safe observability helpers that standardize OpenTelemetry setup and W3C context propagation across services.

from fastapi import FastAPI
from veris_ai import init_observability, instrument_fastapi_app

# Initialize tracing/export early (no-op if dependencies are absent)
init_observability(service_name="my-customer-service")

app = FastAPI()

# Ensure inbound HTTP requests continue W3C traces
instrument_fastapi_app(app)

What this enables:

  • Sets global W3C propagator (TraceContext + Baggage)
  • Optionally instruments FastAPI, requests, httpx, MCP client if installed
  • Includes request hooks to attach outbound traceparent on HTTP calls for continuity

End-to-end propagation with the simulator:

  • The simulator injects W3C headers when connecting to your FastAPI MCP endpoints
  • The SDK injects W3C headers on /api/v2/tool_mock and logging requests back to the simulator
  • Result: customer agent spans and tool mocks appear under the same distributed trace

Function Mocking

Semantic Tag: tool-mocking

Core Decorators

from veris_ai import veris

# Mock mode: Returns simulated responses in ENV=simulation
@veris.mock()
async def your_function(param1: str, param2: int) -> dict:
    """Function documentation for LLM context."""
    return {"result": "actual implementation"}

# Spy mode: Executes function but logs calls/responses
@veris.mock(mode="spy")
async def monitored_function(data: str) -> dict:
    return process_data(data)

# Stub mode: Returns fixed value in simulation
@veris.stub(return_value={"status": "success"})
async def get_data() -> dict:
    return await fetch_from_api()

Behavior: In simulation mode, decorators intercept calls to mock endpoints. In production, functions execute normally.

Implementation: See src/veris_ai/tool_mock.py for decorator logic and API integration.

FastAPI MCP Integration

Semantic Tag: fastapi-mcp

Expose FastAPI endpoints as MCP tools for AI agent consumption using HTTP transport.

from fastapi import FastAPI
from veris_ai import veris

app = FastAPI()

# Enable MCP integration with HTTP transport
veris.set_fastapi_mcp(
    fastapi=app,
    name="My API Server",
    include_operations=["get_users", "create_user"],
    exclude_tags=["internal"]
)

# Mount the MCP server with HTTP transport (recommended)
veris.fastapi_mcp.mount_http()

Key Features:

  • HTTP Transport: Uses Streamable HTTP protocol for better session management
  • Automatic schema conversion: FastAPI OpenAPI → MCP tool definitions
  • Session management: Bearer token → session ID mapping
  • Filtering: Include/exclude operations and tags
  • Authentication: OAuth2 integration

Transport Protocol: The SDK uses HTTP transport (via mount_http()) which implements the MCP Streamable HTTP specification, providing robust connection handling and fixing session routing issues with concurrent connections.

Configuration Reference: See function signature in src/veris_ai/tool_mock.py for all set_fastapi_mcp() parameters.

Utility Functions

Semantic Tag: json-schema-utils

from veris_ai.utils import extract_json_schema

# Schema extraction from types
user_schema = extract_json_schema(User)  # Pydantic models
list_schema = extract_json_schema(List[str])  # Generics

Supported Types: Built-in types, generics (List, Dict, Union), Pydantic models, TypedDict, forward references.

Implementation: See src/veris_ai/utils.py for type conversion logic.

Development

Semantic Tag: development-setup

Requirements: Python 3.11+, uv package manager

# Install with dev dependencies
uv add "veris-ai[dev]"

# Quality checks
ruff check --fix .    # Lint and format
pytest --cov=veris_ai # Test with coverage

Testing & Architecture: See tests/README.md for test structure, fixtures, and coverage strategies. See src/veris_ai/README.md for module architecture and implementation flows.

Module Architecture

Semantic Tag: module-architecture

Core Modules: tool_mock (mocking), jaeger_interface (trace queries), utils (schema conversion)

Complete Architecture: See src/veris_ai/README.md for module overview, implementation flows, and configuration details.

Jaeger Trace Interface

Semantic Tag: jaeger-query-api

from veris_ai.jaeger_interface import JaegerClient

client = JaegerClient("http://localhost:16686")
traces = client.search(service="veris-agent", tags={"error": "true"})

Complete Guide: See src/veris_ai/jaeger_interface/README.md for API reference, filtering strategies, and architecture details.


License: MIT License - see LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

veris_ai-1.6.0.tar.gz (165.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

veris_ai-1.6.0-py3-none-any.whl (21.2 kB view details)

Uploaded Python 3

File details

Details for the file veris_ai-1.6.0.tar.gz.

File metadata

  • Download URL: veris_ai-1.6.0.tar.gz
  • Upload date:
  • Size: 165.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.11

File hashes

Hashes for veris_ai-1.6.0.tar.gz
Algorithm Hash digest
SHA256 342ac513446f22d7d137afcd7f05b0419dc8bf2709d59882255034a4a572ed75
MD5 99e12f5c544caaf940bae8300210c6bf
BLAKE2b-256 52253cd76e05cef275be26176d2060b31c4a0c0de59e8718eac6b5d36e259a24

See more details on using hashes here.

File details

Details for the file veris_ai-1.6.0-py3-none-any.whl.

File metadata

  • Download URL: veris_ai-1.6.0-py3-none-any.whl
  • Upload date:
  • Size: 21.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.11

File hashes

Hashes for veris_ai-1.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0b5d77c59641e8e8ad7f389c37d5aa862da19ef914583c06caa29edbf21f23f8
MD5 85aa710f05ffb00d954e6ddd3c94ee05
BLAKE2b-256 64ef0dad4a2ab9531d96bfda782edb404ca4d02135d0f29a3582c393cd7b122c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page