<https://github.com/All-Hands-AI/agent-sdk/pull/33...
# proj-sdk
s
https://github.com/All-Hands-AI/agent-sdk/pull/331 This was painful - But all the Secondary Types have been removed and all the tests finally pass (e.g.:
SecurityAnalyzer
is now
SecurityAnalyzerBase
) @chilly-france-44439 / @wide-doctor-37830 - Any chance of final ๐Ÿ‘€ I am not fully happy with the result - I have the growing suspicion that if you want to your traditional extendable polymorphism then the creators of Pydantic hate you and want nothing but sadness for your future. You either need to: โ€ข Accept that certain things won't work (Like json schemas) ๐Ÿคฎ โ€ข Have strict layering ( Making class A that includes a Field B that includes a class A impossible)๐Ÿคฎ โ€ข Build 2 full sets of models - one with non polymorphic ABCs and the other with the actual implementations, and define and use your polymorphic versions only when serializing. (It is not just enough to define your polymorphic classes - you'll need to define EVERY class that may potentially be saved twice. And also a transformation layer between them - ๐Ÿคฎ Or... You can partake the unspeakable horrors of my PR. I've tried to limit the crazy to
discriminated_union.py
My biggest sins in that file are: โ€ข Monkey patching the
__init__
method of
TypeAdapter
(Though I do use splat parameters to and don't access anything private to minimize the damage - it just feels gross) โ€ข Directly accessing the dunder values on the pydantic models in order to replace them with their polymorphic equivalents. (Kind of subverts the immutability of models) I'd love to merge this soon
๐Ÿ‘€ 1
w
Is there something we can give up to make this better?
Maybe we can just deal with repeated/copypasta code?
Not infrequently I find that better than clever methods for keeping things DRY
When I hear terms like
TypeAdapter
or `DiscriminatedFieldsMixin`or
discriminated_union
or
factory_path
I'm inclined to think we've overcomplicated things ๐Ÿ˜… So I'd try and step back and figure out if there's some requirement we're trying to fulfill (like no repeated code, full serializability, MCP support, etc) that we might be able to relax to make this better
s
The requirement here is to make the polymorphic structures we developed serializable using pydantic. Developers will only notice this at all if they create custom event types. I can go over why this is the best solution and the other solutions didn't work if you're interested.
And then only in the context of saving data or creating custom server endpoints
w
Thanks for taking a crack at this Tim, I'm at the mechanic rn but I'll take a look as soon as I get back
w
Are we sure we need polymorphism? Would just defining classes with duplicated code make things simpler? (I'm mostly just agitating here, the answer might very well be "yes"--I'm not close enough to the code to make a judgement)
s
It does make a lot of things more elegant - the only thing it negatively affects is serialization
I think this effectively isolates that problem
And I think most developers will never even know this is here
And it's not that unusual to have a common base type for all your models
c
yeah, calvin juan and i had a rubber duck session yesteryday that sort of result in the same conclusion -- we still need some form of typing to make our developing life easier & make bugs easier to spot & code easier to read
s
Maybe the name is what bugs me
w
๐Ÿ‘ thanks y'all. I know this is tricky stuff
c
i'll take a look at the PR now and testing it -- if everything goes well, i'll help merge it ๐Ÿ™‚
s
I think a better name for the root class is "OpenHandsModel" (Instead of "DiscriminatedTypeFieldsMixin"
lolsob 1
c
i also spent some effort yesterday to simplify the mcp action so serialization for MCP action is considered solved too (we don't need to save the spec again); i believe tim's fix and my fix here should set us pretty well for the future
s
And "OpenHandsUnion" instead of "DiscriminatedTypeUnion"
c
these are internal to our codebase so we can probably do it in future PR to save the git diff a bit ๐Ÿ˜…
s
We should coordinate as soon as Calvin is available
c
@straight-sundown-84319lefting comments as i go through it
gratitude thank you 1
w
What about EventModel or EventUnion?
(assuming that's accurate)
OpenHandsUnion doesn't really say much
s
Not just events
w
This is for all pydantic types in the SDK?
s
The OpenHandsModel will likely be
๐Ÿ‘ 1
w
agreed that's at least a less intimidating name ๐Ÿ˜‚
s
The union is for items that are polymorphic - events, actions, observations, tools, security analyzers, agents, etc
c
btw tim, minor q: what makes you switch from qualname to just classname? maybe just for brevity?
s
2 reasons
โ€ข Brevity โ€ข We define local classes which share a common name anyway - so using the full module sometimes just gives us a false sense of security
And it implies a relation where one may not exist
(ie: It implies you can load this path to find this class, which is true MOST of the time, but not all the time)
c
so because of this switch, i imagine that's why you need to rename most classes in the test, right lolsob So will it throw an error if there's two class defined with the same name in different files?
s
Yes
I added that because the collisions are hard to diagnose otherwise
๐Ÿ‘ 1
c
i think collision detection is very good to have - better to be errored out explicitly
s
I certainly found it to be the case when testing - once I put the check in I went from ~30 failing tests to ~1 in a matter of a few short commits
c
go through all the changes besides the discriminative union implementation -- once comments are addressed, most other stuff lgtm. Will look deeper into the discriminative union logic here and once calvin also think that looks good, i think this PR is good to merge
s
A lot of these...
were due to the fact that the
DiscriminatedFieldMixin
did not used to extend the
OpenHandsModel
Nice catch!
c
๐Ÿ‘ lmk when you fixed that and i'd happy to take another look!
fyi @straight-sundown-84319, i will bring the openapi schema test back in the CI in your pr if you are ok with it (it will try to generate openapi.json, then try to use it to generate a python client -- we didn't use that client, but i found it was pretty helpful in spotting potentially JSON schema issue)
๐Ÿ™ 1
For example, i found some schema issue with Condenser now
โฏ make test-server-schema
Checking uv version...
uv version 0.8.13 meets requirements
set -euo pipefail;
# Generate OpenAPI JSON inline (no file left in repo)
uv run python -c 'import os,json; from openhands.agent_server.api import api; open("openapi.json","w").write(json.dumps(api.openapi(), indent=2))'
/Users/xingyaow/Projects/All-Hands-AI/openhands-v1-dev/agent-sdk.worktree/worktree2/.venv/lib/python3.12/site-packages/litellm/llms/custom_httpx/async_client_cleanup.py66 DeprecationWarning: There is no current event loop
loop = asyncio.get_event_loop()
# Generate client from the temp schema and fail on any warnings to check
uv run openapi-python-client generate \
--path "openapi.json" \
--output-path ".client" \
--meta uv \
--overwrite \
--fail-on-warning
Generating .client
Warning(s) encountered while generating. Client was generated, but some pieces may be missing
WARNING parsing GET /conversations/search within default.
Cannot parse response for status code 200 (Could not find reference in parsed models or enums), response will be omitted from generated client
Reference(ref='#/components/schemas/ConversationPage')
WARNING parsing GET /conversations/{conversation_id} within default.
Cannot parse response for status code 200 (Could not find reference in parsed models or enums), response will be omitted from generated client
Reference(ref='#/components/schemas/ConversationInfo')
WARNING parsing GET /conversations/ within default.
Cannot parse response for status code 200 (Invalid property in union response_200_item), response will be omitted from generated client
Reference(ref='#/components/schemas/ConversationInfo')
WARNING parsing POST /conversations/ within default.
Cannot parse response for status code 200 (Could not find reference in parsed models or enums), response will be omitted from generated client
Reference(ref='#/components/schemas/ConversationInfo')
Unable to parse schema /components/schemas/LLMSummarizingCondenser-Output
Unable to parse this part of your OpenAPI document: : Attempted to generate duplicate models with name "LLMSummarizingCondenser"
Schema(title='LLMSummarizingCondenser', multipleOf=None, maximum=None, exclusiveMaximum=None, minimum=None, exclusiveMinimum=None, maxLength=None, minLength=None, pattern=None, maxItems=None, minItems=None, uniqueItems=None, maxProperties=None, minProperties=None, required=['llm', 'kind'], enum=None, const=None, type=<DataType.OBJECT: 'object'>, allOf=[], oneOf=[], anyOf=[], schema_not=None, items=None, prefixItems=[], properties={'llm': Reference(ref='#/components/schemas/LLM'), 'max_size': Schema(title='Max Size', multipleOf=None, maximum=None, exclusiveMaximum=None, minimum=None, exclusiveMinimum=0.0, maxLength=None, minLength=None, pattern=None, maxItems=None, minItems=None, uniqueItems=None, maxProperties=None, minProperties=None, required=None, enum=None, const=None, type=<DataType.INTEGER: 'integer'>, allOf=[], oneOf=[], anyOf=[], schema_not=None, items=None, prefixItems=[], properties=None, additionalProperties=None, description=None, schema_format=None, default=120, nullable=False, discriminator=None, readOnly=None, writeOnly=None, xml=None, externalDocs=None, example=None, deprecated=None), 'keep_first': Schema(title='Keep First', multipleOf=None, maximum=None, exclusiveMaximum=None, minimum=0.0, exclusiveMinimum=None, maxLength=None, minLength=None, pattern=None, maxItems=None, minItems=None, uniqueItems=None, maxProperties=None, minProperties=None, required=None, enum=None, const=None, type=<DataType.INTEGER: 'integer'>, allOf=[], oneOf=[], anyOf=[], schema_not=None, items=None, prefixItems=[], properties=None, additionalProperties=None, description=None, schema_format=None, default=4, nullable=False, discriminator=None, readOnly=None, writeOnly=None, xml=None, externalDocs=None, example=None, deprecated=None), 'kind': Schema(title='Kind', multipleOf=None, maximum=None, exclusiveMaximum=None, minimum=None, exclusiveMinimum=None, maxLength=None, minLength=None, pattern=None, maxItems=None, minItems=None, uniqueItems=None, maxProperties=None, minProperties=None, required=None, enum=None, const=None, type=<DataType.STRING: 'string'>, allOf=[], oneOf=[], anyOf=[], schema_not=None, items=None, prefixItems=[], properties=None, additionalProperties=None, description='Property to create kind field from class name when serializing.', schema_format=None, default=None, nullable=False, discriminator=None, readOnly=True, writeOnly=None, xml=None, externalDocs=None, example=None, deprecated=None)}, additionalProperties=None, description=None, schema_format=None, default=None, nullable=False, discriminator=None, readOnly=None, writeOnly=None, xml=None, externalDocs=None, example=None, deprecated=None)
Unable to parse schema /components/schemas/NoOpCondenser-Output
Unable to parse this part of your OpenAPI document: : Attempted to generate duplicate models with name "NoOpCondenser"
Schema(title='NoOpCondenser', multipleOf=None, maximum=None, exclusiveMaximum=None, minimum=None, exclusiveMinimum=None, maxLength=None, minLength=None, pattern=None, maxItems=None, minItems=None, uniqueItems=None, maxProperties=None, minProperties=None, required=['kind'], enum=None, const=None, type=<DataType.OBJECT: 'object'>, allOf=[], oneOf=[], anyOf=[], schema_not=None, items=None, prefixItems=[], properties={'kind': Schema(title='Kind', multipleOf=None, maximum=None, exclusiveMaximum=None, minimum=None, exclusiveMinimum=None, maxLength=None, minLength=None, pattern=None, maxItems=None, minItems=None, uniqueItems=None, maxProperties=None, minProperties=None, required=None, enum=None, const=None, type=<DataType.STRING: 'string'>, allOf=[], oneOf=[], anyOf=[], schema_not=None, items=None, prefixItems=[], properties=None, additionalProperties=None, description='Property to create kind field from class name when serializing.', schema_format=None, default=None, nullable=False, discriminator=None, readOnly=True, writeOnly=None, xml=None, externalDocs=None, example=None, deprecated=None)}, additionalProperties=None, description='Simple condenser that returns a view un-manipulated.\n\nPrimarily intended for testing purposes.', schema_format=None, default=None, nullable=False, discriminator=None, readOnly=None, writeOnly=None, xml=None, externalDocs=None, example=None, deprecated=None)
Unable to parse schema /components/schemas/PipelineCondenser-Output
Unable to parse this part of your OpenAPI document: : Attempted to generate duplicate models with name "PipelineCondenser"
Schema(title='PipelineCondenser', multipleOf=None, maximum=None, exclusiveMaximum=None, minimum=None, exclusiveMinimum=None, maxLength=None, minLength=None, pattern=None, maxItems=None, minItems=None, uniqueItems=None, maxProperties=None, minProperties=None, required=['condensers', 'kind'], enum=None, const=None, type=<DataType.OBJECT: 'object'>, allOf=[], oneOf=[], anyOf=[], schema_not=None, items=None, prefixItems=[], properties={'condensers': Schema(title='Condensers', multipleOf=None, maximum=None, exclusiveMaximum=None, minimum=None, exclusiveMinimum=None, maxLength=None, minLength=None, pattern=None, maxItems=None, minItems=None, uniqueItems=None, maxProperties=None, minProperties=None, required=None, enum=None, const=None, type=<DataType.ARRAY: 'array'>, allOf=[], oneOf=[], anyOf=[], schema_not=None, items=Schema(title=None, multipleOf=None, maximum=None, exclusiveMaximum=None, minimum=None, exclusiveMinimum=None, maxLength=None, minLength=None, pattern=None, maxItems=None, minItems=None, uniqueItems=None, maxProperties=None, minProperties=None, required=None, enum=None, const=None, type=None, allOf=[], oneOf=[Reference(ref='#/components/schemas/PipelineCondenser-Output'), Reference(ref='#/components/schemas/LLMSummarizingCondenser-Output'), Reference(ref='#/components/schemas/NoOpCondenser-Output')], anyOf=[], schema_not=None, items=None, prefixItems=[], properties=None, additionalProperties=None, description=None, schema_format=None, default=None, nullable=False, discriminator=None, readOnly=None, writeOnly=None, xml=None, externalDocs=None, example=None, deprecated=None), prefixItems=[], properties=None, additionalProperties=None, description=None, schema_format=None, default=None, nullable=False, discriminator=None, readOnly=None, writeOnly=None, xml=None, externalDocs=None, example=None, deprecated=None), 'kind': Schema(title='Kind', multipleOf=None, maximum=None, exclusiveMaximum=None, minimum=None, exclusiveMinimum=None, maxLength=None, minLength=None, pattern=None, maxItems=None, minItems=None, uniqueItems=None, maxProperties=None, minProperties=None, required=None, enum=None, const=None, type=<DataType.STRING: 'string'>, allOf=[], oneOf=[], anyOf=[], schema_not=None, items=None, prefixItems=[], properties=None, additionalProperties=None, description='Property to create kind field from class name when serializing.', schema_format=None, default=None, nullable=False, discriminator=None, readOnly=True, writeOnly=None, xml=None, externalDocs=None, example=None, deprecated=None)}, additionalProperties=None, description='A condenser that applies a sequence of condensers in order.\n\nAll condensers are defined primarily by their
condense
method, which takes a\n`View` and returns either a new
View
or a
Condensation
event. That means we can\nchain multiple condensers together by passing `View`s along and exiting early if any\ncondenser returns a
Condensation
.\n\nFor example:\n\n # Use the pipeline condenser to chain multiple other condensers together\n condenser = PipelineCondenser(condensers=[\n CondenserA(...),\n CondenserB(...),\n CondenserC(...),\n ])\n\n result = condenser.condense(view)\n\n # Doing the same thing without the pipeline condenser requires more boilerplate\n # for the monadic chaining\n other_result = view\n\n if isinstance(other_result, View):\n other_result = CondenserA(...).condense(other_result)\n\n if isinstance(other_result, View):\n other_result = CondenserB(...).condense(other_result)\n\n if isinstance(other_result, View):\n other_result = CondenserC(...).condense(other_result)\n\n assert result == other_result', schema_format=None, default=None, nullable=False, discriminator=None, readOnly=None, writeOnly=None, xml=None, externalDocs=None, example=None, deprecated=None)
Unable to process schema /components/schemas/ConversationInfo:
Invalid property in union condenser
Failure to process schema has resulted in the removal of:
/components/schemas/ConversationInfo
/components/schemas/ConversationPage
Schema(title=None, multipleOf=None, maximum=None, exclusiveMaximum=None, minimum=None, exclusiveMinimum=None, maxLength=None, minLength=None, pattern=None, maxItems=None, minItems=None, uniqueItems=None, maxProperties=None, minProperties=None, required=None, enum=None, const=None, type=None, allOf=[], oneOf=[Reference(ref='#/components/schemas/PipelineCondenser-Output'), Reference(ref='#/components/schemas/LLMSummarizingCondenser-Output'), Reference(ref='#/components/schemas/NoOpCondenser-Output')], anyOf=[], schema_not=None, items=None, prefixItems=[], properties=None, additionalProperties=None, description=None, schema_format=None, default=None, nullable=False, discriminator=None, readOnly=None, writeOnly=None, xml=None, externalDocs=None, example=None, deprecated=None)
If you believe this was a mistake or this tool is missing a feature you need, please open an issue at https://github.com/openapi-generators/openapi-python-client/issues/new/choose
make: * [test-server-schema] Error 1
w
@straight-sundown-84319 I made it back to my computer, lmk if we need to sync on anything. Otherwise I'll just start poking around your PR
s
Please do! The more ๐Ÿ‘€ the better
๐Ÿ‘ 1
c
weird thing seems to be going on for condenser, maybe some base class is not configured correctly
๐Ÿ‘€ 1
You can find errors in CI https://github.com/All-Hands-AI/agent-sdk/actions/runs/17861937831/job/50794719990?pr=331 or running
make test-server-schema
locally
s
I also see them when running my local server
The issue becomes clear when you view the
openapi.json
It looks pydantic / model related. It is related to the
kind
field. So in this case: โ€ข Output includes a
kind
โ€ข Input does not accept a
kind
(Which is weird and the root of the problem) So the json schema resolves this to 2 different
LLMSummarizingCondenser
types with the same title: โ€ข LLMSummarizingCondenser-Input โ€ข LLMSummarizingCondenser-Output
So I gotta check out why we don't accept a kind for input on this...
nod 1
w
I didn't even know we had that many files ๐Ÿ˜‚
๐Ÿคฃ 1
c
if it makes you feel anybetter, i already gone through most of them and they are simpy renaming -- you can focus on the core discriminative union logic if you want, the rest of the file you can just "trust me bro!"
s
The discriminated union is the meat and potatoes of the PR
w
I just thought the high number was funny, it's not a bad PR to review at all
nod 1
c
โฏ repomix --ignore '**/*.json'
๐Ÿ“ฆ Repomix v1.4.2
No custom config found at repomix.config.json5, repomix.config.jsonc, repomix.config.json or global config at /Users/xingyaow/.config/repomix/repomix.config.json5, /Users/xingyaow/.config/repomix/repomix.config.jsonc, /Users/xingyaow/.config/repomix/repomix.config.json.
You can add a config file for additional settings. Please check https://github.com/yamadashy/repomix for more information.
โœ”๏ธ Packing completed successfully!
๐Ÿ“ˆ Top 5 Files by Token Count:
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
1. openhands/sdk/llm/mixins/fn_call_converter.py (8,323 tokens, 39,911 chars, 2.1%)
2. tests/tools/execute_bash/test_bash_session.py (7,816 tokens, 35,666 chars, 2%)
3. tests/tools/str_replace_editor/test_basic_operations.py (7,072 tokens, 30,035 chars, 1.8%)
4. tests/sdk/context/test_view.py (6,924 tokens, 30,632 chars, 1.8%)
5. openhands/sdk/llm/llm.py (6,856 tokens, 32,732 chars, 1.8%)
๐Ÿ”Ž Security Check:
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
โœ”๏ธ No suspicious files detected.
๐Ÿ“Š Pack Summary:
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
Total Files: 310 files
Total Tokens: 390,871 tokens
Total Chars: 1,787,654 chars
Output: repomix-output.xml
Security: โœ”๏ธ No suspicious files detected
๐ŸŽ‰ All Done!
Your repository has been successfully packed.
Our repo is now 310 files, so this PR touches 1/3 of the file lolsob
c
I have the growing suspicion that if you want to your traditional extendable polymorphism then the creators of Pydantic hate you and want nothing but sadness for your future.
Ouchy ๐Ÿ˜… I remember Pydantic had plastered on its home site something like: Pydantic is a VERY opinionated framework and totally proud of it! Itโ€™s that thing, if you do things its way, fine, it makes some things easier. But if you fight it, specially on the fundamentals, you will cry.
nod 1
s
That said - After my next commit I think we have something that works well
๐Ÿ‘ 1
c
Thank you for the work on this - I took a quick look on the PR but I have no opinion on the details, justโ€ฆ idk, fingers crossed lolsob
c
Ok I think all LGTM and we can merge it if we got green light from @wide-doctor-37830 & we fixed the kind issue and get OpenAPI schema test passing
s
Kind issue is fixed
Now working on OpenAPI schema
And I responded to Calvin's comments
๐Ÿ‘ 1
w
Green light from me, I had a few follow up comments but they're addressable later. Would rather get the rest of y'all's work unblocked.
๐Ÿ™Œ 1
s
Merged
๐Ÿ™Œ 1
c
Traceback (most recent call last):
File "/Users/xingyaow/Projects/All-Hands-AI/openhands-v1-dev/agent-sdk.worktree/worktree2/examples/10_persistence.py", line 109, in <module>
conversation = Conversation(
^^^^^^^^^^^^^
File "/Users/xingyaow/Projects/All-Hands-AI/openhands-v1-dev/agent-sdk.worktree/worktree2/openhands/sdk/conversation/conversation.py", line 65, in init
self.state = ConversationState.create(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/xingyaow/Projects/All-Hands-AI/openhands-v1-dev/agent-sdk.worktree/worktree2/openhands/sdk/conversation/state.py", line 138, in create
state = cls.model_validate(json.loads(base_text))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/xingyaow/Projects/All-Hands-AI/openhands-v1-dev/agent-sdk.worktree/worktree2/openhands/sdk/utils/models.py", line 67, in model_validate
return super().model_validate(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/xingyaow/Projects/All-Hands-AI/openhands-v1-dev/agent-sdk.worktree/worktree2/.venv/lib/python3.12/site-packages/pydantic/main.py", line 705, in model_validate
return cls.__pydantic_validator__.validate_python(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.ValidationError: 1 validation error for ConversationState
agent.kind
Input should be 'Condensation', 'CondensationRequest', 'MessageEvent', 'PauseEvent', 'FinishAction', 'ActionEvent', 'FinishObservation', 'AgentErrorEvent', 'ObservationEvent', 'ThinkAction', 'Tool', 'ThinkObservation', 'CondensationSummaryEvent', 'SystemPromptEvent' or 'UserRejectObservation' [type=literal_error, input_value='AgentBase', input_type=str]
For further information visit https://errors.pydantic.dev/2.11/v/literal_error
facepalm some how got this when running
examples/10_persistence.py
in my PR (https://github.com/All-Hands-AI/agent-sdk/pull/342) seems like there's still some weird edge cases
s
I see it on main - investigating
c
removing ABC from AgentBase seems to fix it in parts
conversation = Conversation(
^^^^^^^^^^^^^
File "/Users/xingyaow/Projects/All-Hands-AI/openhands-v1-dev/agent-sdk.worktree/worktree2/openhands/sdk/conversation/conversation.py", line 65, in init
self.state = ConversationState.create(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/xingyaow/Projects/All-Hands-AI/openhands-v1-dev/agent-sdk.worktree/worktree2/openhands/sdk/conversation/state.py", line 148, in create
resolved = agent.resolve_diff_from_deserialized(state.agent)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/xingyaow/Projects/All-Hands-AI/openhands-v1-dev/agent-sdk.worktree/worktree2/openhands/sdk/agent/base.py", line 177, in resolve_diff_from_deserialized
raise ValueError(
ValueError: Cannot resolve from deserialized: persisted agent is of type AgentBase, but self is of type Agent.
/Users/xingyaow/Projects/All-Hands-AI/openhands-v1-dev/agent-sdk.worktree/worktree2/.venv/lib/python3.12/site-packages/litellm/llms/custom_httpx/async_client_cleanup.py66 DeprecationWarning: There is no current event loop
loop = asyncio.get_event_loop()
But when i serialize and save
Agent
- it is saved as
kind=AgentBase
s
Oh - I think I know what's going on there
๐Ÿ‘ 1
c
I took a look at local JSON, the
kind=Agent
is correct, but just when we load it back and do
.model_validate
, some how it got tranformed to
AgentBase
Just some additional info hopefully it is helpful ๐Ÿ™‚ will work on smth else until you figured this out
s
Yeah - it is related to one of the last commits I made
c
@straight-sundown-84319, were you able to figure it out? I have a couple PRs i want to get in but blocked by this ๐Ÿ˜ญ
s
I'm close
๐Ÿ™Œ 1
Down to 1 broken test
excited 1
(From 30)
Ready for review
c
left a comment -- any idea why we want to specifically add resolve_kind for Agent? Shouldn't the mixin should figured it out?
s
The resolve kind for agent has a fallback
if you cant find an appropriate AgentBase then use Agent
The default impl throws an error
We have a bunch of tests checking for the fallback
Hence the override
c
actually i was looking at the tests
it seems some test doesn't feel valid too me
working on it now
@straight-sundown-84319 GPT-5 thinks this is the right fix, the root issue was
len(subclasses)<2
https://github.com/All-Hands-AI/agent-sdk/pull/364/commits/3420a818ad3bace6416c58fee3a42266379cdd94
image.png
actually, this
len(subclasses)<2
is the only fixes that's required. I've reverted your change and all sdk tests seems passing too
confirmed things are fixed with 10_persistence.py example, ๐Ÿ™‚ will merge it but happy to revert if you have additional concerns!
๐Ÿ™Œ 1
@straight-sundown-84319 a bit more fixes here
actually, this
len(subclasses)<2
is the only fixes that's required. I've reverted your change and all sdk tests seems passing too
turns out this was wrong too ๐Ÿ˜… the schema generation test is flaky... I've brought most of the content back in this PR: https://github.com/All-Hands-AI/agent-sdk/pull/374 Issues: It turns out that somehow
TypeAdapter.__init__
hacks at the bottom were causing the issue, and yet CI passes (bc things are breaking randomly ๐Ÿ˜…): 1.
get_known_concrete_subclasses
returns a set, and the order is non-deterministic, so sometimes
make test-server-schema
works and sometimes they don't 2.
TypeAdapter.__init__
alters the schema mid-traversal, breaking the schema generation ๐Ÿ˜… Applied some fixes suggested by GPT-5: 1. make
get_known_concrete_subclasses
return a sorted list based on
qualname
to get rid of the nondeterministic issue 2. In
__init_subclass__
when a concrete subclass is defined, we stamp a stable kind: Literal["ClassName"], check for duplicate kinds, and proactively rebuild the abstract โ€œownerโ€ unions so their schemas include the new subclass immediately The good news is that we can get rid of the
TypeAdapter
fix and everything still works now! Would like to get these fixes in ๐Ÿ™ https://github.com/All-Hands-AI/agent-sdk/pull/374 Want to get this unblocked myself, but do want to let you take a look whenever you have time next Monday to make sure I'm not doing weird things! All tests pass now & local schema generation works!
s
This is awesome - it is good to get that hack out of there
Looking now
๐Ÿ™Œ 1
Approved!
Let's get this merged!
c
awesome! thank you for taking a look!!!