Skip to content

Commit a9796b6

Browse files
fix(sdk): keep JWT runtime evaluation target-bound
1 parent 12297d3 commit a9796b6

2 files changed

Lines changed: 37 additions & 1 deletion

File tree

sdks/python/src/agent_control/evaluation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ async def _post_evaluation_request(
229229
) -> httpx.Response:
230230
"""Send an evaluation request, using runtime auth when the client supports it."""
231231
runtime_post = None
232-
if target_type is not None and target_id is not None:
232+
if (target_type is not None and target_id is not None) or client.runtime_auth_mode == "jwt":
233233
runtime_post = _runtime_post_evaluation(client)
234234
if runtime_post is not None:
235235
return await runtime_post(

sdks/python/tests/test_local_evaluation.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from typing import Any
1212
from unittest.mock import AsyncMock, MagicMock, patch
1313

14+
import httpx
1415
import pytest
1516
from agent_control.client import AgentControlClient
1617
from agent_control.evaluation import (
@@ -418,6 +419,41 @@ async def test_mock_client_with_runtime_method_uses_runtime_auth_path(
418419
client.post_runtime_evaluation.assert_awaited_once()
419420
client.http_client.post.assert_not_called()
420421

422+
@pytest.mark.asyncio
423+
async def test_jwt_runtime_client_without_target_raises(
424+
self,
425+
agent_name,
426+
llm_payload,
427+
) -> None:
428+
"""JWT runtime mode requires target context through local evaluation."""
429+
controls = [
430+
make_control_dict(1, "server_ctrl", execution="server"),
431+
]
432+
sent_requests: list[httpx.Request] = []
433+
434+
def handler(request: httpx.Request) -> httpx.Response:
435+
sent_requests.append(request)
436+
return httpx.Response(200, json={"is_safe": True, "confidence": 1.0})
437+
438+
transport = httpx.MockTransport(handler)
439+
440+
async with AgentControlClient(
441+
base_url="https://agent-control.test",
442+
api_key="test-key",
443+
runtime_auth_mode="jwt",
444+
transport=transport,
445+
) as client:
446+
with pytest.raises(RuntimeError, match="requires target_type and target_id"):
447+
await check_evaluation_with_local(
448+
client=client,
449+
agent_name=agent_name,
450+
step=llm_payload,
451+
stage="pre",
452+
controls=controls,
453+
)
454+
455+
assert sent_requests == []
456+
421457
@pytest.mark.asyncio
422458
async def test_server_only_template_backed_controls_still_call_server(
423459
self,

0 commit comments

Comments
 (0)