-
Notifications
You must be signed in to change notification settings - Fork 436
feat(sdk): Evaluator v2 outbound worker runtime — managed + self-hosted pods, fork+exec sandbox, review hardening #758
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SiddarthAA
wants to merge
23
commits into
main
Choose a base branch
from
evaluator
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
4620e56
docs(sdk): clarify evaluator v2 boundary
SiddarthAA 6642a0d
feat(sdk): add evaluator v2 worker runtime
chhhee10 20e9c1e
fix(evaluator): resume only unfinished replayed runs
chhhee10 30f2fc2
feat(sdk): run hosted evaluator definitions
chhhee10 17bf0a6
fix(evaluator): harden managed source sandbox and contain poison defi…
chhhee10 ca3a7c8
feat(evaluator): normal short polling instead of long-poll in the worker
chhhee10 6a3592b
fix(evaluator): sandbox managed source in a killable process (hermes …
chhhee10 e955eef
fix(evaluator): fail closed when the fork sandbox is unavailable (her…
chhhee10 dadd90f
fix(evaluator): fork+exec the sandbox + clamp the timeout (hermes SEC…
chhhee10 6a7aea8
fix(evaluator): bound the sandbox result on both sides (hermes SEC-001)
chhhee10 ff95a42
fix(evaluator): bound aggregate sandbox memory (hermes SEC-001)
chhhee10 0868e00
Harden evaluator v2 sandbox; fix condition selection and error mirror
chhhee10 c1e63ca
Count sandbox-slot wait against the execution timeout (hermes SEC-001)
chhhee10 05b6266
fix(evaluator): report why source was rejected; scrub the sandbox chi…
SiddarthAA b24e8c3
test(evaluator): give the condition compute bomb a margin that surviv…
SiddarthAA e5a29d7
fp-cloud-cli: mirror the new evaluations:run permission
chhhee10 e435035
sdk(evaluator): fail closed when kernel resource limits are unavailable
chhhee10 47cd2c8
sdk(evaluator): bound the condition phase by the lease; make sync-eva…
chhhee10 b3dd423
sdk(evaluator): let a managed comprehension read session on Python 3.…
chhhee10 f6770f2
chore(security): time-box the nltk advisory that has no fix
chhhee10 6e0fdec
sdk(evaluator): fix five worker-runtime defects found in review
SiddarthAA 3450052
sdk(evaluator): register insufficient_permissions in the error contract
SiddarthAA ecb3e08
sdk(evaluator): harden the run loop against lease loss, replay, and t…
SiddarthAA File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| """Customer evaluator with deterministic and optional async judge checks.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import asyncio | ||
| import ipaddress | ||
| import json | ||
| import os | ||
| from urllib.parse import urlsplit | ||
| from urllib.request import HTTPRedirectHandler, Request, build_opener | ||
|
|
||
| from failproofai_sdk.evaluator import ( | ||
| ConditionResult, | ||
| EvalResult, | ||
| Evaluator, | ||
| Metric, | ||
| Score, | ||
| ) | ||
|
|
||
| app = Evaluator(name="customer-production", version="2026.08.1") | ||
|
|
||
|
|
||
| class _RejectRedirects(HTTPRedirectHandler): | ||
| def redirect_request(self, request, file_pointer, code, message, headers, new_url): | ||
| return None | ||
|
|
||
|
|
||
| @app.eval( | ||
| "tool_efficiency", | ||
| version="1.0.0", | ||
| labels=["tools", "deterministic"], | ||
| when=lambda session: ConditionResult( | ||
| session.count("tool_use") > 0, "no_tool_calls" | ||
| ), | ||
| ) | ||
| def tool_efficiency(session): | ||
| calls = session.events_of_type("tool_use") | ||
| distinct = { | ||
| event.payload.get("tool_name") | ||
| for event in calls | ||
| if event.payload.get("tool_name") | ||
| } | ||
| value = len(distinct) / len(calls) | ||
| return EvalResult( | ||
| score=Score(value, passed=value >= 0.7), | ||
| metrics={ | ||
| "tool_call_count": Metric(len(calls), unit="events"), | ||
| "distinct_tool_count": Metric(len(distinct), unit="tools"), | ||
| }, | ||
| reasoning=f"{len(distinct)} distinct tools across {len(calls)} calls", | ||
| ) | ||
|
|
||
|
|
||
| def _judge_configured(session): | ||
| configured = bool(os.environ.get("EXAMPLE_JUDGE_URL")) | ||
| return ConditionResult(configured, "judge_not_configured") | ||
|
|
||
|
|
||
| def _last_content(session, event_type): | ||
| events = session.events_of_type(event_type) | ||
| if not events: | ||
| return None | ||
| payload = events[-1].payload | ||
| fields = { | ||
| "human_input": ("response",), | ||
| "model_response": ("content",), | ||
| "agent_end": ("summary",), | ||
| }.get(event_type, ("content", "summary", "response")) | ||
| return next((payload.get(field) for field in fields if payload.get(field)), None) | ||
|
|
||
|
|
||
| def _call_judge(question, answer): | ||
| url = os.environ["EXAMPLE_JUDGE_URL"] | ||
| parsed = urlsplit(url) | ||
| if parsed.scheme not in {"http", "https"} or not parsed.netloc: | ||
| raise ValueError("EXAMPLE_JUDGE_URL must be an absolute http(s) URL") | ||
| hostname = parsed.hostname | ||
| loopback = hostname == "localhost" | ||
| if hostname is not None and not loopback: | ||
| try: | ||
| loopback = ipaddress.ip_address(hostname).is_loopback | ||
| except ValueError: | ||
| loopback = False | ||
| if parsed.scheme != "https" and not loopback: | ||
| raise ValueError("EXAMPLE_JUDGE_URL must use https unless it targets loopback") | ||
| token = os.environ.get("EXAMPLE_JUDGE_TOKEN") | ||
| body = json.dumps({"question": question, "answer": answer}).encode("utf-8") | ||
| headers = {"Content-Type": "application/json", "Accept": "application/json"} | ||
| if token: | ||
| headers["Authorization"] = f"Bearer {token}" | ||
| request = Request(url, data=body, headers=headers, method="POST") | ||
| with build_opener(_RejectRedirects()).open(request, timeout=25) as response: # nosec B310 | ||
| result = json.loads(response.read(64 * 1024)) | ||
| return float(result["score"]), str( | ||
| result.get("reasoning") or "Judge returned no reasoning" | ||
| ) | ||
|
|
||
|
|
||
| @app.eval( | ||
| "answer_relevance", | ||
| version="judge-api-v1", | ||
| labels=["llm_judge", "relevance"], | ||
| when=_judge_configured, | ||
| timeout_seconds=30, | ||
| ) | ||
| async def answer_relevance(session): | ||
| question = _last_content(session, "human_input") | ||
| answer = _last_content(session, "model_response") | ||
| if question is None or answer is None: | ||
| raise ValueError("answer relevance requires human input and model output") | ||
| value, reasoning = await asyncio.to_thread(_call_judge, question, answer) | ||
| value = min(max(value, 0.0), 1.0) | ||
| return EvalResult( | ||
| score=Score(value, passed=value >= 0.7), | ||
| reasoning=reasoning, | ||
| labels=("llm_judge", "relevance"), | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| app.run_from_env() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.