Repository navigation
feat(langgraph): support input_schema, output_schema and include_contents - #385
Conversation
antiv
left a comment
There was a problem hiding this comment.
Thanks @tharunsridhar, this follows the ADK path closely: the same json_schema_to_pydantic_model naming as agent_manager.py, set_model_response with ADK's prompt wording, and include_contents: "none" that keeps the current turn's tool calls. One finding, two nits.
Finding: the reply shown in the session is the raw call arguments, not the validated answer
event_translator.py builds the JSON text from tool_call["args"] when it sees the set_model_response call, before the tool has validated anything. It then drops the successful ToolMessage. Two results:
- On a schema mismatch (your
test_answer_violating_the_schema_is_not_returned_as_valid_json), the events are a text event{"city": "Oslo", "temp": "warm"}followed by the error as a function response. That text is persisted as the agent's last answer.return_directends the run on the error too (LangGraph routes to END on the tool name, whatever its status), so this invalid JSON is the final reply. Issue #374 asks that the final answer is JSON matching the schema. - On success, the text is the arguments as the model sent them, not
output_model(**kwargs).model_dump_json(...). Pydantic coercion ("4"→4) or defaults make the two differ.
Suggested fix: take the JSON text from the set_model_response ToolMessage when its status is not error (its content is already the validated JSON), and hide the call. On an error, emit the call and the error response as normal function events and no text. The test for the mismatch case could then assert that no text event carries the invalid JSON.
Nits (optional)
test_langgraph_schemas.py:_runcreates a new event loop on every call and never closes it, which givesResourceWarnings across the 13 tests.asyncio.run(coro)does the same and closes the loop.TestIncludeContents._shown:not m.type == "system"reads better asm.type != "system".
CI hasn't run yet: this is a first PR from a fork, so the workflows are waiting for a maintainer's approval.
If you enjoy working on this repo, please consider giving it a ⭐!
Generated by Claude Code
…valid arguments The event translator built the JSON reply from the set_model_response call arguments before the tool validated them. On a schema mismatch the invalid JSON became the final answer, and on success coercion and defaults were lost. Hide the call and take the reply from the tool's non-error result. On an error emit the call and its error as function events and no text. Test cleanups: asyncio.run in _run, and != in _shown.
|
Thanks for the careful review, you were right on both points. Pushed 3392d5a. Finding
Nits
|
What and why
An agent's
output_schema,input_schemaandinclude_contentsworked on the ADK runtime and were ignored on the LangGraph runtime. They were listed under "Not supported in v1". This makes the LangGraph runtime behave like ADK for all three.Closes #374
How it maps to ADK
output_schema: same mechanism as ADK's tools-plus-schema path.set_model_response, a tool whose arguments are the schema (return_direct, so the run ends there).include_contents:noneshows the model the messages from the latest user message on, so the current turn's tool calls and results stay (ADK's "current turn" rule). Empty ordefaultshows everything. The checkpoint still holds the whole conversation.input_schema: parsed with the samejson_schema_to_pydantic_modelconversion and the same warnings for bad JSON or a non-object schema. No run-time effect: on ADK it only shapes an agent called throughAgentTool, which MATE does not use.docs/dev/langgraph-runtime.md: removed from "Not supported in v1" and added a "Schemas and include_contents" section.Differences from ADK
with_structured_outputcall. The tool-call route needs a model that supports tool calling, like the rest of this runtime.set_model_responseis returned as it is. ADK does not force it either.How it was tested
shared/test/test_langgraph_schemas.py, 13 tests with a scripted chat model (no API key). They cover a valid answer, tools before the answer, a schema mismatch, no schema,input_schemaaccepted and ignored, an invalid schema ignored, andinclude_contentsnone, default, empty and the current turn's tool messages.python -m unittest discover -s shared/test -t . -p "test_langgraph_*.py": 105 tests, OK.PYTHONUTF8=1on Windows: 2062 tests, 2 failures and 18 errors intest_workspaces_schema,test_mate_help_agent,test_settings,test_feedback_to_evalandtest_async_tool_adapter. The same 94 tests in those modules fail the same way on cleanmain, so they are not from this change.ruffon the changed files: only two existing== Falsecomparisons in code this change does not touch.Checklist
shared/test/. The full suite has the failures listed above, which are also onmain.python scripts/gen_docs.py drift --base origin/main. It listsdocs/user/fallback-model.md,docs/user/file-search.mdanddocs/dev/agent-runtime.md. None of them mentions schemas orinclude_contents, so they still hold.