feat(serialization): add Component serialization convenience APIs#126
feat(serialization): add Component serialization convenience APIs#126pullely-samuel wants to merge 15 commits intooracle:mainfrom
Conversation
|
Thank you for your pull request and welcome to our community! To contribute, please sign the Oracle Contributor Agreement (OCA).
To sign the OCA, please create an Oracle account and sign the OCA in Oracle's Contributor Agreement Application. When signing the OCA, please provide your GitHub username. After signing the OCA and getting an OCA approval from Oracle, this PR will be automatically updated. If you are an Oracle employee, please make sure that you are a member of the main Oracle GitHub organization, and your membership in this organization is public. |
|
I signed the Oracle Contributor Agreement (OCA) and received DocuSign confirmation. It is now pending Oracle approver review. |
|
Thank you @pullely-samuel for the contribution! |
|
Thank you for signing the OCA. |
|
Update since the initial PR commit d244a2e: SummaryFollowing review, the main behavioral change is that What Changed
Validation
Relevant Examplesagent-spec/docs/pyagentspec/source/code_examples/howto_agents.py Lines 73 to 79 in db56cb5 |
cesarebernardis
left a comment
There was a problem hiding this comment.
Thank you for the contribution!
|
Internal regression failed: Build ID #378 |
Add convenience methods on Component for serialization and deserialization: - to_yaml(), to_json(), to_dict() - from_yaml(), from_json(), from_dict() Keep behavior consistent by delegating to AgentSpecSerializer and AgentSpecDeserializer, including disaggregated configuration support and plugin forwarding. Update documentation and examples to show direct component methods, and add serialization tests for roundtrips, type checks, disaggregated loading, plugin integration, and formatting behavior. Also align serializer overload typing with runtime behavior for to_json() and to_dict(). Signed-off-by: Samuel Pullely <236219770+pullely-samuel@users.noreply.github.com>
Mirror the serializer-style overload coverage for Component.to_yaml(), Component.to_json(), and Component.to_dict(). Move the wrapper-specific `plugins` argument to the end and make it keyword-only in the runtime signatures, while keeping `indent` positional-or-keyword for `to_json()` to match serializer behavior. This improves completeness and consistency of the convenience API while keeping the implementation thin and delegated to AgentSpecSerializer. Signed-off-by: Samuel Pullely <236219770+pullely-samuel@users.noreply.github.com>
Add serializer-style example pointers to Component.to_yaml() and Component.to_json(), and update the Component.to_dict() examples to mirror the serializer docs while using the convenience API. This keeps the convenience-method documentation consistent with the underlying serializer docs and makes the two surfaces easier to compare. Signed-off-by: Samuel Pullely <236219770+pullely-samuel@users.noreply.github.com>
Remove the import_only_referenced_components parameter from Component.from_yaml(), Component.from_json(), and Component.from_dict(), and always deserialize the main component in the inner AgentSpecDeserializer call. Referenced-component imports remain available through AgentSpecDeserializer, which is the appropriate advanced API for loading disaggregated configurations into a components registry. This keeps convenience APIs such as Agent.from_yaml() and Flow.from_dict() predictable by ensuring they always return the requested component type. Update the serialization tests accordingly. Signed-off-by: Samuel Pullely <236219770+pullely-samuel@users.noreply.github.com>
…ializer Mirror the deserializer-style overload coverage for Component.from_yaml(), Component.from_json(), and Component.from_dict() after removing the import_only_referenced_components convenience path. Keep the convenience API focused on main-component deserialization while preserving consistent overload coverage and keyword-only handling for the wrapper-specific plugins argument. This improves parity between Component and AgentSpecDeserializer without reintroducing the unstable dict-returning behavior on the classmethods. Signed-off-by: Samuel Pullely <236219770+pullely-samuel@users.noreply.github.com>
Align the Component.from_yaml(), Component.from_json(), and Component.from_dict() docstrings more closely with the corresponding AgentSpecDeserializer docstrings where that still fits the convenience API. Add example pointers to the YAML and JSON helpers, and update the from_dict() examples to use the convenience API for the normal path while keeping AgentSpecDeserializer for the advanced referenced-component import workflow. Keep the return-value documentation convenience-specific so it still reflects the typed ComponentT/cls contract. Signed-off-by: Samuel Pullely <236219770+pullely-samuel@users.noreply.github.com>
Add a simplest_agent fixture to the serialization test conftest and use it in the existing convenience-API serialization tests that previously repeated the same inline Agent construction. This reduces duplication in test_serialization.py while keeping the current test coverage and behavior unchanged. Signed-off-by: Samuel Pullely <236219770+pullely-samuel@users.noreply.github.com>
Rename the temporary loaded_references variable in the serialization tests to referenced_components for consistency with the disaggregated-loading terminology. Signed-off-by: Samuel Pullely <236219770+pullely-samuel@users.noreply.github.com>
Rename the custom plugin-only helper components used in the serialization tests to make their nested/container roles easier to understand when reading the plugin and disaggregation roundtrip cases. Signed-off-by: Samuel Pullely <236219770+pullely-samuel@users.noreply.github.com>
Add Agent.from_* convenience deserialization examples to the simple agent how-to, and update the disaggregated configuration guide to show the intended split workflow: AgentSpecDeserializer for importing referenced components and Agent.from_yaml() for loading the main agent. This keeps the docs aligned with the convenience API surface and the advanced disaggregated loading workflow. Signed-off-by: Samuel Pullely <236219770+pullely-samuel@users.noreply.github.com>
Move the Agent import back inside the Sphinx snippet boundaries in the disaggregated configuration example and mark the file to skip isort so future formatting does not pull shared imports above the snippet markers. This keeps the rendered documentation examples complete and easier to read on their own. Signed-off-by: Samuel Pullely <236219770+pullely-samuel@users.noreply.github.com>
Update the convenience serialization API changelog entry to reflect the final API split for disaggregated configurations: convenience deserialization uses `components_registry`, while referenced-component imports remain available through `AgentSpecDeserializer(..., import_only_referenced_components=True)`. Signed-off-by: Samuel Pullely <236219770+pullely-samuel@users.noreply.github.com>
e348c09 to
80777b3
Compare
|
Internal regression failed: Build ID #379 |
53c5fc5 to
6c3ecd6
Compare
|
Internal regression failed: Build ID #383 |
|
Internal regression succeeded 🍏: Build ID #384 |
feat(serialization): add Component serialization convenience APIs
Closes #112
Summary
This PR adds convenience serialization and deserialization APIs directly on
Componentsubclasses, so users can call methods likeagent.to_json()andAgent.from_yaml(...)without manually instantiating serializer/deserializer classes.What Changed
Component:to_yaml(...)to_json(...)to_dict(...)Component:from_yaml(...)from_json(...)from_dict(...)AgentSpecSerializerAgentSpecDeserializerTyping Alignment
AgentSpecSerializer.to_json(...)overloads includeindent.AgentSpecSerializer.to_dict(...)bool-overload return type includes tuple form when exporting disaggregated components.Documentation and Examples
agent.to_json().Tests
Extended serialization tests to cover convenience APIs and key edge cases, including:
Componentdeserialization returning concrete typesagentspec_versionforwarding behaviorValidation run:
pre-commit run --files <changed files>pytest pyagentspec/tests/serialization/test_serialization.py -q(50 passed)SKIP_LLM_TESTS=1 pytest -q pyagentspec/tests(935 passed, 511 skipped)Notes
pytest -qincludestests_fuzzand fails in this local environment because optionalpythonfuzzis not installed; CI test workflow runspyagentspec/tests.