Pydantic AI
A decorator that puts a permission check in front of a Pydantic AI tool, carrying the agent identity through RunContext so the audit event knows who ran it.
Pydantic AI Integration
Type-safe agent identity for Pydantic AI agents. Uses dependency injection to provide identity, permission checking, and audit logging through RunContext.
Installation
pip install vorim pydantic-aibashVorimDeps Dependency
Pass VorimDeps as your agent's dependency type. It provides check(), emit(), grant(), and verify() methods on the context.
from vorim.pydantic_ai import VorimDeps
from pydantic_ai import Agent, RunContext
agent = Agent('openai:gpt-4o', deps_type=VorimDeps)
@agent.tool
async def fetch_data(ctx: RunContext[VorimDeps], query: str) -> str:
# Check permission before acting
check = ctx.deps.check('agent:read')
if not check.get('allowed'):
return 'Permission denied: agent:read not granted'
result = do_something(query)
# Log the action
ctx.deps.emit('data.fetch', outcome='success')
return result
# Run with Vorim identity
deps = VorimDeps(api_key='agid_sk_...', agent_id='agid_abc123')
result = await agent.run('Fetch the latest data', deps=deps)typescriptvorim_tool Decorator
Automatically checks permissions and logs audit events on every tool call. No manual check()/emit() needed.
from vorim.pydantic_ai import VorimDeps, vorim_tool
agent = Agent('openai:gpt-4o', deps_type=VorimDeps)
@agent.tool
@vorim_tool(scope='agent:read', action='data.fetch')
async def fetch_data(ctx: RunContext[VorimDeps], query: str) -> str:
# Permission checked automatically before this runs
# Audit event emitted automatically after this returns
return do_something(query)
# If permission is denied, tool returns 'Permission denied'
# and a denial audit event is loggedtypescriptQuick Start with create_vorim_agent
Register a new agent and create a Pydantic AI Agent in one call:
from vorim.pydantic_ai import create_vorim_agent
agent, deps = create_vorim_agent(
model='openai:gpt-4o',
api_key='agid_sk_...',
agent_name='research-agent',
scopes=['agent:read', 'agent:execute'],
system_prompt='You are a research agent.',
)
result = await agent.run('Find the latest papers', deps=deps)typescriptBook a demo for a walkthrough, or contact us for support. For enterprise needs, reach out at sales@vorim.ai.