Spaces:
Runtime error
Runtime error
Implementation Plan - Fraud Assistant Workflow Pattern
Goal Description
Transition the fraud_model_explainability_assistant from a monolithic Agent loop to a structured "Workflow Pattern". This improves Determinism (explicit steps), Auditability (logging per step), Reliability (error handling per step), and enables Human-in-the-loop capabilities in the future.
The workflow will explicitly orchestrate:
- Intent Analysis: Understand what the user is asking.
- Routing: Decide which specialized sub-routine or tool to use.
- Execution: Run the tools (e.g.,
explain_fraud_score,check_fair_lending_flags). - Synthesis: Generate the final response based on tool outputs.
User Review Required
This change refactors the core
query_agentfunction inapp.pyto use a newFraudWorkflowclass instead of the directstrands.Agentcall. The external API endpoints remain the same.
Proposed Changes
Fraud Model Explainability Assistant
[NEW] workflow.py
FraudWorkflowState: A TypedDict/Pydantic model to hold the conversation state (messages, current context, tool outputs).FraudWorkflowClass:__init__: Initialize models and tools.run(input): Main entry point.analyze_intent(state): Classify user query (Classification/Routing).execute_tools(state): Run selected tools based on intent.generate_response(state): Final synthesis.- Uses
strandscomponents where applicable (e.g.,OpenAIModelfor the cognitive steps).
[MODIFY] app.py
- Import
FraudWorkflow. - Replace
create_enhanced_agentwithcreate_workflow(or update logic). - Update
query_agentto invokeworkflow.run().
[MODIFY] utils.py
- Ensure tools are compatible with direct python execution if needed (they already are decorated with
@toolbut can be called effectively as functions).
Verification Plan
Automated Tests
- Run
app.pylocally. - Use
curlor the built-in UI to send the example questions:- "Why was application APP-78432 flagged?" (Should trigger
get_application_summary+explain_fraud_score) - "Check fair lending compliance for APP-55555" (Should trigger
check_fair_lending_flags)
- "Why was application APP-78432 flagged?" (Should trigger
Manual Verification
- Review logs to confirm the step-by-step execution (Intent -> Tool -> Response).
- Verify the quality of the answers matches or exceeds the previous implementation.