[OPIK-5326] [SDK] feat: cast job input values to declared param types in runner#5952
Conversation
TS SDK E2E Tests - Node 20275 tests 273 ✅ 16m 32s ⏱️ Results for commit 83fd452. ♻️ This comment has been updated with latest results. |
Python SDK E2E Tests Results (Python 3.13)361 tests 359 ✅ 13m 34s ⏱️ Results for commit 83fd452. ♻️ This comment has been updated with latest results. |
…ner 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>
Python SDK Unit Tests Results (Python 3.14)2 440 tests 2 440 ✅ 43s ⏱️ Results for commit f682c5e. ♻️ This comment has been updated with latest results. |
Python SDK Unit Tests Results (Python 3.13)2 440 tests 2 440 ✅ 58s ⏱️ Results for commit f682c5e. ♻️ This comment has been updated with latest results. |
Python SDK Unit Tests Results (Python 3.12)2 440 tests 2 440 ✅ 58s ⏱️ Results for commit f682c5e. ♻️ This comment has been updated with latest results. |
Python SDK Unit Tests Results (Python 3.11)2 440 tests 2 440 ✅ 59s ⏱️ Results for commit f682c5e. ♻️ This comment has been updated with latest results. |
Python SDK Unit Tests Results (Python 3.10)2 445 tests 2 445 ✅ 1m 2s ⏱️ Results for commit 08f02af. ♻️ This comment has been updated with latest results. |
… 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>
…ner 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>
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>
…n in_process_loop Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…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>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…iled 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>
08f02af to
e1a0e09
Compare
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…to-declared-param-types
…to-declared-param-types
Details
Add input type casting to both the TypeScript and Python in-process runner loops. Previously, job inputs were passed directly to agent functions with no conversion — causing incorrect behaviour when the server serialises primitive values as strings (e.g.
"42","true").Each SDK now maps inputs through a
castInputValue/cast_input_valuehelper that uses the declaredParam.typeto coerce values to their correct native type before calling the agent function. Complex types (dict/list/object/array) are JSON-serialised as strings, matching the existing pattern intypeHelpers.ts.Change checklist
Issues
AI-WATERMARK
AI-WATERMARK: yes
Testing
TypeScript SDK
castInputValue.test.ts)Python SDK
Both test suites use parametrisation to cover:
opik_argspassthrough (Python only — key not in registered params)Documentation
N/A — internal runner implementation detail, no public API surface changed.