Files
Alfredv2/alfred/scripts/test_hermes_acp.py
T
2026-10-24 17:55:05 +02:00

98 lines
2.6 KiB
Python

import asyncio
import time
from acp import Client, connect_to_agent
from acp.schema import (
InitializeResponse,
NewSessionResponse,
PromptResponse,
RequestPermissionResponse,
)
class AlfredClient(Client):
async def session_update(self, session_id, update):
print(f"[ACP] {update}", flush=True)
async def request_permission(self, options, session_id, tool_call):
raise RuntimeError(
"Une autorisation est demandée pendant le test ACP"
)
async def main():
print("[ALFRED] Démarrage Hermes ACP...", flush=True)
start = time.perf_counter()
process = await asyncio.create_subprocess_exec(
"/root/.local/bin/hermes",
"acp",
stdin=asyncio.subprocess.PIPE,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.DEVNULL,
)
try:
client = AlfredClient()
async with connect_to_agent(
client,
process.stdin,
process.stdout,
) as agent:
init = await agent.initialize(
protocol_version=1,
client_capabilities={},
client_info={
"name": "alfred",
"version": "1.0",
},
)
print(f"[ACP] Initialisation : {init}", flush=True)
session = await agent.new_session(
cwd="/opt/alfred/app",
mcp_servers=[],
)
print(f"[ACP] Session : {session.session_id}", flush=True)
for question in (
"Combien font deux plus deux ? Réponds en français.",
"Quelle est la capitale de la France ? Réponds en français.",
):
start_question = time.perf_counter()
result = await agent.prompt(
session_id=session.session_id,
prompt=[
{
"type": "text",
"text": question,
}
],
)
elapsed = time.perf_counter() - start_question
print(f"\nQuestion : {question}")
print(f"Résultat : {result}")
print(f"Temps : {elapsed:.2f} secondes\n")
print(
f"[ALFRED] Temps total : "
f"{time.perf_counter() - start:.2f}s"
)
finally:
if process.returncode is None:
process.terminate()
await process.wait()
if __name__ == "__main__":
asyncio.run(main())