mirror of
https://github.com/TauricResearch/TradingAgents.git
synced 2026-06-30 03:34:19 +03:00
fix(structured): harden structured output for local servers and thinking models
- Local servers (LM Studio, vLLM) reject the object-form tool_choice langchain sends for function calling. The generic openai_compatible provider now binds the schema as a tool without forcing tool_choice. - A structured call can return no parsed result (a thinking model answering in plain text); fall back to free text with a clear reason instead of an opaque render error.
This commit is contained in:
@@ -121,6 +121,24 @@ def _structured_trader_llm(captured: dict, proposal: TraderProposal | None = Non
|
||||
return llm
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_invoke_structured_falls_back_when_result_is_none():
|
||||
# A thinking model can answer in plain text, leaving the parser with None.
|
||||
# That must fall back to free text, not crash on render(None) (#1051).
|
||||
from tradingagents.agents.utils.structured import invoke_structured_or_freetext
|
||||
|
||||
structured = MagicMock()
|
||||
structured.invoke.return_value = None
|
||||
plain = MagicMock()
|
||||
plain.invoke.return_value = MagicMock(content="FREETEXT")
|
||||
|
||||
out = invoke_structured_or_freetext(
|
||||
structured, plain, "prompt", render=lambda r: r.rating, agent_name="t"
|
||||
)
|
||||
assert out == "FREETEXT"
|
||||
plain.invoke.assert_called_once()
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
class TestTraderAgent:
|
||||
def test_structured_path_produces_rendered_markdown(self):
|
||||
|
||||
Reference in New Issue
Block a user