(feat): added common functions/tools for all templates#595
(feat): added common functions/tools for all templates#595narsimhaReddyJuspay wants to merge 1 commit intojuspay:releasefrom
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughThis change introduces a common tools registry system for the Breeze Buddy voice agent template. New modules define tool registration, management, and IST-based date/time utilities. The flow manager now reads common tool categories from configuration and injects them into global functions at build time. Changes
Sequence DiagramsequenceDiagram
participant FM as FlowManager
participant Cfg as Configuration
participant TB as TemplateBuilder
participant GFR as GlobalFunctionRegistry
participant CTR as CommonToolRegistry
FM->>Cfg: Read common_tools categories
FM->>TB: Call build_global_functions(flow, categories)
TB->>GFR: Call build(flow, handler_map, categories)
GFR->>GFR: Parse categories to ToolCategory enums
GFR->>CTR: Fetch tools by categories
CTR-->>GFR: Return FlowsFunctionSchema objects
GFR->>GFR: Combine template functions + common tools
GFR-->>TB: Return merged function schemas
TB-->>FM: Return complete global functions
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 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 |
There was a problem hiding this comment.
🧹 Nitpick comments (4)
app/ai/voice/agents/breeze_buddy/template/common_tools/registry.py (1)
88-89: Make registry state explicit withClassVarto silence RUF012.Ruff flags mutable class attributes here. Annotating as
ClassVarmakes the intent clear and avoids lint noise.♻️ Suggested change
-from typing import Any, Callable, Dict, List, Optional +from typing import Any, Callable, ClassVar, Dict, List, Optional ... - _tools: Dict[str, CommonTool] = {} - _by_category: Dict[ToolCategory, List[str]] = {cat: [] for cat in ToolCategory} + _tools: ClassVar[Dict[str, CommonTool]] = {} + _by_category: ClassVar[Dict[ToolCategory, List[str]]] = {cat: [] for cat in ToolCategory}🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@app/ai/voice/agents/breeze_buddy/template/common_tools/registry.py` around lines 88 - 89, The mutable class attributes _tools and _by_category in registry.py should be annotated as ClassVar to make the registry state explicit and silence RUF012; update the declarations for _tools (type Dict[str, CommonTool]) and _by_category (type Dict[ToolCategory, List[str]]) to use typing.ClassVar and ensure ClassVar is imported, leaving the initialization logic (the empty dict and the {cat: [] for cat in ToolCategory}) unchanged so the CommonTool and ToolCategory usages remain the same.app/ai/voice/agents/breeze_buddy/template/common_tools/basic_tools.py (1)
83-115: Silence unused-arg lint in handlers.The handlers don’t use
argsorflow_manager. Prefix with_to avoid ARG001 warnings while keeping the required signature.♻️ Suggested change
async def _get_current_datetime_handler( - args: Dict[str, Any], flow_manager: FlowManager + _args: Dict[str, Any], _flow_manager: FlowManager ) -> tuple: ... async def _get_current_date_handler( - args: Dict[str, Any], flow_manager: FlowManager + _args: Dict[str, Any], _flow_manager: FlowManager ) -> tuple: ... async def _get_current_time_handler( - args: Dict[str, Any], flow_manager: FlowManager + _args: Dict[str, Any], _flow_manager: FlowManager ) -> tuple:🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@app/ai/voice/agents/breeze_buddy/template/common_tools/basic_tools.py` around lines 83 - 115, The handlers _get_current_datetime_handler, _get_current_date_handler, and _get_current_time_handler currently accept args and flow_manager but don't use them; rename their parameters to _args and _flow_manager (e.g. def _get_current_datetime_handler(_args: Dict[str, Any], _flow_manager: FlowManager) -> tuple) so the required signature is preserved but ARG001 lint warnings are silenced; update each handler's parameter names consistently in the three function definitions.app/ai/voice/agents/breeze_buddy/template/global_function.py (1)
265-285: Avoid duplicate function names when merging common tools.If a template defines a function with the same name as a common tool, the merged list may include duplicates. It’s safer to dedupe (or warn) to avoid ambiguous LLM tool resolution.
♻️ Suggested change
result: List[FlowsFunctionSchema] = [] # Build template-defined global functions global_functions_config = flow.get("global_functions", []) if global_functions_config: logger.info(f"Building {len(global_functions_config)} global functions") for func_config in global_functions_config: schema = cls._build_one(func_config, handler_map) if schema: result.append(schema) + existing_names = {schema.name for schema in result} + # Append common tools based on requested categories if common_tool_categories: categories = cls._parse_categories(common_tool_categories) if categories: common_tools = CommonToolRegistry.get_by_categories(categories) if common_tools: logger.info( f"Appending {len(common_tools)} common tools " f"for categories: {[c.value for c in categories]}" ) - result.extend(common_tools) + for tool in common_tools: + if tool.name in existing_names: + logger.warning( + f"Skipping common tool '{tool.name}' due to name collision" + ) + continue + result.append(tool) + existing_names.add(tool.name)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@app/ai/voice/agents/breeze_buddy/template/global_function.py` around lines 265 - 285, When merging template-defined globals and common tools (variables: global_functions_config, result, cls._build_one and CommonToolRegistry.get_by_categories called with common_tool_categories/categories), avoid duplicate function names by collecting existing function names from result before appending common_tools and filtering the common_tools list to exclude any whose name matches an existing one; optionally log a warning that a common tool was skipped due to a name conflict to make resolution explicit. Ensure the dedupe uses the function identifier/name property used elsewhere in schemas so tool resolution remains unambiguous.app/ai/voice/agents/breeze_buddy/template/types.py (1)
250-253: Consider validatingcommon_toolsagainst the tool category enum.Right now it’s
List[str], so typos only surface later via warnings and silently skip tools. Using an enum type (or a validator) will fail fast and normalize values.♻️ Suggested change
-from typing import Any, Dict, List, Optional +from typing import Any, Dict, List, Optional +from app.ai.voice.agents.breeze_buddy.template.common_tools import ToolCategory ... - common_tools: Optional[List[str]] = Field( + common_tools: Optional[List[ToolCategory]] = Field( None, description="Common tool categories to include. Currently supported: ['BASIC'] for date/time tools.", )🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@app/ai/voice/agents/breeze_buddy/template/types.py` around lines 250 - 253, Change common_tools from Optional[List[str]] to an enum-backed field and add validation: define a ToolCategory Enum (e.g., with BASIC) and update common_tools: Optional[List[ToolCategory]] = Field(...), then add a pydantic validator (e.g., validate_common_tools) on the model to normalize inputs (accept strings, upper-case/map to enum) and raise a clear ValueError for unknown values so typos fail fast; reference the Field named common_tools, the new ToolCategory Enum, and the validator function validate_common_tools when implementing.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@app/ai/voice/agents/breeze_buddy/template/common_tools/basic_tools.py`:
- Around line 83-115: The handlers _get_current_datetime_handler,
_get_current_date_handler, and _get_current_time_handler currently accept args
and flow_manager but don't use them; rename their parameters to _args and
_flow_manager (e.g. def _get_current_datetime_handler(_args: Dict[str, Any],
_flow_manager: FlowManager) -> tuple) so the required signature is preserved but
ARG001 lint warnings are silenced; update each handler's parameter names
consistently in the three function definitions.
In `@app/ai/voice/agents/breeze_buddy/template/common_tools/registry.py`:
- Around line 88-89: The mutable class attributes _tools and _by_category in
registry.py should be annotated as ClassVar to make the registry state explicit
and silence RUF012; update the declarations for _tools (type Dict[str,
CommonTool]) and _by_category (type Dict[ToolCategory, List[str]]) to use
typing.ClassVar and ensure ClassVar is imported, leaving the initialization
logic (the empty dict and the {cat: [] for cat in ToolCategory}) unchanged so
the CommonTool and ToolCategory usages remain the same.
In `@app/ai/voice/agents/breeze_buddy/template/global_function.py`:
- Around line 265-285: When merging template-defined globals and common tools
(variables: global_functions_config, result, cls._build_one and
CommonToolRegistry.get_by_categories called with
common_tool_categories/categories), avoid duplicate function names by collecting
existing function names from result before appending common_tools and filtering
the common_tools list to exclude any whose name matches an existing one;
optionally log a warning that a common tool was skipped due to a name conflict
to make resolution explicit. Ensure the dedupe uses the function identifier/name
property used elsewhere in schemas so tool resolution remains unambiguous.
In `@app/ai/voice/agents/breeze_buddy/template/types.py`:
- Around line 250-253: Change common_tools from Optional[List[str]] to an
enum-backed field and add validation: define a ToolCategory Enum (e.g., with
BASIC) and update common_tools: Optional[List[ToolCategory]] = Field(...), then
add a pydantic validator (e.g., validate_common_tools) on the model to normalize
inputs (accept strings, upper-case/map to enum) and raise a clear ValueError for
unknown values so typos fail fast; reference the Field named common_tools, the
new ToolCategory Enum, and the validator function validate_common_tools when
implementing.
ℹ️ Review info
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
app/ai/voice/agents/breeze_buddy/agent/flow.pyapp/ai/voice/agents/breeze_buddy/template/__init__.pyapp/ai/voice/agents/breeze_buddy/template/builder.pyapp/ai/voice/agents/breeze_buddy/template/common_tools/__init__.pyapp/ai/voice/agents/breeze_buddy/template/common_tools/basic_tools.pyapp/ai/voice/agents/breeze_buddy/template/common_tools/registry.pyapp/ai/voice/agents/breeze_buddy/template/global_function.pyapp/ai/voice/agents/breeze_buddy/template/types.py
f571627 to
26b565c
Compare
26b565c to
ccf5e5a
Compare
Summary by CodeRabbit