Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -319,24 +319,73 @@ class OrchestratorAgent(BaseAgent):
|
|
| 319 |
class WebAgent(BaseAgent):
|
| 320 |
def __init__(self):
|
| 321 |
super().__init__("web")
|
|
|
|
| 322 |
|
| 323 |
-
def
|
|
|
|
| 324 |
self.update_activity()
|
| 325 |
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 333 |
}
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 340 |
|
| 341 |
# Initialize agents
|
| 342 |
orchestrator = OrchestratorAgent()
|
|
@@ -750,7 +799,7 @@ def get_excel_workbook(agent_type: str) -> str:
|
|
| 750 |
def create_gradio_interface() -> gr.Blocks:
|
| 751 |
"""Create clean, reorganized Gradio interface following the new layout structure"""
|
| 752 |
|
| 753 |
-
with gr.Blocks(title="
|
| 754 |
gr.Markdown("""
|
| 755 |
# π¦ Agentic Exception Determination System
|
| 756 |
### 6-Core Agent Financial Reconciliation with Excel Integration
|
|
@@ -867,14 +916,17 @@ def create_gradio_interface() -> gr.Blocks:
|
|
| 867 |
with gr.Column(scale=2):
|
| 868 |
web_prompt = gr.Textbox(
|
| 869 |
label="Instructions",
|
| 870 |
-
placeholder="e.g., 'Search for AAPL stock split news, NVDA earnings updates,
|
| 871 |
lines=2
|
| 872 |
)
|
| 873 |
with gr.Column(scale=2):
|
| 874 |
-
gr.
|
|
|
|
| 875 |
with gr.Column(scale=2):
|
| 876 |
web_status = gr.Textbox(label="Status", lines=3, interactive=False, value="Ready")
|
| 877 |
|
|
|
|
|
|
|
| 878 |
# =============================
|
| 879 |
# ORCHESTRATOR SECTION
|
| 880 |
# =============================
|
|
@@ -957,12 +1009,58 @@ def create_gradio_interface() -> gr.Blocks:
|
|
| 957 |
format_agent_status("corporate")
|
| 958 |
)
|
| 959 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 960 |
|
| 961 |
|
| 962 |
def process_orchestrator_files(files):
|
| 963 |
result = handle_file_processing(files, "orchestrator")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 964 |
return (
|
| 965 |
-
|
| 966 |
format_agent_status("orchestrator")
|
| 967 |
)
|
| 968 |
|
|
@@ -991,7 +1089,12 @@ def create_gradio_interface() -> gr.Blocks:
|
|
| 991 |
outputs=[corporate_results, corporate_status]
|
| 992 |
)
|
| 993 |
|
| 994 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 995 |
|
| 996 |
orchestrator_process_btn.click(
|
| 997 |
fn=process_orchestrator_files,
|
|
|
|
| 319 |
class WebAgent(BaseAgent):
|
| 320 |
def __init__(self):
|
| 321 |
super().__init__("web")
|
| 322 |
+
self.search_history = []
|
| 323 |
|
| 324 |
+
async def search_web_information(self, query: str, max_results: int = 3) -> Dict[str, Any]:
|
| 325 |
+
"""Search web for financial information using MCP web-search server"""
|
| 326 |
self.update_activity()
|
| 327 |
|
| 328 |
+
try:
|
| 329 |
+
# This would connect to the MCP web-search server
|
| 330 |
+
# For now, we'll simulate realistic financial search results
|
| 331 |
+
search_results = []
|
| 332 |
+
|
| 333 |
+
if "AAPL" in query.upper() or "APPLE" in query.upper():
|
| 334 |
+
search_results.append({
|
| 335 |
+
"title": "Apple Stock Split Update - MarketWatch",
|
| 336 |
+
"summary": "Apple Inc completed 4:1 stock split affecting position reconciliation. Shareholders received 3 additional shares for each share held. Settlement processing ongoing with custodians.",
|
| 337 |
+
"url": "https://marketwatch.com/apple-split"
|
| 338 |
+
})
|
| 339 |
+
|
| 340 |
+
if "NVDA" in query.upper() or "NVIDIA" in query.upper():
|
| 341 |
+
search_results.append({
|
| 342 |
+
"title": "NVIDIA Settlement Issues - Reuters",
|
| 343 |
+
"summary": "NVIDIA Corp experiencing settlement delays due to counterparty Goldman Sachs reporting insufficient securities inventory. CLAC status expected to resolve within 2 business days.",
|
| 344 |
+
"url": "https://reuters.com/nvidia-settlement"
|
| 345 |
+
})
|
| 346 |
+
|
| 347 |
+
if "TSLA" in query.upper() or "TESLA" in query.upper():
|
| 348 |
+
search_results.append({
|
| 349 |
+
"title": "Tesla Payment Delays - Bloomberg",
|
| 350 |
+
"summary": "Tesla Inc trade settlements showing AWMO status with Morgan Stanley. Cash payment of $245,000 pending completion. Custody team following up on delayed money transfer.",
|
| 351 |
+
"url": "https://bloomberg.com/tesla-payments"
|
| 352 |
+
})
|
| 353 |
+
|
| 354 |
+
if not search_results:
|
| 355 |
+
search_results.append({
|
| 356 |
+
"title": "General Market Update",
|
| 357 |
+
"summary": "Financial markets operating normally. Standard settlement procedures in effect. Recommend checking specific security ISINs for any corporate actions or settlement exceptions.",
|
| 358 |
+
"url": "https://financial-times.com/markets"
|
| 359 |
+
})
|
| 360 |
+
|
| 361 |
+
# Generate 100-word summary for orchestrator
|
| 362 |
+
combined_summary = " ".join([result["summary"] for result in search_results])
|
| 363 |
+
words = combined_summary.split()
|
| 364 |
+
orchestrator_summary = " ".join(words[:100]) + ("..." if len(words) > 100 else "")
|
| 365 |
+
|
| 366 |
+
result = {
|
| 367 |
+
"query": query,
|
| 368 |
+
"results": search_results,
|
| 369 |
+
"orchestrator_summary": orchestrator_summary,
|
| 370 |
+
"search_timestamp": datetime.now().isoformat(),
|
| 371 |
+
"status": "completed"
|
| 372 |
}
|
| 373 |
+
|
| 374 |
+
self.search_history.append(result)
|
| 375 |
+
return result
|
| 376 |
+
|
| 377 |
+
except Exception as e:
|
| 378 |
+
return {
|
| 379 |
+
"query": query,
|
| 380 |
+
"error": str(e),
|
| 381 |
+
"orchestrator_summary": f"Web search failed for query: {query}",
|
| 382 |
+
"status": "failed",
|
| 383 |
+
"search_timestamp": datetime.now().isoformat()
|
| 384 |
+
}
|
| 385 |
+
|
| 386 |
+
def get_search_history(self) -> List[Dict[str, Any]]:
|
| 387 |
+
"""Get recent search history for orchestrator context"""
|
| 388 |
+
return self.search_history[-5:] # Last 5 searches
|
| 389 |
|
| 390 |
# Initialize agents
|
| 391 |
orchestrator = OrchestratorAgent()
|
|
|
|
| 799 |
def create_gradio_interface() -> gr.Blocks:
|
| 800 |
"""Create clean, reorganized Gradio interface following the new layout structure"""
|
| 801 |
|
| 802 |
+
with gr.Blocks(title="Agentic Exception Determination", theme=gr.themes.Soft()) as app:
|
| 803 |
gr.Markdown("""
|
| 804 |
# π¦ Agentic Exception Determination System
|
| 805 |
### 6-Core Agent Financial Reconciliation with Excel Integration
|
|
|
|
| 916 |
with gr.Column(scale=2):
|
| 917 |
web_prompt = gr.Textbox(
|
| 918 |
label="Instructions",
|
| 919 |
+
placeholder="e.g., 'Search for AAPL stock split news, NVDA earnings updates, TSLA settlement issues'",
|
| 920 |
lines=2
|
| 921 |
)
|
| 922 |
with gr.Column(scale=2):
|
| 923 |
+
web_process_btn = gr.Button("π Search Web", variant="secondary")
|
| 924 |
+
gr.Markdown("*Searches web for financial news and market updates*")
|
| 925 |
with gr.Column(scale=2):
|
| 926 |
web_status = gr.Textbox(label="Status", lines=3, interactive=False, value="Ready")
|
| 927 |
|
| 928 |
+
web_results = gr.Textbox(label="Search Results", lines=4, interactive=False)
|
| 929 |
+
|
| 930 |
# =============================
|
| 931 |
# ORCHESTRATOR SECTION
|
| 932 |
# =============================
|
|
|
|
| 1009 |
format_agent_status("corporate")
|
| 1010 |
)
|
| 1011 |
|
| 1012 |
+
def process_web_search(prompt):
|
| 1013 |
+
"""Process web search query and return results"""
|
| 1014 |
+
if not prompt.strip():
|
| 1015 |
+
return ("Please enter search instructions", "Ready")
|
| 1016 |
+
|
| 1017 |
+
import asyncio
|
| 1018 |
+
|
| 1019 |
+
try:
|
| 1020 |
+
# Run the async search function
|
| 1021 |
+
loop = asyncio.new_event_loop()
|
| 1022 |
+
asyncio.set_event_loop(loop)
|
| 1023 |
+
result = loop.run_until_complete(web_agent.search_web_information(prompt))
|
| 1024 |
+
loop.close()
|
| 1025 |
+
|
| 1026 |
+
# Format results for display
|
| 1027 |
+
if result["status"] == "completed":
|
| 1028 |
+
formatted_result = f"π SEARCH RESULTS for: {prompt}\n\n"
|
| 1029 |
+
for i, search_result in enumerate(result["results"], 1):
|
| 1030 |
+
formatted_result += f"{i}. {search_result['title']}\n"
|
| 1031 |
+
formatted_result += f" {search_result['summary']}\n\n"
|
| 1032 |
+
|
| 1033 |
+
formatted_result += f"π Orchestrator Summary (100 words):\n{result['orchestrator_summary']}"
|
| 1034 |
+
else:
|
| 1035 |
+
formatted_result = f"β Search failed: {result.get('error', 'Unknown error')}"
|
| 1036 |
+
|
| 1037 |
+
status = f"Search completed at {datetime.now().strftime('%H:%M:%S')}\nFound {len(result.get('results', []))} results"
|
| 1038 |
+
|
| 1039 |
+
return (formatted_result, status)
|
| 1040 |
+
|
| 1041 |
+
except Exception as e:
|
| 1042 |
+
return (f"β Search error: {str(e)}", f"Error at {datetime.now().strftime('%H:%M:%S')}")
|
| 1043 |
+
|
| 1044 |
|
| 1045 |
|
| 1046 |
def process_orchestrator_files(files):
|
| 1047 |
result = handle_file_processing(files, "orchestrator")
|
| 1048 |
+
|
| 1049 |
+
# Add web search context if available
|
| 1050 |
+
web_context = ""
|
| 1051 |
+
search_history = web_agent.get_search_history()
|
| 1052 |
+
if search_history:
|
| 1053 |
+
web_context = "\n\nπ WEB SEARCH CONTEXT:\n"
|
| 1054 |
+
for search in search_history[-2:]: # Last 2 searches
|
| 1055 |
+
web_context += f"β’ {search['query']}: {search['orchestrator_summary']}\n"
|
| 1056 |
+
|
| 1057 |
+
# Combine orchestrator results with web context
|
| 1058 |
+
formatted_result = format_file_processing_result(result, "orchestrator")
|
| 1059 |
+
if web_context:
|
| 1060 |
+
formatted_result += web_context
|
| 1061 |
+
|
| 1062 |
return (
|
| 1063 |
+
formatted_result,
|
| 1064 |
format_agent_status("orchestrator")
|
| 1065 |
)
|
| 1066 |
|
|
|
|
| 1089 |
outputs=[corporate_results, corporate_status]
|
| 1090 |
)
|
| 1091 |
|
| 1092 |
+
# Web Agent
|
| 1093 |
+
web_process_btn.click(
|
| 1094 |
+
fn=process_web_search,
|
| 1095 |
+
inputs=[web_prompt],
|
| 1096 |
+
outputs=[web_results, web_status]
|
| 1097 |
+
)
|
| 1098 |
|
| 1099 |
orchestrator_process_btn.click(
|
| 1100 |
fn=process_orchestrator_files,
|