feat: add real-time observer system for voicemail/hallucination detec…#828
feat: add real-time observer system for voicemail/hallucination detec…#828Dev-Bhumika03 wants to merge 1 commit into
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughIntroduces a real-time observer subsystem for the breeze_buddy agent. A new ChangesReal-time observer subsystem
Sequence DiagramsequenceDiagram
participant Agent
participant build_observers
participant ObserverManager
participant RealtimeObserver
participant SideLLM
rect rgba(100, 149, 237, 0.5)
note over Agent,build_observers: Initialization (run())
Agent->>build_observers: configs, template, agent_context, handler_map
build_observers->>build_observers: merge_llm_config per observer
build_observers->>SideLLM: get_llm_service(pooled=True)
build_observers-->>Agent: List[RealtimeObserver]
Agent->>ObserverManager: __init__(observers, llm_context)
end
rect rgba(144, 238, 144, 0.5)
note over Agent,RealtimeObserver: Per-turn and function-call evaluation
Agent->>ObserverManager: on_turn_completed()
ObserverManager->>ObserverManager: _run_checks() [asyncio task]
ObserverManager->>RealtimeObserver: check(transcript) [gather]
RealtimeObserver->>SideLLM: run_inference(system_prompt, transcript)
SideLLM-->>RealtimeObserver: {detected: true, reason: "..."}
RealtimeObserver-->>ObserverManager: True
ObserverManager->>RealtimeObserver: execute_action()
RealtimeObserver->>Agent: handler_map["end_conversation"]()
end
rect rgba(255, 160, 122, 0.5)
note over Agent,ObserverManager: Shutdown
Agent->>ObserverManager: stop()
Agent->>Agent: _observer_manager = None
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
e32b969 to
b907b75
Compare
There was a problem hiding this comment.
Actionable comments posted: 5
🧹 Nitpick comments (2)
app/ai/voice/agents/breeze_buddy/observers/observer.py (1)
30-36: ⚡ Quick winAdd explicit return type hints on new method signatures.
__init__andexecute_actionare missing return annotations.Proposed fix
def __init__( self, config: ObserverConfig, llm_service: Any, agent_context: Any, handler_map: Dict[str, Any], - ): + ) -> None: @@ - async def execute_action(self): + async def execute_action(self) -> None:As per coding guidelines, "Add type hints on all function signatures."
Also applies to: 89-90
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@app/ai/voice/agents/breeze_buddy/observers/observer.py` around lines 30 - 36, Add explicit return type hints to the method signatures in the Observer class. The `__init__` method should include a `-> None` return type annotation. Additionally, the `execute_action` method (which the comment also references) needs an appropriate return type hint added based on what it returns. These return type annotations are required by the coding guidelines to ensure all function signatures have complete type hints for better code clarity and type safety.Source: Coding guidelines
app/ai/voice/agents/breeze_buddy/observers/manager.py (1)
45-52: ⚡ Quick winAdd return type annotations on new manager methods.
New methods are missing explicit return types (
-> None).Proposed fix
- def on_turn_completed(self): + def on_turn_completed(self) -> None: @@ - def on_function_call(self, function_name: str, arguments: Any): + def on_function_call(self, function_name: str, arguments: Any) -> None: @@ - async def _run_checks(self): + async def _run_checks(self) -> None: @@ - async def stop(self): + async def stop(self) -> None:As per coding guidelines, "Add type hints on all function signatures."
Also applies to: 65-67, 130-131
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@app/ai/voice/agents/breeze_buddy/observers/manager.py` around lines 45 - 52, Add explicit return type annotations to new methods that are missing them. The method on_turn_completed and other methods (at lines 65-67 and 130-131 in the manager.py file) do not include return type hints. Add `-> None` return type annotation to each method signature that lacks one to comply with the coding guideline requiring type hints on all function signatures. Ensure all methods in the manager.py file have explicit return types declared.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@app/ai/voice/agents/breeze_buddy/observers/factory.py`:
- Around line 25-34: In the merge_llm_config() function's no-override branch
(when override is None), add the missing region parameter to the
LLMConfiguration constructor call by including region=base.region alongside the
other parameters like provider, sdk, model, endpoint, api_key_name, temperature,
and max_tokens to ensure region information is preserved and consistent with the
override branch behavior.
In `@app/ai/voice/agents/breeze_buddy/observers/manager.py`:
- Around line 85-99: The current implementation using asyncio.gather() waits for
all observer checks to complete, then selects the first True result based on the
eligible list's config order, not the actual completion order. To implement true
first-writer-wins behavior where the observer that completes its check first
wins, replace the asyncio.gather() call with asyncio.as_completed() or
asyncio.wait() with return_when=asyncio.FIRST_COMPLETED. This will allow you to
process results as they complete rather than after all checks finish, ensuring
the observer that actually detects first (not the one earliest in the config)
gets to execute its action.
In `@app/ai/voice/agents/breeze_buddy/observers/observer.py`:
- Around line 72-75: The logger.info call in the observer.py file is logging raw
LLM-generated reason text from the model output, which can expose sensitive user
details and PII in application logs. Remove or replace the reason field logging
with a generic, non-sensitive message that does not include the actual
LLM-generated reason text. Ensure the log entry still conveys that the observer
was triggered but without exposing any sensitive details from the model output.
In `@app/ai/voice/agents/breeze_buddy/template/types.py`:
- Around line 1535-1563: Black code formatting has not been applied to several
files, causing CI build failures. Apply Black formatter with line-length=88
configuration to the following files at their specified line ranges:
app/ai/voice/agents/breeze_buddy/template/types.py (lines 1535-1563),
app/ai/voice/agents/breeze_buddy/observers/factory.py (lines 36-50),
app/ai/voice/agents/breeze_buddy/observers/manager.py (lines 52-59), and
app/ai/voice/agents/breeze_buddy/agent/__init__.py (lines 1127-1132). Run the
Black formatter on these files to reformat the code according to the
repository's coding guidelines, then commit the reformatted changes.
- Around line 1527-1563: The ObserverConfig.action field currently accepts any
FlowAction type, but RealtimeObserver.execute_action() only supports
end_conversation and function actions, causing invalid combinations to pass
validation and silently no-op at runtime. Constrain the action field in
ObserverConfig to only accept the action variants that are actually supported by
the runtime (end_conversation and function) by either creating a narrower type
definition or using a Union of only the supported action types, so that invalid
action types are rejected during validation rather than failing silently at
runtime.
---
Nitpick comments:
In `@app/ai/voice/agents/breeze_buddy/observers/manager.py`:
- Around line 45-52: Add explicit return type annotations to new methods that
are missing them. The method on_turn_completed and other methods (at lines 65-67
and 130-131 in the manager.py file) do not include return type hints. Add `->
None` return type annotation to each method signature that lacks one to comply
with the coding guideline requiring type hints on all function signatures.
Ensure all methods in the manager.py file have explicit return types declared.
In `@app/ai/voice/agents/breeze_buddy/observers/observer.py`:
- Around line 30-36: Add explicit return type hints to the method signatures in
the Observer class. The `__init__` method should include a `-> None` return type
annotation. Additionally, the `execute_action` method (which the comment also
references) needs an appropriate return type hint added based on what it
returns. These return type annotations are required by the coding guidelines to
ensure all function signatures have complete type hints for better code clarity
and type safety.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: d2b4ccbb-2dac-4320-9314-4a8378557e07
📒 Files selected for processing (6)
app/ai/voice/agents/breeze_buddy/agent/__init__.pyapp/ai/voice/agents/breeze_buddy/observers/__init__.pyapp/ai/voice/agents/breeze_buddy/observers/factory.pyapp/ai/voice/agents/breeze_buddy/observers/manager.pyapp/ai/voice/agents/breeze_buddy/observers/observer.pyapp/ai/voice/agents/breeze_buddy/template/types.py
b907b75 to
1b87a60
Compare
|
@coderabbitai full review |
✅ Action performedFull review finished. |
c468bb7 to
812ae66
Compare
PR #828 — real-time observer system (voicemail / hallucination detection)Verdict: request changes — 3 majors. Gates all green: 🟥 Major (inline comments posted)
🟨 Minor (not blocking)
✅ What's goodObservers are dispatched via |
812ae66 to
441321b
Compare
…tion Add ObserverConfig type to template configurations (reuses LLMConfiguration, FlowAction) Add observers package: RealtimeObserver, ObserverManager, factory Wire observer lifecycle in agent/init.py (on_user_turn_started, on_function_calls_started) Observers read from LLMContext, run in parallel via asyncio.gather, first-writer-wins Uses existing get_llm_service(pooled=True) and Pipecat run_inference() — no custom HTTP clients Template-configurable: add any detection by writing a system_prompt, zero code changes Tested with real voicemail calls — observer detects and sets outcome=VOICEMAIL
441321b to
f15f800
Compare
…tion
Summary by CodeRabbit