Collapse vendor configs into pydantic models for IDE autocomplete#54
Merged
Conversation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ulate_by_name Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Global vendor classes now resolve to real types via the top-level TYPE_CHECKING block, so `from agora_agent import DeepgramSTT` gives IDE autocomplete (was Any). CN vendors get a dedicated `agora_agent.cn` module (natural names), which also resolves the MicrosoftSTT/MicrosoftTTS/MiniMaxTTS collisions. SpatiusAvatar (CN) is now cn-only; XaiGrok/GenericAvatar demoted to TYPE_CHECKING-only. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR has two related parts, both in service of IDE autocomplete for vendor configs.
Part 1 — Collapse vendor configs into pydantic models
Every STT/LLM/TTS/MLLM/avatar vendor config class (~63 across
agentkit/vendors/) useddef __init__(self, **kwargs: Any)and stashed a parallel*Optionspydantic model, which erased all constructor type information — so VSCode/Pylance showed no autocomplete, no parameter types, and no hover docs when constructing e.g.DeepgramSTT(...).This collapses each vendor class into its pydantic model: fields (with their
Field(..., description=...), constraints, and validators) live directly on the class, andto_config()readsself.<field>. The*Optionsclasses are deleted and the base classes becomeBaseModel + ABC. Result: full field autocomplete + hover docs + type-checking, with no new dependencies.Behavior preservation
to_config()output is byte-identical for every vendor (guarded by golden-master snapshots + the full existing suite).FengmingSTT(**unexpected)now raises pydanticValidationErrorinstead ofTypeError.SenseTimeAvataradditionally accepts snake_case (app_id/scene_list) viapopulate_by_name=True; the wire output still emitsappId/sceneList.Notable design decisions
Groq,CustomLLM,VertexAILLM, and the CNAliyun/Bytedance/DeepSeek/TencentLLMs) are standalone copies rather than inheriting/delegating — removes the old__init__kwargsmutation and gives each clean per-class hints (accepted duplication over coupling).sample_rate: the base exposesresolved_sample_rate(readsgetattr(self, "sample_rate", None)) to avoid a base member shadowing subclasssample_ratefields;agent.py's single consumer updated accordingly. Sarvam/Murf/CosyVoice keep their original accessor semantics via targeted overrides.HeyGenAvataris a standalone copy ofLiveAvatarAvatarwith its deprecation warning moved tomodel_post_init.Part 2 — Top-level type exports +
agora_agent.cnPart 1 made the classes typed, but the most natural import —
from agora_agent import DeepgramSTT— still resolved toAny(the top-level package uses a lazy__getattr__fallback). This part gives the global vendors real static types at the top level, and puts CN vendors in a dedicated module:from agora_agent import DeepgramSTT, OpenAI, MiniMaxTTS. Implemented by adding them to the top-levelTYPE_CHECKINGblock only (they're already inagentkit.__all__, so runtime +__all__are handled by the existing fallback/union — no_dynamic_imports/_ROOT_ALLchurn).agora_agent.cnmodule with natural names:from agora_agent.cn import AliyunLLM, MiniMaxTTS, TencentSTT. This also resolves the three name collisions cleanly —agora_agent.MiniMaxTTSis the global class,agora_agent.cn.MiniMaxTTSis the CN class.SpatiusAvatar(a CN vendor previously exported top-level) is now cn-only —from agora_agent import SpatiusAvatarstill runs (fallback →Any) but its typed path isfrom agora_agent.cn import SpatiusAvatar.XaiGrok/GenericAvatarwere demoted toTYPE_CHECKING-only (behavior-neutral). One documented example indocs/guides/avatars.mdupdated; the broader CN-docs/alias-convention migration is a deliberate follow-up.Test Plan
poetry run pytest -rP .— 235 passed, 1 skippedpoetry run mypy .— no new errors (only the 3 pre-existingcore/errors)to_config()output for the high-risk classesfrom agora_agent import DeepgramSTTandfrom agora_agent.cn import AliyunLLMresolve to realtype[...]with 0 warnings; global vs CNMiniMaxTTSdistinct🤖 Generated with Claude Code