diff --git a/langstream-agents/langstream-agent-http-request/src/main/java/ai/langstream/agents/http/LangServeClient.java b/langstream-agents/langstream-agent-http-request/src/main/java/ai/langstream/agents/http/LangServeClient.java index e490a9107..256847ec4 100644 --- a/langstream-agents/langstream-agent-http-request/src/main/java/ai/langstream/agents/http/LangServeClient.java +++ b/langstream-agents/langstream-agent-http-request/src/main/java/ai/langstream/agents/http/LangServeClient.java @@ -146,7 +146,12 @@ private Object parseResponseBody(String body, boolean streaming) { Map map = mapper.readValue(body, new TypeReference>() {}); if (!streaming) { - map = (Map) map.get("output"); + Object output = map.get("output"); + if (output == null || output instanceof String) { + return output; + } else if (output instanceof Map) { + map = (Map) output; + } } if (options.contentField.isEmpty()) { return map; diff --git a/langstream-agents/langstream-agent-http-request/src/test/java/ai/langstream/agents/http/LangServeInvokeAgentTest.java b/langstream-agents/langstream-agent-http-request/src/test/java/ai/langstream/agents/http/LangServeInvokeAgentTest.java index 9905484fe..ed0eb4210 100644 --- a/langstream-agents/langstream-agent-http-request/src/test/java/ai/langstream/agents/http/LangServeInvokeAgentTest.java +++ b/langstream-agents/langstream-agent-http-request/src/test/java/ai/langstream/agents/http/LangServeInvokeAgentTest.java @@ -57,6 +57,15 @@ void testInvokeJSONMap(WireMockRuntimeInfo wireMockRuntimeInfo) throws Exception testInvoke(wireMockRuntimeInfo, response); } + @Test + void testInvokeJSONMapWithoutContent(WireMockRuntimeInfo wireMockRuntimeInfo) throws Exception { + String response = + """ + {"output":"Why don't cats play poker in the wild? Too many cheetahs!"} + """; + testInvoke(wireMockRuntimeInfo, response); + } + @Test void testInvokeJSONString(WireMockRuntimeInfo wireMockRuntimeInfo) throws Exception { String response =