BloomERP

Create a custom AI provider

See the built-in reference for the definition fields and available built-ins.

Register a project provider using an existing runtime

Reuse the built-in provider’s runtime, credential schema and integration under a project-owned ID.

python
from bloomerp.agents.providers.definition import AIProviderDefinition
from bloomerp.agents.providers.registry import AI_PROVIDER_REGISTRY

original = AI_PROVIDER_REGISTRY.openai
reviews = AIProviderDefinition(
    id="example_review_provider",
    name="Review provider",
    description="A provider entry for document review agents.",
    runtime=original.runtime,
    runtime_factory=original.runtime_factory,
    credentials_schema=original.credentials_schema,
    config_schema=original.config_schema,
    integration=original.integration,
)
AI_PROVIDER_REGISTRY.register(reviews.id, reviews)

Constrain provider settings for a short-answer agent

Pass the same settings schema to the definition and integration so both validate the response length cap.

python
from pydantic import Field

from bloomerp.agents.providers.builtins.pydantic_ai_common import PydanticAIProvider, PydanticAISettings
from bloomerp.agents.providers.builtins.pydantic_open_ai import create_openai_model
from bloomerp.agents.providers.definition import AIProviderDefinition
from bloomerp.agents.providers.registry import AI_PROVIDER_REGISTRY, pydantic_runtime


class ShortAnswerSettings(PydanticAISettings):
    '''Apply a smaller output limit for short-answer agents.'''

    max_tokens: int = Field(default=256, gt=0, le=512, strict=True)


short_answers = AIProviderDefinition(
    id="example_short_answers",
    name="Short-answer provider",
    runtime_factory=pydantic_runtime,
    config_schema=ShortAnswerSettings,
    integration=PydanticAIProvider(create_openai_model, ShortAnswerSettings),
)
AI_PROVIDER_REGISTRY.register(short_answers.id, short_answers)