Spaces:
Sleeping
Sleeping
remove reset
Browse files
app.py
CHANGED
|
@@ -77,10 +77,13 @@ class BasicAgent:
|
|
| 77 |
print("✅ BasicAgent initialized.")
|
| 78 |
|
| 79 |
async def answer_once(self, prompt: str) -> str:
|
| 80 |
-
"""
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
async def __call__(self, input_text: str):
|
| 86 |
# Use run() within async context
|
|
|
|
| 77 |
print("✅ BasicAgent initialized.")
|
| 78 |
|
| 79 |
async def answer_once(self, prompt: str) -> str:
|
| 80 |
+
"""Run the agent in a blank context so tokens never pile up."""
|
| 81 |
+
# Safety: trim monster inputs
|
| 82 |
+
# prompt = prompt[:32000] # ≈ 2 k tokens head-room
|
| 83 |
+
ctx = Context(self.agent) # no prior messages
|
| 84 |
+
resp = await self.agent.run(user_msg=prompt, ctx=ctx)
|
| 85 |
+
# run() sometimes returns dict, sometimes str
|
| 86 |
+
return resp if isinstance(resp, str) else resp.get("response", str(resp))
|
| 87 |
|
| 88 |
async def __call__(self, input_text: str):
|
| 89 |
# Use run() within async context
|