feat(sdk): add static structured output to subagent response#2437
feat(sdk): add static structured output to subagent response#2437Maahir Sachdev (maahir30) wants to merge 5 commits intomainfrom
Conversation
| skills: NotRequired[list[str]] | ||
| """Skill source paths for SkillsMiddleware.""" | ||
|
|
||
| response_format: NotRequired[ResponseFormat[Any] | type | dict[str, Any]] |
There was a problem hiding this comment.
Instead of documenting example usage, could we document what the options are?
What is type ? (i.e., allows pydantic model, dataclass etc)
waht is dict? (i think it's json schema)
Given that we allow a dataclass, does this code work b/c there's a json.dumps?
|
|
||
| structured = result.get("structured_response") | ||
| if structured is not None: | ||
| content: str = structured.model_dump_json() if hasattr(structured, "model_dump_json") else json.dumps(structured) |
There was a problem hiding this comment.
Does the json.dumps work? I think response format may be a dataclass?
There was a problem hiding this comment.
missed that part. fixed by adding in a conditional check for data classes and then json dump accordingly
There was a problem hiding this comment.
added tests too to make sure
181df13 to
1ed2dd0
Compare
Merging this PR will not alter performance
Comparing Footnotes
|
| and child agents. | ||
| """ | ||
|
|
||
| import json |
There was a problem hiding this comment.
can we just use CityPopulation.model_validate_json(...) instead of importing json
| structured = result.get("structured_response") | ||
| if structured is not None: |
There was a problem hiding this comment.
little nit
| structured = result.get("structured_response") | |
| if structured is not None: | |
| if (structured := result.get("structured_response")) is not None: |
| create_agent_kwargs: dict[str, Any] = {} | ||
| if "response_format" in agent_: | ||
| create_agent_kwargs["response_format"] = agent_["response_format"] | ||
|
|
There was a problem hiding this comment.
eh no need to thread this through the legacy API, we'll remove
|
gah sorry, review was pending |
Port of langchain-ai/deepagentsjs#290 to Python.
response_formatfield toSubAgentTypedDict, allowing structured output schemas to be passed through tocreate_agentstructured_response, JSON-serialize it as theToolMessagecontent instead of extracting the last message textresponse_formatthrough in both the legacy and newSubAgentMiddlewareAPIsIntegration test ported from langchain-ai/deepagentsjs#423.