-
Notifications
You must be signed in to change notification settings - Fork 474
feat(sdk): add flags support and x-agenta-flags OpenAPI extension for chat detection #3622
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?
Conversation
… chat detection
- Add flags parameter to legacy @ag.route/@ag.entrypoint decorators (serving.py)
- Emit x-agenta-flags on /run and /test OpenAPI operations
- Add flags parameter to new @ag.route decorator (routing.py) and propagate to auto_workflow()
- Add is_chat to WorkflowFlags model in SDK and API
- Update builtin chat service to set flags={"is_chat": True}
- Add design docs for chat-interface RFC
This enables custom workflows to explicitly declare is_chat: true, which the frontend can read from OpenAPI to determine chat UI mode.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
| return self | ||
|
|
||
| workflow = auto_workflow(foo) | ||
| workflow = auto_workflow(foo, flags=self.flags) |
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.
🟡 Flags parameter ignored when auto_workflow receives an existing Workflow object
When auto_workflow is called with an object that is already a workflow, the flags parameter is silently ignored.
Click to expand
Root Cause
In sdk/agenta/sdk/decorators/running.py:460-468, the auto_workflow function has early return paths that don't use the **kwargs (which includes flags):
def auto_workflow(obj: Any, **kwargs) -> Workflow:
if is_workflow(obj):
return obj # kwargs ignored!
if isinstance(obj, workflow):
return obj() # kwargs ignored!
if isinstance(getattr(obj, "workflow", None), workflow):
return obj # kwargs ignored!
return workflow(**kwargs)(obj) # Only this path uses kwargsHow It Gets Triggered
When using the new @ag.route decorator from routing.py with an already-decorated workflow:
@ag.route("/", flags={"is_chat": True})
@ag.workflow() # Creates a workflow first
def my_handler():
...The flags={"is_chat": True} from @ag.route will be silently ignored because my_handler is already a workflow when auto_workflow(foo, flags=self.flags) is called at routing.py:226.
Actual vs Expected
- Actual: Flags are ignored,
/inspectresponse won't includeis_chat: true - Expected: Flags from
@ag.routeshould be merged with or override the workflow's existing flags
Impact
Users combining @ag.route(flags=...) with @ag.workflow() decorators won't get their flags applied, leading to incorrect chat detection in the frontend.
Recommendation: Modify auto_workflow to merge flags when the object is already a workflow, or document that @ag.route(flags=...) should not be combined with @ag.workflow(). Alternatively, the route class could check if foo is already a workflow and update its flags directly before calling auto_workflow.
Was this helpful? React with 👍 or 👎 to provide feedback.
62b64bd to
a7d6257
Compare
Summary
This PR implements Phase 1 and Phase 1b of the Chat Interface RFC, enabling custom workflows to explicitly declare themselves as chat applications via a
flagsparameter.Changes
Legacy System (
serving.py):flags: Optional[Dict[str, Any]]parameter to@ag.route,@ag.entrypoint, andcreate_app()'sisolated_routex-agenta-flagson/runand/testOpenAPI operationsflags={"is_chat": True}New Workflow System (
routing.py):flags: Optional[dict]parameter to@ag.routeauto_workflow()so they flow to/inspectresponseModels:
is_chat: bool = FalsetoWorkflowFlagsin SDK (sdk/agenta/sdk/models/workflows.py)is_chat: bool = FalsetoWorkflowFlagsin API (api/oss/src/core/workflows/dtos.py)Design Docs:
docs/design/chat-interface-rfc/with research, plan, and statusUsage
OpenAPI Output
Testing
x-agenta-flags.is_chat: trueappears in/services/chat/openapi.jsonNext Steps (Phase 2)
Frontend changes to read
x-agenta-flags.is_chatfor chat detection (with heuristics fallback).