Skip to content

feat(langgraph): support input_schema, output_schema and include_contents - #385

Merged
antiv merged 2 commits into
antiv:mainfrom
tharunsridhar:feat/langgraph-schemas-include-contents
Nov 20, 2026
Merged

antiv merged 2 commits into
antiv:mainfrom
tharunsridhar:feat/langgraph-schemas-include-contents

Conversation

@tharunsridhar

Copy link
Copy Markdown
Contributor

What and why

An agent's output_schema, input_schema and include_contents worked 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.
    • The agent keeps its tools and transfers.
    • It ends its turn by calling set_model_response, a tool whose arguments are the schema (return_direct, so the run ends there).
    • The prompt tells the model to answer through that tool, with ADK's wording.
    • The event translator sends the answer as one JSON text event, so the session reply is the JSON text, as on ADK. The call itself is not shown.
  • include_contents: none shows 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 or default shows everything. The checkpoint still holds the whole conversation.
  • input_schema: parsed with the same json_schema_to_pydantic_model conversion and the same warnings for bad JSON or a non-object schema. No run-time effect: on ADK it only shapes an agent called through AgentTool, 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

  • No provider-native JSON mode and no with_structured_output call. The tool-call route needs a model that supports tool calling, like the rest of this runtime.
  • A model that answers in plain text without calling set_model_response is returned as it is. ADK does not force it either.
  • If the arguments do not match the schema, the run ends with the validation error as a function response and no JSON answer. The JSON text event goes out with the call, so a client sees the invalid JSON before the error.

How it was tested

  • New 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_schema accepted and ignored, an invalid schema ignored, and include_contents none, default, empty and the current turn's tool messages.
  • python -m unittest discover -s shared/test -t . -p "test_langgraph_*.py": 105 tests, OK.
  • Full suite with PYTHONUTF8=1 on Windows: 2062 tests, 2 failures and 18 errors in test_workspaces_schema, test_mate_help_agent, test_settings, test_feedback_to_eval and test_async_tool_adapter. The same 94 tests in those modules fail the same way on clean main, so they are not from this change.
  • ruff on the changed files: only two existing == False comparisons in code this change does not touch.
  • Not run against a real provider.

Checklist

  • Tests added or updated in shared/test/. The full suite has the failures listed above, which are also on main.
  • Schema changes have a migration: no schema change
  • Changed a route, env var, model or the tool registry: none changed
  • Ran python scripts/gen_docs.py drift --base origin/main. It lists docs/user/fallback-model.md, docs/user/file-search.md and docs/dev/agent-runtime.md. None of them mentions schemas or include_contents, so they still hold.
  • New user-facing feature: the dev guide is updated. No dashboard change.
  • No API keys, tokens or credentials in code, logs or tests

@tharunsridhar
tharunsridhar requested a review from antiv as a code owner November 19, 2026 19:50

@antiv antiv left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_direct ends 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: _run creates a new event loop on every call and never closes it, which gives ResourceWarnings across the 13 tests. asyncio.run(coro) does the same and closes the loop.
  • TestIncludeContents._shown: not m.type == "system" reads better as m.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.
@tharunsridhar

Copy link
Copy Markdown
Contributor Author

Thanks for the careful review, you were right on both points. Pushed 3392d5a.

Finding

  • The call is now hidden in the translator. The reply text comes from the set_model_response result when its status is not error, so it is the validated model_dump_json output, not the raw args.
  • On a schema mismatch the translator emits the call and the error as normal function events and no text event. The invalid JSON is no longer persisted as the last answer.
  • The mismatch test now asserts there is no text event and that the call is shown with its error.
  • New test for the coercion case: {"temp": "4"} replies as {"city":"Oslo","temp":4}.
  • Updated the output_schema bullet in docs/dev/langgraph-runtime.md to match.

Nits

  • _run uses asyncio.run.
  • _shown uses m.type != "system".

test_langgraph_*.py: 106 tests, OK. Not run against a real provider.

@antiv
antiv merged commit f40b8a1 into antiv:main Nov 20, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LangGraph runtime: input and output schemas and include_contents

2 participants