Introduce Devii agents subsystem with supervisor, policy, and evals
- Add agents package: controller, runner, store, tools, actions, evals, policy - Wire agents into Devii service, session, registry, CLI, and dispatcher - Extend database schema and config for agent persistence - Add news and telegram bridge updates plus landing UI and docs - Cover agents, news, and telegram flows with unit tests
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
# retoor <retoor@molodetz.nl>
|
||||
|
||||
from devplacepy.services.telegram.bridge import TelegramConnection
|
||||
from tests.conftest import run_async
|
||||
|
||||
|
||||
class _Service:
|
||||
def __init__(self):
|
||||
self.sent = []
|
||||
self.edits = []
|
||||
|
||||
async def send(self, chat_id, text, **kwargs):
|
||||
self.sent.append(text)
|
||||
return 100 + len(self.sent)
|
||||
|
||||
async def edit(self, chat_id, message_id, text, **kwargs):
|
||||
self.edits.append(text)
|
||||
return True
|
||||
|
||||
async def chat_action(self, chat_id, action="typing"):
|
||||
return None
|
||||
|
||||
|
||||
class _Session:
|
||||
def resolve_query(self, query_id, payload):
|
||||
pass
|
||||
|
||||
def resolve_interaction(self, interaction_id, payload):
|
||||
pass
|
||||
|
||||
|
||||
def _flow(payloads):
|
||||
async def run():
|
||||
import asyncio
|
||||
|
||||
service = _Service()
|
||||
conn = TelegramConnection(service, _Session(), 7, 42)
|
||||
try:
|
||||
for payload in payloads:
|
||||
await conn.send_json(payload)
|
||||
finally:
|
||||
conn.done.set()
|
||||
conn._stop_typing()
|
||||
await asyncio.gather(conn._typing_task, return_exceptions=True)
|
||||
return service
|
||||
|
||||
return run_async(run())
|
||||
|
||||
|
||||
def test_trace_without_agent_unchanged():
|
||||
service = _flow([{"type": "trace", "event": "call", "name": "fetch_url"}])
|
||||
assert service.edits == ["<i>Working... (fetch_url)</i>"]
|
||||
assert service.sent == []
|
||||
|
||||
|
||||
def test_trace_with_agent_labels_progress():
|
||||
service = _flow(
|
||||
[
|
||||
{
|
||||
"type": "trace",
|
||||
"event": "call",
|
||||
"name": "fetch_url",
|
||||
"agent": "sg",
|
||||
"uid": "uid-1",
|
||||
}
|
||||
]
|
||||
)
|
||||
assert service.edits == ["<i>Working... ([sg] fetch_url)</i>"]
|
||||
assert service.sent == []
|
||||
|
||||
|
||||
def test_agent_frame_while_open_edits_placeholder():
|
||||
service = _flow(
|
||||
[
|
||||
{
|
||||
"type": "agent",
|
||||
"kind": "needs_user",
|
||||
"uid": "uid-1",
|
||||
"label": "sg",
|
||||
"payload": "Budget?",
|
||||
}
|
||||
]
|
||||
)
|
||||
assert service.edits == ["<i>[sg] needs_user</i>"]
|
||||
assert service.sent == []
|
||||
|
||||
|
||||
def test_agent_frame_after_finalize_sends_new_message():
|
||||
service = _flow(
|
||||
[
|
||||
{"type": "reply", "text": "On it, working in the background."},
|
||||
{
|
||||
"type": "agent",
|
||||
"kind": "done",
|
||||
"uid": "uid-1",
|
||||
"label": "sg",
|
||||
"payload": "The comparison is ready.",
|
||||
},
|
||||
]
|
||||
)
|
||||
assert len(service.edits) == 1
|
||||
assert len(service.sent) == 1
|
||||
assert "Subagent" in service.sent[0]
|
||||
assert "sg" in service.sent[0]
|
||||
assert "finished" in service.sent[0]
|
||||
Reference in New Issue
Block a user