Skip to content

PydanticAI

angelatgithub edited this page Sep 19, 2026 · 1 revision

Pydantic AI — pydantic-ai-algenta

AlgentaToolset — a WrapperToolset over pydantic-ai's own MCPToolset, pointed at your self-hosted engine. execute_decision's result parses into a typed ExecutionReceipt; denials surface through pydantic-ai's native ToolDenied primitive with the real gate name preserved.

PyPI

Install

pip install pydantic-ai-algenta

Depends on exactly two things: the published algenta-sdk and pydantic-ai-slim[mcp] (not the full pydantic-ai metapackage).

Quickstart

import asyncio
from pydantic_ai import Agent
from pydantic_ai_algenta import AlgentaToolset

async def main() -> None:
    toolset = AlgentaToolset(base_url="http://localhost:8000/mcp", profile="observe")
    agent = Agent("openai:gpt-5", toolsets=[toolset])
    result = await agent.run("What's the expected value of scenario X?")
    print(result.output)

asyncio.run(main())

profile="observe" is the default. Endpoint resolves from base_url= → ALGENTA_BASE_URL → http://localhost:8000/mcp (see Self-Hosted).

Profiles

All four, per the contract: observe (default) · govern · execute · full (opt-in). force/override_safety are stripped from advertised schemas and scrubbed from forwarded arguments, in every profile.

Notes

  • Why ToolDenied, not ApprovalRequired: an earlier version modeled an async approval-pause via pydantic-ai's deferred-approval primitives. Checked against the real engine, execute_decision has no "pending" state — a call succeeds or is denied by one of three named gates in the same call — so that machinery was removed. ToolDenied (what a human reviewer's "no" produces) is the correct, simpler fit.
  • Transport failures are not wrapped: a dropped connection or 5xx surfaces as pydantic-ai's own ToolFailed/ModelRetry before the toolset ever sees a result.
  • Try it locally: local_demo.py in the package directory runs a full agent turn against the stub server with TestModel — no engine, no API key: uv run --package pydantic-ai-algenta python pydantic-ai-algenta/local_demo.py.
  • Tests: ALLOW_MODEL_REQUESTS = False is enforced in conftest.py as a real guard against live-model calls — uv run --package pydantic-ai-algenta pytest pydantic-ai-algenta/tests -v.

Full reference: package README (the decision lifecycle, gate table, ExecutionReceipt fields).

Clone this wiki locally