You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[OPIK-5326] [SDK] feat: cast job input values to declared param types in runner (#5952)
* [OPIK-5326] [SDK] feat: cast job input values to declared param types in runner
Add input type casting to both the TypeScript and Python in-process runner
loops so agent functions receive correctly-typed arguments regardless of how
the server serialised the values in job.inputs.
TypeScript: export castInputValue() from InProcessRunnerLoop, apply it in
invokeAgent using each Param's declared type (boolean / number / string).
Python: add cast_input_value() to in_process_loop, apply it in _execute_job
for all keys that match a registered param (bool / int / float / str); keys
such as opik_args that are not in params pass through unchanged.
Both implementations follow the same pattern as typeHelpers.ts: primitives
are cast natively, complex types (dict/list) are JSON-serialised as strings,
and null/None passes through unchanged.
Unit tests added for both SDKs using parametrisation to cover each type
individually and a set of multi-param combination scenarios.
Implements OPIK-5326
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* [OPIK-5326] [SDK] refactor: reuse type_helpers deserialization in runner casting
Address baz-reviewer feedback on PR #5952:
TypeScript (comment #3009010633): castInputValue now delegates to
deserializeValue() from typeHelpers.ts for string→boolean and string→number
conversions. Adds a Number.isNaN guard so non-numeric strings (e.g. "abc")
throw TypeError instead of silently passing NaN to the agent function.
Python (comment #3009010639): extract_params now calls unwrap_optional()
from type_helpers.py before extracting the type name, so Optional[int]
annotations correctly store type="int" instead of the raw
"typing.Optional[int]" string. cast_input_value is rewritten to delegate to
backend_value_to_python_value() from type_helpers.py, unifying the
conversion logic across AgentConfig and the runner.
Python (comment #3009010648): renamed all test functions in
test_cast_input_value.py to follow the repo convention
test_WHAT__CASE_DESCRIPTION__EXPECTED_RESULT. Added tests for Optional[T]
unwrapping in extract_params and for the new backend type name aliases
("boolean", "integer", "string").
Skipping comment #3009010644 (bool "1"→True): strict "true"/"false" only
behaviour is intentional and mirrors the TypeScript SDK — the backend
serialises booleans as true/false, not "1"/"yes".
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* [OPIK-5326] [SDK] refactor: move type_helpers to shared path
type_helpers.py / typeHelpers.ts were under agent_config but are now
used by the runner as well. Move them to a neutral location:
Python: api_objects/agent_config/type_helpers.py
→ api_objects/type_helpers.py
TypeScript: agent-config/typeHelpers.ts
→ typeHelpers.ts (opik package root)
Update all import sites in both SDKs: agent_config internals
(config, blueprint, base, AgentConfig, Blueprint, index), the runner
(in_process_loop, registry), the client (Client.ts), and all
corresponding test files. No logic changes.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* [OPIK-5303] [SDK] refactor: use module-form import for type_helpers in in_process_loop
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* [OPIK-5326] [SDK] refactor: standardise input casting around backend type names
- Remove backend_type param from backend_value_to_python_value (was unused)
- Raise TypeError for truncating int casts ("3.9") and bool→int coercion
- registry.extract_params now emits backend type names (integer/boolean/string)
so Param.type is consistent with what the server expects
- cast_input_value delegates directly to backend_type_to_python_type; the
dual Python/backend name lookup (type_name_to_python_type) is removed
- Add _execute_job integration tests covering multi-typed params in both
Python and TypeScript
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* [NA] revert package-lock.json to main
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* test(runner): update extract_params assertions to backend type names
* fix(runner): treat '1'/'yes' as truthy bool; report cast errors as failed jobs
- Extend bool casting to accept "1" and "yes" as truthy values
- Move input casting inside _execute_job's try/except so TypeError
from invalid inputs is reported to the backend as a failed job
instead of propagating uncaught
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* test(runner): use fake timers in typed-params TS test
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
0 commit comments