real integrations: implementation elicitation, INTEGRATION, fidelity + repair

Anchor the product premise at the top of AGENTS.md: semif-agent is an
end-user app that does the user's task for real against their actual
service, asking a few questions and learning when it doesn't know how.

Elicitation now asks implementation questions (service/account, how to
connect, credential source, expected result) and is on by default. The
REPL asks inline; the dashboard defers via a question queue the worker
waits on (/api/questions + panel). Answers ride every body attempt and
persist in the registry so restart doesn't re-ask.

SKILL.md requires real actions via stdlib transports with values from
ctx.config and a module-level INTEGRATION declaration
(service/transport/config_vars). TESTGEN.md scopes tests as hermetic
mechanics checks (loopback http.server in-test, never fixture addresses
in bodies) that never certify the live integration.

After the body lands a fidelity review (small LLM + static declaration
findings) regenerates a simulated body once, then accepts it traced and
badged unverified. A failed real run logs a SemIf repair choice
(retry/repair_skill/ask_user/no_repair), surfaced in REPL and dashboard,
bounded by codegen.repair.max_attempts and user-confirmed.

Dev unit suite: 191 passed. Jarvis integration run still pending.
This commit is contained in:
Denton Social committed 2026-09-26 01:42:00 -05:00
1 parent 06ccfb77c6
commit dde034f1b4
16 files changed
+2263 -255

No files matched your search

+93
View File
@@ -0,0 +1,93 @@
"""Pure-stdlib tests for the self-assessment LLM client.
The only network usage is a throwaway stdlib HTTP server standing in for an
OpenAI-compatible endpoint; the client itself is real, not mocked.
"""
import json
import socket
import threading
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
from semif_agent.llm import LLMClient
def _chat_server(content: str):
class Handler(BaseHTTPRequestHandler):
received: list = []
def do_POST(self):
length = int(self.headers.get("Content-Length") or 0)
type(self).received.append(
json.loads(self.rfile.read(length).decode("utf-8"))
)
body = json.dumps(
{"choices": [{"message": {"content": content}}]}
).encode("utf-8")
self.send_response(200)
self.send_header("Content-Type", "application/json")
self.send_header("Content-Length", str(len(body)))
self.end_headers()
self.wfile.write(body)
def log_message(self, format, *args):
pass
handler = type("Handler", (Handler,), {"received": []})
httpd = ThreadingHTTPServer(("127.0.0.1", 0), handler)
threading.Thread(target=httpd.serve_forever, daemon=True).start()
return httpd, f"http://127.0.0.1:{httpd.server_address[1]}/v1"
def _dead_url() -> str:
sock = socket.socket()
sock.bind(("127.0.0.1", 0))
port = sock.getsockname()[1]
sock.close()
return f"http://127.0.0.1:{port}/v1"
def test_review_skill_body_parses_fake_verdict():
httpd, base = _chat_server(
'{"performs_real_action": false, "reason": "returns a canned string"}'
)
try:
client = LLMClient(base_url=base, model="test", timeout=10)
review = client.review_skill_body(
"send the email",
"Send an email through the user's mail account.",
"def act(ctx, request, prediction):\n return 'sent'",
requirements={"Which service?": "SMTP"},
integration={"service": "mail", "transport": "smtp"},
)
assert review.performs_real_action is False
assert "canned" in review.reason
sent = httpd.RequestHandlerClass.received[0]["messages"]
joined = " ".join(message["content"] for message in sent)
assert "send the email" in joined
assert "SMTP" in joined
assert "smtp" in joined
finally:
httpd.shutdown()
httpd.server_close()
def test_review_skill_body_accepts_real_body():
httpd, base = _chat_server(
'{"performs_real_action": true, "reason": "calls urllib"}'
)
try:
client = LLMClient(base_url=base, model="test", timeout=10)
review = client.review_skill_body("check the service", "Check it.", "code")
assert review.performs_real_action is True
assert review.reason == "calls urllib"
finally:
httpd.shutdown()
httpd.server_close()
def test_review_skill_body_degrades_when_unreachable():
client = LLMClient(base_url=_dead_url(), model="test", timeout=2)
review = client.review_skill_body("x", "y", "z")
assert review.performs_real_action is True
assert "review failed" in review.reason