Skip to content

bug(mind): structure build and retrieve fail on json_object-only providers #126

Description

@keli-wen

🐛 Bug Description

Both LLM stages of the structure-retrieval feature request strict structured output through the Agents SDK output_type=, which sends a strict json_schema response_format: the draft-structuring agent in quantmind/flows/paper/_structure.py (output_type=PaperStructureTreeDraft) and the agentic retriever in quantmind/mind/retrieval.py (output_type=_RetrievalSelectionDraft). Providers that support only response_format: {"type": "json_object"} and not strict json_schema — DeepSeek, for example — reject the request, so both PaperFlow.build and AgenticRetriever.retrieve fail. This contradicts the multi-model support documented in contexts/design/mind/retrieval.md ("Multi-Model Compatibility").

🔄 Steps to Reproduce

  1. Set DEEPSEEK_API_KEY and select a DeepSeek model, e.g. PaperStructureCfg(model="litellm/deepseek/deepseek-chat").
  2. Run await PaperFlow(cfg).build(LocalFilePath(path=<any page-aware pdf>)).
  3. Observe the failure at the draft-structuring call; AgenticRetriever.retrieve fails identically for the same reason.

✅ Expected Behavior

Structure build and agentic retrieve run on any provider the SDK can route, including json_object-only providers, consistent with the design's multi-model-compatibility claim.

❌ Actual Behavior

The provider rejects the strict json_schema response_format and the build aborts before producing a tree.

📋 Environment

📝 Additional Context

Offline tests mock agents.Runner.run, so no real response_format is ever sent; the "covers at least one non-OpenAI model" claim in the design is mock-only, which is why this stayed hidden until a live smoke run. OpenAI models, which support strict json_schema, work end to end.

Error Logs

litellm.exceptions.BadRequestError: litellm.BadRequestError: DeepseekException - {"error":{"message":"This response_format type is unavailable now","type":"invalid_request_error","code":"invalid_request_error"}}
  File "quantmind/flows/paper/_structure.py", line 130, in structure
    output = await asyncio.wait_for(run_with_observability(agent, ...))

🛠️ Possible Solution

Port the compatibility handling already implemented on branch feat/mind-memory (commit 1dc67ee — "fix(flows): real LLM-call compatibility — MCP lifecycle, JSON-object fallback, schema-strict bypass") to this feature's structuring and retrieval agents: fall back to json_object (or a non-strict mode) when a provider does not support strict json_schema, and validate the parsed output in code. Add a live smoke assertion against at least one json_object-only provider so this cannot regress silently.


Checklist

  • I have searched existing issues to avoid duplicates
  • I have provided a clear and concise description
  • I have included steps to reproduce the issue
  • I have included my environment information
  • I have included relevant error logs or screenshots

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: flowsPublic operation implementations under quantmind/flows/area: mindMemory, tools, MCP integration, and the cognitive layerimpact: live-networkChanges or depends on real public-network behavior or smoke teststype: bugExisting behavior violates its contract or documented expectation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions