-
Notifications
You must be signed in to change notification settings - Fork 57
(feat): add actions for langfuse evaluators #593
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
narsimhaReddyJuspay
wants to merge
1
commit into
juspay:release
Choose a base branch
from
narsimhaReddyJuspay:add-actions-for-langfuse-evaluators
base: release
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| """ | ||
| Tracing utility helpers for Breeze Buddy. | ||
| """ | ||
|
|
||
| from typing import Any, Dict, List | ||
|
|
||
|
|
||
| def extract_possible_outcomes(flow: Dict[str, Any]) -> List[str]: | ||
| """ | ||
| Extract all possible outcome values from a template flow definition. | ||
|
|
||
| Walks through all nodes → functions → hooks to find every | ||
| ``update_outcome_in_database`` hook with a static ``outcome`` field and | ||
| collects the unique values. | ||
|
|
||
| Args: | ||
| flow: The raw template flow dict (``template.flow``). | ||
|
|
||
| Returns: | ||
| Deduplicated list of outcome strings defined in the template. | ||
| """ | ||
| outcomes: list[str] = [] | ||
| seen: set[str] = set() | ||
|
|
||
| for node in flow.get("nodes", []): | ||
| for func in node.get("functions", []): | ||
| for hook in func.get("hooks", []): | ||
| if hook.get("name") != "update_outcome_in_database": | ||
| continue | ||
| expected_fields = hook.get("expected_fields", {}) | ||
| outcome_field = expected_fields.get("outcome", {}) | ||
| if outcome_field.get("source") == "static" and outcome_field.get( | ||
| "value" | ||
| ): | ||
| value = outcome_field["value"] | ||
| if value not in seen: | ||
| seen.add(value) | ||
| outcomes.append(value) | ||
|
|
||
| return outcomes | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import json | ||
| from typing import Any | ||
|
|
||
| from app.core.logger import logger | ||
| from app.services.live_config.store import get_config | ||
|
|
@@ -280,6 +281,107 @@ async def LANGFUSE_EVALUATORS() -> dict[str, int]: | |
| return evaluators | ||
|
|
||
|
|
||
| async def EVALUATOR_ACTIONS() -> dict[str, Any]: | ||
| """ | ||
| Returns EVALUATOR_ACTIONS from Redis as a dict mapping evaluator names to action configs. | ||
|
|
||
| Format: JSON string stored in Redis | ||
| { | ||
| "<VOICEMAIL_EVALUATOR_NAME>": { | ||
| "action_type": "outcome_update", | ||
| "action_config": { | ||
| "outcome": "VOICEMAIL", | ||
| "allowed_outcome_changes": {"BUSY": ["VOICEMAIL"]}, | ||
| "disallowed_outcome_changes": {"*": ["BUSY"]} | ||
| }, | ||
| "action_steps": { | ||
| "update_in_db": true, | ||
| "send_reporting_webhook": true, | ||
| "cancel_retries": true | ||
| } | ||
| }, | ||
| "<OUTCOME_CORRECTOR_NAME>": { | ||
| "action_type": "outcome_update", | ||
| "action_config": { | ||
| "outcome_key": "$.correct_outcome" | ||
| }, | ||
| "action_steps": { | ||
| "update_in_db": true, | ||
| "cancel_retries": true | ||
| } | ||
| } | ||
| } | ||
|
|
||
| action_config options: | ||
| - outcome: Direct outcome value (e.g., "VOICEMAIL") - use for simple cases | ||
| - outcome_key: JSON path to extract from JSON at end of comment (e.g., "$.correct_outcome") | ||
| - allowed_outcome_changes: (optional) Dict of {current_outcome: [allowed_new_outcomes]} | ||
| Use "*" as key to allow a target from any current outcome. Deny (disallowed) takes precedence. | ||
| - disallowed_outcome_changes: (optional) Dict of {current_outcome: [disallowed_new_outcomes]} | ||
| Use "*" as key to disallow for all current outcomes (e.g., {"*": ["BUSY"]}) | ||
|
|
||
| action_steps options: | ||
| - update_in_db: (default: true) Update the lead's outcome in the database | ||
| - send_reporting_webhook: (default: true) Send reporting webhook for outcome correction | ||
| - cancel_retries: (default: true) Cancel any pending retry leads | ||
|
|
||
| Trigger logic: Action triggers when score < threshold (from LANGFUSE_EVALUATORS config) | ||
|
narsimhaReddyJuspay marked this conversation as resolved.
|
||
| """ | ||
| config_value = await get_config("EVALUATOR_ACTIONS", "", str) | ||
| if not config_value: | ||
| return {} | ||
|
|
||
| try: | ||
| parsed = json.loads(config_value) | ||
| if not isinstance(parsed, dict): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. decode here |
||
| logger.error( | ||
| f"EVALUATOR_ACTIONS config must be a JSON object, got {type(parsed).__name__}" | ||
| ) | ||
| return {} | ||
|
|
||
| # Validate and decode each evaluator config entry | ||
| valid_actions: dict[str, Any] = {} | ||
| for evaluator_name, config in parsed.items(): | ||
| if not isinstance(config, dict): | ||
| logger.warning( | ||
| f"EVALUATOR_ACTIONS: skipping '{evaluator_name}' — config must be an object, got {type(config).__name__}" | ||
| ) | ||
| continue | ||
|
|
||
| action_type = config.get("action_type") | ||
| if not action_type or not isinstance(action_type, str): | ||
| logger.warning( | ||
| f"EVALUATOR_ACTIONS: skipping '{evaluator_name}' — missing or invalid 'action_type'" | ||
| ) | ||
| continue | ||
|
|
||
| action_config = config.get("action_config") | ||
| if action_config is not None and not isinstance(action_config, dict): | ||
| logger.warning( | ||
| f"EVALUATOR_ACTIONS: skipping '{evaluator_name}' — 'action_config' must be an object" | ||
| ) | ||
| continue | ||
|
|
||
| action_steps = config.get("action_steps") | ||
| if action_steps is not None and not isinstance(action_steps, dict): | ||
| logger.warning( | ||
| f"EVALUATOR_ACTIONS: skipping '{evaluator_name}' — 'action_steps' must be an object" | ||
| ) | ||
| continue | ||
|
|
||
| valid_actions[evaluator_name] = config | ||
|
|
||
| if len(valid_actions) < len(parsed): | ||
| logger.info( | ||
| f"EVALUATOR_ACTIONS: {len(valid_actions)}/{len(parsed)} configs valid" | ||
| ) | ||
|
|
||
| return valid_actions | ||
| except json.JSONDecodeError as e: | ||
| logger.error(f"Failed to parse EVALUATOR_ACTIONS config: {e}") | ||
| return {} | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
|
|
||
| # --- Noise Cancellation Configuration --- | ||
| async def BB_NOISE_CANCELLATION_ENABLED() -> bool: | ||
| """Returns BB_NOISE_CANCELLATION_ENABLED from Redis""" | ||
|
|
||
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| from app.services.langfuse.tasks.actions.actions import ActionExecutor, ActionResult | ||
|
|
||
| __all__ = ["ActionExecutor", "ActionResult"] |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.