-
-
Notifications
You must be signed in to change notification settings - Fork 4
Strengthen deterministic agent workflow routing #381
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
base: main
Are you sure you want to change the base?
Changes from all commits
6028b9a
3c89c02
20725b7
23ad1cf
68f00d3
2ee1eff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
|
|
||
| from __future__ import annotations | ||
|
|
||
| import logging | ||
| import re | ||
| from datetime import date, datetime, timedelta, timezone | ||
| from typing import Literal, Protocol, cast | ||
|
|
@@ -65,6 +66,7 @@ | |
| "december": 12, | ||
| } | ||
| LiteralPlanner = Literal["deterministic_regex", "live_model"] | ||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class AgentIntentNormalizer(Protocol): | ||
|
|
@@ -120,13 +122,21 @@ def plan(self, message: str, context: AgentIdentityContext) -> AgentResponse: | |
| if resolved_member_agreement is not None: | ||
| return resolved_member_agreement | ||
|
|
||
| planner: LiteralPlanner = "deterministic_regex" | ||
| planning_text = text | ||
| action = self._parse_action(text) | ||
| if action is not None: | ||
| return self._response_for_deterministic_action( | ||
|
Comment on lines
+126
to
+127
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.
In deployments where Useful? React with 👍 / 👎. |
||
| action=action, | ||
| context=context, | ||
| planning_text=planning_text, | ||
| planner=planner, | ||
| ) | ||
|
|
||
| planned_response = self._plan_with_model(text, context) | ||
| if planned_response is not None: | ||
| return planned_response | ||
|
|
||
| planner: LiteralPlanner = "deterministic_regex" | ||
| planning_text = text | ||
| action = self._parse_action(text) | ||
| if action is None and not re.search( | ||
| r"\bcreate\s+(?:a\s+)?task\b", text, re.IGNORECASE | ||
| ): | ||
|
|
@@ -151,6 +161,23 @@ def plan(self, message: str, context: AgentIdentityContext) -> AgentResponse: | |
| "Try asking me to manage a task, GitHub issue, CRM contact, or member account." | ||
| ), | ||
| ) | ||
| return self._response_for_deterministic_action( | ||
| action=action, | ||
| context=context, | ||
| planning_text=planning_text, | ||
| planner=planner, | ||
| ) | ||
|
|
||
| def _response_for_deterministic_action( | ||
| self, | ||
| *, | ||
| action: AgentToolAction, | ||
| context: AgentIdentityContext, | ||
| planning_text: str, | ||
| planner: LiteralPlanner, | ||
| ) -> AgentResponse: | ||
| """Plan a known workflow before asking a model to infer an intent.""" | ||
|
|
||
| if action.tool_name == "task_read.search_tasks" and not action.arguments.get( | ||
| "project" | ||
| ): | ||
|
|
@@ -184,9 +211,15 @@ def _plan_with_model( | |
| runtime_config=self.registry.runtime_config, | ||
| model_tier=model_tier, | ||
| ) | ||
| except Exception: | ||
| except Exception as exc: | ||
| # Provider errors fall through to deterministic parsing. Do not expose | ||
| # provider internals in a Discord response. | ||
| logger.warning( | ||
| "Structured agent planner failed; using deterministic fallback " | ||
| "model_tier=%s error_type=%s", | ||
| model_tier, | ||
| type(exc).__name__, | ||
| ) | ||
| return None | ||
| if result is None: | ||
| return None | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a configured planner receives an explicit multi-step request where the first step matches the regex parser, e.g.
Create a task to update docs and invite Sarah to Outline, this early return bypasses_plan_with_modelafter parsing only oneAgentToolAction. The deterministic parser can only return a single action, so the later requested workflow is silently dropped instead of being planned as the multi-action confirmation path covered by the structured planner.Useful? React with 👍 / 👎.