Python quickstart

Build a Python AI Agent That Takes Real Actions

A Python quickstart: define your app's actions as OpenVerb verbs, run them through an executor, require confirmation for risky ones, and connect a model with tool calling.

Last reviewed

In short: pip install openverb, describe your app's actions as verbs, register a Python function for each, and let a model call them through tool calling. Risky actions wait for confirmation.

Most “Python AI agent” tutorials stop at an agent that can chat or search the web. This one builds an agent that can take actions inside your own application, safely, using the openverb Python package. It works with any Python app: Django, Flask, FastAPI, a desktop tool or a script.

1. Install

terminal
pip install openverb

The package ships the core verb library, so you can look around straight away:

explore.py
from openverb import load_core_library, create_executor

library = load_core_library()
print(library['namespace'])        # 'openverb.core'

executor = create_executor(library)
print(executor.get_verbs()[:3])    # the first few verb names

2. Describe your actions as verbs

A verb is an action described as data: a name, a description the model will read, typed parameters, and safety flags. Group your app's verbs into a library:

verbs.py
from openverb import load_library, create_executor

library = load_library({
    'namespace': 'my.tasks',
    'version': '1.0.0',
    'verbs': [
        {
            'name': 'task.create',
            'category': 'tasks',
            'description': 'Create a new task.',
            'params': {
                'title': {'type': 'string', 'description': 'What needs to be done.', 'required': True},
                'assignee': {'type': 'string', 'description': 'Who should do it.', 'required': False},
            },
        },
        {
            'name': 'task.list',
            'category': 'tasks',
            'description': 'List tasks, optionally by assignee.',
            'params': {
                'assignee': {'type': 'string', 'description': 'Only this person.', 'required': False},
            },
        },
        {
            'name': 'task.delete',
            'category': 'tasks',
            'description': 'Permanently delete a task.',
            'params': {'id': {'type': 'string', 'description': 'Task ID.', 'required': True}},
            'destructive': True,
            'requires_confirmation': True,
        },
    ],
})

# load_library also accepts a JSON string or a file path:
# library = load_library('my.tasks.json')

3. Register a handler for each verb

Handlers are plain Python functions that receive the action's params and return a result with a status. In a real app they call your existing models and services:

handlers.py
executor = create_executor(library)
tasks = []

def create_task(params):
    task = {'id': str(len(tasks) + 1), 'title': params['title'], 'assignee': params.get('assignee')}
    tasks.append(task)
    return {'verb': 'task.create', 'status': 'success', 'data': task}

def list_tasks(params):
    who = params.get('assignee')
    return {'verb': 'task.list', 'status': 'success',
            'data': [t for t in tasks if not who or t['assignee'] == who]}

def delete_task(params):
    tasks[:] = [t for t in tasks if t['id'] != params['id']]
    return {'verb': 'task.delete', 'status': 'success', 'data': {'id': params['id']}}

executor.register('task.create', create_task)
executor.register('task.list', list_tasks)
executor.register('task.delete', delete_task)

print(executor.execute({'verb': 'task.create', 'params': {'title': 'Send the Q3 report', 'assignee': 'Dana'}}))
# {'verb': 'task.create', 'status': 'success', 'data': {'id': '1', ...}}

executor.execute checks that the verb exists and its required params are present before your function runs, and returns an error result instead if they don't.

4. Hold risky actions for confirmation

Route every action through one function that checks the verb's flags first:

gate.py
def run_action(action, confirmed=False):
    verb = executor.get_verb(action['verb']) or {}
    if (verb.get('destructive') or verb.get('requires_confirmation')) and not confirmed:
        return {'verb': action['verb'], 'status': 'needs_confirmation',
                'message': f"Confirm: {verb['description']}"}
    return executor.execute(action)

5. Connect a model with tool calling

Turn each verb into a tool definition, send the conversation to the model, run any tool calls through run_action, and loop until it answers. With Claude (pip install anthropic):

agent.py
import json, re
import anthropic

def param_to_schema(p):
    base = {'description': p.get('description', '')}
    if p['type'] == 'enum':
        return {**base, 'type': 'string', 'enum': p['enum']}
    m = re.fullmatch(r'array<(.+)>', p['type'])
    if m:
        return {**base, 'type': 'array', 'items': {'type': m.group(1)}}
    return {**base, 'type': p['type']}

def verb_to_tool(verb):
    params = verb.get('params', {})
    return {
        'name': verb['name'],
        'description': verb['description'],
        'input_schema': {
            'type': 'object',
            'properties': {n: param_to_schema(p) for n, p in params.items()},
            'required': [n for n, p in params.items() if p.get('required')],
        },
    }

client = anthropic.Anthropic()   # reads ANTHROPIC_API_KEY
tools = [verb_to_tool(executor.get_verb(n)) for n in executor.get_verbs()]

def ask(messages):
    while True:
        response = client.beta.messages.create(
            model='claude-opus-5-5',
            max_tokens=16000,
            system='You are the assistant inside a task manager. Use the tools to act for the user.',
            tools=tools,
            messages=messages,
            betas=['server-side-fallback-2026-07-01'],
            fallbacks='default',
        )
        if response.stop_reason == 'refusal':
            return messages
        messages.append({'role': 'assistant', 'content': response.content})
        if response.stop_reason != 'tool_use':
            return messages
        results = []
        for block in response.content:
            if block.type == 'tool_use':
                result = run_action({'verb': block.name, 'params': block.input})
                results.append({'type': 'tool_result', 'tool_use_id': block.id,
                                'content': json.dumps(result)})
        messages.append({'role': 'user', 'content': results})

ask([{'role': 'user', 'content': 'Add a task for Dana to send the Q3 report, then list her tasks.'}])

The converter handles the shorthand types the core library uses (enum and array<string>). For OpenAI, the same verbs become tools with a function.parameters schema; the OpenAI and Anthropic guide has that version.

Python API at a glance

FunctionWhat it does
load_library(source)Load a library from a dict, a JSON string or a file path
load_core_library()Load the built-in openverb.core library
create_executor(library)Create an executor for a library
executor.register(name, fn)Attach a handler to a verb
executor.execute(action)Validate and run an action
executor.get_verbs() / get_verb(name)List verb names / read one definition
build_registry(library)Index verbs by name
validate_action(action, verb)Check an action against a definition

Next steps

  • Put the agent in your interface and test it the way users will: steps 7 and 8 of the main guide.
  • Add policies by role or plan and keep an audit trail: AI agent governance.
  • Use ready-made verb vocabularies such as OpenVerb GIS, which also documents a PyQGIS integration.
OpenVerb Sandbox

Paste a Verb Library JSON schema here to define what actions the AI can perform.

Ask the AI to perform a task. It will use the vocabulary defined in your library.

The AI proposes a structured action based on your library vocabulary.

Waiting for prompt...

OpenVerb Core intercepts the AI's action and validates it before execution.

Verb exists in library
Payload matches JSON Schema
Policy requirements passed
Inputs valid and sanitized

The validated action is routed to the application backend for execution.

Waiting...

OpenVerb Core generates an execution receipt for full auditability.

Waiting for execution...