Skip to content

Make chat and embed interfaces provider-agnostic using pydantic_ai#200

Merged
gvanrossum merged 24 commits intomainfrom
agnostic
Feb 27, 2026
Merged

Make chat and embed interfaces provider-agnostic using pydantic_ai#200
gvanrossum merged 24 commits intomainfrom
agnostic

Conversation

@gvanrossum
Copy link
Collaborator

@gvanrossum gvanrossum commented Feb 17, 2026

Support multiple AI providers via pydantic_ai

  • New model_adapters.py: create_chat_model(),
    create_embedding_model(), and configure_models() accept
    "provider:model" specs (e.g. "anthropic:claude-sonnet-4-20250514"),
    delegating to pydantic_ai's 25+ provider registry.
  • New IEmbedder protocol (two async methods) replaces the
    monolithic AsyncEmbeddingModel class; CachingEmbeddingModel
    wraps any IEmbedder with cache logic.
  • Removed: AsyncEmbeddingModel, ModelWrapper,
    create_typechat_model(), hardcoded embedding_size,
    max_retries, and model_registry.py.
  • Azure auto-fallback preserved; new OPENAI_EMBEDDING_MODEL
    env var; create_test_embedding_model() for tests.

@bmerkle
Copy link
Contributor

bmerkle commented Feb 23, 2026

pyproject.toml or lockfile was not touched so the dependecy to pydantic_ai is missing.

print("Setting up conversation settings...")
try:
embedding_model = AsyncEmbeddingModel(model_name=embedding_name)
embedding_model = create_embedding_model(model_name=embedding_name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the pydantic.ai API uses a ctor call to instantiate models or agents and not a method so this looks kind of strange.
e.g.

model = os.getenv('PYDANTIC_AI_MODEL', 'openai:gpt-5.2')
print(f'Using model: {model}')
agent = Agent(model, output_type=MyModel)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the pydantic.ai API uses a ctor call to instantiate models or agents and not a method so this looks kind of strange.

I don't understand your comment. This is the (new) idiomatic way to create an embedding model. Unless there's already an embedding model available in the settings?

@gvanrossum
Copy link
Collaborator Author

pyproject.toml or lockfile was not touched so the dependecy to pydantic_ai is missing.

Fixed.

@gvanrossum gvanrossum marked this pull request as ready for review February 26, 2026 03:53
@bmerkle
Copy link
Contributor

bmerkle commented Feb 26, 2026

found another issue, not from this PR, but we should fix before release:

will fix this in the bugfix branch

src\typeagent\knowpro\interfaces_search.py
contains two all lists. IMO we should delete one :-) (line 147 or 20)

__all__ = [
    "KnowledgePropertyName",
    "PropertySearchTerm",
    "SearchSelectExpr",
    "SearchTerm",
    "SearchTermGroup",
    "SearchTermGroupTypes",
    "SemanticRefSearchResult",
    "WhenFilter",
]


@bmerkle
Copy link
Contributor

bmerkle commented Feb 27, 2026

LGTM, please merge to main

@gvanrossum gvanrossum merged commit 4e428e2 into main Feb 27, 2026
16 checks passed
@gvanrossum gvanrossum deleted the agnostic branch February 27, 2026 23:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants