Spaces:
Sleeping
Sleeping
Update agent_service.py
Browse files- agent_service.py +9 -2
agent_service.py
CHANGED
|
@@ -52,6 +52,7 @@ class AgentService:
|
|
| 52 |
conversation_history: List[Dict],
|
| 53 |
mode: str = "sales", # "sales" or "feedback"
|
| 54 |
user_id: Optional[str] = None,
|
|
|
|
| 55 |
max_iterations: int = 3
|
| 56 |
) -> Dict[str, Any]:
|
| 57 |
"""
|
|
@@ -62,6 +63,7 @@ class AgentService:
|
|
| 62 |
conversation_history: Previous messages [{"role": "user", "content": ...}, ...]
|
| 63 |
mode: "sales" or "feedback"
|
| 64 |
user_id: User ID (for feedback mode to check purchase history)
|
|
|
|
| 65 |
max_iterations: Maximum tool call iterations to prevent infinite loops
|
| 66 |
|
| 67 |
Returns:
|
|
@@ -74,6 +76,9 @@ class AgentService:
|
|
| 74 |
print(f"\n馃 Agent Mode: {mode}")
|
| 75 |
print(f"馃懁 User Message: {user_message}")
|
| 76 |
|
|
|
|
|
|
|
|
|
|
| 77 |
# Select system prompt
|
| 78 |
system_prompt = self._get_system_prompt(mode)
|
| 79 |
|
|
@@ -103,7 +108,8 @@ class AgentService:
|
|
| 103 |
print(f"馃敡 Tool Called: {tool_call['tool_name']}")
|
| 104 |
tool_result = await self.tools_service.execute_tool(
|
| 105 |
tool_call['tool_name'],
|
| 106 |
-
tool_call['arguments']
|
|
|
|
| 107 |
)
|
| 108 |
|
| 109 |
# Record tool call
|
|
@@ -327,7 +333,8 @@ Example:
|
|
| 327 |
# Format results
|
| 328 |
formatted = []
|
| 329 |
for i, result in enumerate(results, 1):
|
| 330 |
-
|
|
|
|
| 331 |
texts = payload.get("texts", [])
|
| 332 |
text = texts[0] if texts else ""
|
| 333 |
event_id = payload.get("id_use", "")
|
|
|
|
| 52 |
conversation_history: List[Dict],
|
| 53 |
mode: str = "sales", # "sales" or "feedback"
|
| 54 |
user_id: Optional[str] = None,
|
| 55 |
+
access_token: Optional[str] = None, # NEW: For authenticated API calls
|
| 56 |
max_iterations: int = 3
|
| 57 |
) -> Dict[str, Any]:
|
| 58 |
"""
|
|
|
|
| 63 |
conversation_history: Previous messages [{"role": "user", "content": ...}, ...]
|
| 64 |
mode: "sales" or "feedback"
|
| 65 |
user_id: User ID (for feedback mode to check purchase history)
|
| 66 |
+
access_token: JWT token for authenticated API calls
|
| 67 |
max_iterations: Maximum tool call iterations to prevent infinite loops
|
| 68 |
|
| 69 |
Returns:
|
|
|
|
| 76 |
print(f"\n馃 Agent Mode: {mode}")
|
| 77 |
print(f"馃懁 User Message: {user_message}")
|
| 78 |
|
| 79 |
+
# Store access_token for tool calls
|
| 80 |
+
self.current_access_token = access_token
|
| 81 |
+
|
| 82 |
# Select system prompt
|
| 83 |
system_prompt = self._get_system_prompt(mode)
|
| 84 |
|
|
|
|
| 108 |
print(f"馃敡 Tool Called: {tool_call['tool_name']}")
|
| 109 |
tool_result = await self.tools_service.execute_tool(
|
| 110 |
tool_call['tool_name'],
|
| 111 |
+
tool_call['arguments'],
|
| 112 |
+
access_token=self.current_access_token # Pass access_token
|
| 113 |
)
|
| 114 |
|
| 115 |
# Record tool call
|
|
|
|
| 333 |
# Format results
|
| 334 |
formatted = []
|
| 335 |
for i, result in enumerate(results, 1):
|
| 336 |
+
# Result is a dict with keys: id, score, payload
|
| 337 |
+
payload = result.get("payload", {})
|
| 338 |
texts = payload.get("texts", [])
|
| 339 |
text = texts[0] if texts else ""
|
| 340 |
event_id = payload.get("id_use", "")
|