Add agent discovery, CLI commands, module-level agent config, and tests#3
Conversation
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📝 WalkthroughWalkthroughAdds decorator-based agent discovery and directory-based loading: example agents gain Changes
Sequence Diagram(s)sequenceDiagram
participant User as CLI User
participant CLI as openrtc.cli.main()
participant Parser as ArgParser
participant Pool as AgentPool
participant FS as FileSystem
participant Module as Agent Module
User->>CLI: run (e.g. "list --agents-dir ./agents")
CLI->>Parser: parse args
Parser-->>CLI: args (command, agents_dir, defaults...)
CLI->>Pool: AgentPool(defaults...)
CLI->>Pool: pool.discover(agents_dir)
Pool->>FS: list *.py (skip __init__.py, _*)
FS-->>Pool: file list
loop per module
Pool->>Module: import module by path
Module-->>Pool: module object (or import error)
Pool->>Pool: _find_local_agent_subclass(module)
Pool->>Pool: _resolve_discovery_metadata(module, class attrs)
Pool->>Pool: pool.add(name, AgentClass, resolved providers/greeting)
end
Pool-->>CLI: list[AgentConfig]
CLI->>User: print/list or run agents (start/dev)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~30 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/openrtc/__init__.py`:
- Around line 3-4: The current absolute import of openrtc_python._version is
wrong and causes ModuleNotFoundError; update the module-level version import so
it first attempts a relative import of "._version" for __version__, and if that
fails fall back to reading the installed package version via
importlib.metadata.version("openrtc") (assign result to __version__); ensure the
symbol __version__ is defined either way so tests and imports work.
In `@tests/conftest.py`:
- Around line 14-17: The current check uses "if 'livekit.agents' not in
sys.modules" which only detects prior import and can shadow a real install;
change this to attempt importlib.import_module('livekit.agents') inside a
try/except ImportError and only create the types.ModuleType stubs
(livekit_module, agents_module) and inject them into sys.modules if the import
raises ImportError; keep the same names (livekit_module, agents_module) and the
existing sys.modules assignment logic but guarded by the importlib import
failure.
In `@tests/test_discovery.py`:
- Line 8: The import in src/openrtc/__init__.py incorrectly references
openrtc_python._version; update the top-level import to use the correct package
module by replacing the import of __version__ from openrtc_python._version to
openrtc._version so tests can import the package; specifically edit the import
statement in __init__.py that currently reads from openrtc_python._version and
change it to import __version__ from openrtc._version.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: ef368770-c988-4bf8-bfd4-ca0fb591ac3f
📒 Files selected for processing (10)
examples/agents/dental.pyexamples/agents/restaurant.pyexamples/main.pysrc/openrtc/__init__.pysrc/openrtc/cli.pysrc/openrtc/pool.pytests/conftest.pytests/test_cli.pytests/test_discovery.pytests/test_pool.py
Motivation
start/devcommands.Description
AgentPool.discoverwhich loads Python files from a directory, finds a localAgentsubclass, and registers it with optional module-level configuration read fromAGENT_NAME,AGENT_STT,AGENT_LLM,AGENT_TTS, andAGENT_GREETINGattributes._load_agent_module,_find_local_agent_subclass, and_read_module_strto safely import modules and validate configuration values.build_parserand amainthat supportslist,start, anddevcommands with a required--agents-dirargument, prints discovered agents forlist, and runs the pool forstart/devwhile injectingsys.argvto set LiveKit mode.AGENT_*metadata and switchedexamples/main.pyto usepool.discover(Path(__file__).with_name("agents")).__version__import to useopenrtc_python._versionand addedimportlib.util/Path/ModuleTypeusage inpool.py.tests/conftest.pyshim to mocklivekit.agentsfor test isolation.Testing
tests/test_discovery.pyto verify discovery behavior, module config parsing, skipping private modules, import error handling, and ignoring non-local Agent subclasses, and it passed.tests/test_cli.pyto verify CLIlist,start, anddevbehaviors and exit codes, and it passed.tests/test_pool.pyto exerciseadd, duplicate name checks, type validation, order preservation, andrunerror behavior, and it passed.Codex Task
Summary by CodeRabbit
New Features
Tests
Documentation