feat: add wrapper layer with Agent, AgentSession, and token support#3
Merged
Merged
Conversation
Co-Authored-By: blank@buildwithfern.com <blank@buildwithfern.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
⚙️ Control Options:
|
8 tasks
…ion forward ref Co-Authored-By: blank@buildwithfern.com <blank@buildwithfern.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.
feat: add wrapper layer with Agent, AgentSession, and token support
Summary
Ports the custom wrapper layer from the TypeScript SDK to the Python SDK. Adds a
src/agoraio/wrapper/package with:Agent— Fluent builder for agent configuration. Supports shorthand strings (e.g."openai/gpt-4") for LLM/TTS/STT, and converts to Fern-generatedStartAgentsRequestPropertiesviato_properties().AgentSession/AsyncAgentSession— Session lifecycle management (start, stop, say, interrupt, update, get_history, get_info) with state tracking and an event emitter (on/off).avatar_types— Validation for HeyGen (24kHz) and Akool (16kHz) avatar/TTS sample rate constraints.token—generate_rtc_token()that delegates toagora_token_builderif installed, with a hand-rolled HMAC fallback.LlmConfig,SttConfig,TtsConfig, etc.) for verbose Fern-generated types.All wrapper exports are re-exported from the top-level
agoraiopackage..fernignoreupdated to protectsrc/agoraio/wrapper/.Updates since last revision
import-not-founderror for optionalagora_token_builderdependency (added# type: ignore[import-not-found]).name-definederror forAgentSessionreturn type inagent.pyby addingfrom __future__ import annotationsand aTYPE_CHECKING-guarded import.Review & Testing Checklist for Human
token.pycontains a custom_generate_dynamic_keyHMAC fallback used whenagora_token_builderis not installed. This is a hand-rolled reimplementation — verify it produces tokens Agora servers actually accept, or decide whether to drop the fallback and require theagora_token_builderdependency instead.dict, notTtsmodel:_parse_tts_shorthand()returns a plaindictwhile LLM/STT parsers return Pydantic models. Confirm this is compatible when passed toStartAgentsRequestProperties(tts=...)— may silently fail or produce incorrect serialization at runtime.to_properties()logic: Complex branching for MLLM mode vs standard mode, token generation, and LLM config merging. Trace through a few representative configs (standard LLM+TTS, MLLM-only, with avatar) to verify correctness.create_sessionrelies onhasattrchecks:client.app_id if hasattr(client, "app_id") else ""will silently default to an empty string if the client object doesn't have the expected attributes, potentially masking misconfiguration.Test Plan
pip install -e .python -c "from agoraio import Agent, AgentSession, generate_rtc_token"agent = Agent(instructions="...", llm="openai/gpt-4", tts="elevenlabs/voice-id")agent.to_properties(...)produces validStartAgentsRequestPropertiesgenerate_rtc_token(app_id="...", app_certificate="...", channel="test", uid=123)validate_tts_sample_rate({"vendor": "heygen"}, 24000)(should pass),validate_tts_sample_rate({"vendor": "heygen"}, 16000)(should raise)Notes