!function(){function t(t){document.documentElement.setAttribute("data-theme",t)}var e=function(){var t=null;try{t=new URLSearchParams(window.location.search).get("docusaurus-theme")}catch(t){}return t}()||function(){var t=null;try{t=localStorage.getItem("theme")}catch(t){}return t}();t(null!==e?e:"light")}(),document.documentElement.setAttribute("data-announcement-bar-initially-dismissed",function(){try{return"true"===localStorage.getItem("docusaurus.announcement.dismiss")}catch(t){}return!1}())

[Skip to main content](#__docusaurus_skipToContent_fallback)

LangChain v0.2 is coming soon! Preview the new docs [here](/v0.2/docs/introduction/).

[

![🦜️🔗 Langchain](/v0.1/img/brand/wordmark.png)![🦜️🔗 Langchain](/v0.1/img/brand/wordmark-dark.png)

](/v0.1/)[Docs](/v0.1/docs/get_started/introduction/)[Use cases](/v0.1/docs/use_cases/)[Integrations](/v0.1/docs/integrations/platforms/)[API Reference](https://api.js.langchain.com)

[More](#)

*   [People](/v0.1/docs/people/)
*   [Community](/v0.1/docs/community/)
*   [Tutorials](/v0.1/docs/additional_resources/tutorials/)
*   [Contributing](/v0.1/docs/contributing/)

[v0.1](#)

*   [v0.2](https://js.langchain.com/v0.2/docs/introduction)
*   [v0.1](/v0.1/docs/get_started/introduction/)

[🦜🔗](#)

*   [LangSmith](https://smith.langchain.com)
*   [LangSmith Docs](https://docs.smith.langchain.com)
*   [LangChain Hub](https://smith.langchain.com/hub)
*   [LangServe](https://github.com/langchain-ai/langserve)
*   [Python Docs](https://python.langchain.com/)

[Chat](https://chatjs.langchain.com)[](https://github.com/langchain-ai/langchainjs)

Search

*   [Get started](/v0.1/docs/get_started/)
    
    *   [Introduction](/v0.1/docs/get_started/introduction/)
    *   [Installation](/v0.1/docs/get_started/installation/)
    *   [Quickstart](/v0.1/docs/get_started/quickstart/)
*   [LangChain Expression Language](/v0.1/docs/expression_language/)
    
    *   [Get started](/v0.1/docs/expression_language/get_started/)
    *   [Why use LCEL?](/v0.1/docs/expression_language/why/)
    *   [Interface](/v0.1/docs/expression_language/interface/)
    *   [Streaming](/v0.1/docs/expression_language/streaming/)
    *   [How to](/v0.1/docs/expression_language/how_to/routing/)
        
    *   [Cookbook](/v0.1/docs/expression_language/cookbook/)
        
    *   [LangChain Expression Language (LCEL)](/v0.1/docs/expression_language/)
*   [Modules](/v0.1/docs/modules/)
    
    *   [Model I/O](/v0.1/docs/modules/model_io/)
        
    *   [Retrieval](/v0.1/docs/modules/data_connection/)
        
    *   [Chains](/v0.1/docs/modules/chains/)
    *   [Agents](/v0.1/docs/modules/agents/)
        
        *   [Quick start](/v0.1/docs/modules/agents/quick_start/)
        *   [Concepts](/v0.1/docs/modules/agents/concepts/)
        *   [Agent Types](/v0.1/docs/modules/agents/agent_types/)
            
        *   [How-to](/v0.1/docs/modules/agents/how_to/custom_agent/)
            
            *   [Custom agent](/v0.1/docs/modules/agents/how_to/custom_agent/)
            *   [Returning structured output](/v0.1/docs/modules/agents/how_to/agent_structured/)
            *   [Subscribing to events](/v0.1/docs/modules/agents/how_to/callbacks/)
            *   [Cancelling requests](/v0.1/docs/modules/agents/how_to/cancelling_requests/)
            *   [Custom LLM Agent](/v0.1/docs/modules/agents/how_to/custom_llm_agent/)
            *   [Custom LLM Agent (with a ChatModel)](/v0.1/docs/modules/agents/how_to/custom_llm_chat_agent/)
            *   [Custom MRKL agent](/v0.1/docs/modules/agents/how_to/custom_mrkl_agent/)
            *   [Handle parsing errors](/v0.1/docs/modules/agents/how_to/handle_parsing_errors/)
            *   [Access intermediate steps](/v0.1/docs/modules/agents/how_to/intermediate_steps/)
            *   [Logging and tracing](/v0.1/docs/modules/agents/how_to/logging_and_tracing/)
            *   [Cap the max number of iterations](/v0.1/docs/modules/agents/how_to/max_iterations/)
            *   [Streaming](/v0.1/docs/modules/agents/how_to/streaming/)
            *   [Timeouts for agents](/v0.1/docs/modules/agents/how_to/timeouts/)
        *   [Agents](/v0.1/docs/modules/agents/)
        *   [Tools](/v0.1/docs/modules/agents/tools/)
            
    *   [More](/v0.1/docs/modules/memory/)
        
*   [Security](/v0.1/docs/security/)
*   [Guides](/v0.1/docs/guides/)
    
*   [Ecosystem](/v0.1/docs/ecosystem/)
    
*   [LangGraph](/v0.1/docs/langgraph/)
*   * * *
    

*   [](/v0.1/)
*   [Modules](/v0.1/docs/modules/)
*   [Agents](/v0.1/docs/modules/agents/)
*   How-to
*   Streaming

On this page

Streaming
=========

Streaming is an important UX consideration for LLM apps, and agents are no exception. Streaming with agents is made more complicated by the fact that it’s not just tokens that you will want to stream, but you may also want to stream back the intermediate steps an agent takes.

Let’s take a look at how to do this.

Streaming intermediate steps[​](#streaming-intermediate-steps "Direct link to Streaming intermediate steps")
------------------------------------------------------------------------------------------------------------

Let’s look at how to stream intermediate steps. We can do this by using the default `.stream()` method on the AgentExecutor.

tip

See [this section for general instructions on installing integration packages](/v0.1/docs/get_started/installation/#installing-integration-packages).

*   npm
*   Yarn
*   pnpm

    npm install @langchain/openai

    yarn add @langchain/openai

    pnpm add @langchain/openai

    import { TavilySearchResults } from "@langchain/community/tools/tavily_search";import { ChatOpenAI } from "@langchain/openai";import type { ChatPromptTemplate } from "@langchain/core/prompts";import { Calculator } from "@langchain/community/tools/calculator";import { pull } from "langchain/hub";import { AgentExecutor, createOpenAIFunctionsAgent } from "langchain/agents";// Define the tools the agent will have access to.const tools = [new TavilySearchResults({}), new Calculator()];const llm = new ChatOpenAI({  model: "gpt-3.5-turbo-1106",  temperature: 0,});// Get the prompt to use - you can modify this!// If you want to see the prompt in full, you can at:// https://smith.langchain.com/hub/hwchase17/openai-functions-agentconst prompt = await pull<ChatPromptTemplate>(  "hwchase17/openai-functions-agent");const agent = await createOpenAIFunctionsAgent({  llm,  tools,  prompt,});const agentExecutor = new AgentExecutor({  agent,  tools,});const stream = await agentExecutor.stream({  input: "what is the weather in SF and then LA",});for await (const chunk of stream) {  console.log(JSON.stringify(chunk, null, 2));  console.log("------");}/*  {    "intermediateSteps": [      {        "action": {          "tool": "tavily_search_results_json",          "toolInput": {            "input": "weather in San Francisco"          },          "log": "Invoking \"tavily_search_results_json\" with {\"input\":\"weather in San Francisco\"}\n",          "messageLog": [            {              "lc": 1,              "type": "constructor",              "id": [                "langchain_core",                "messages",                "AIMessage"              ],              "kwargs": {                "content": "",                "additional_kwargs": {                  "function_call": {                    "name": "tavily_search_results_json",                    "arguments": "{\"input\":\"weather in San Francisco\"}"                  }                }              }            }          ]        },        "observation": "[{\"title\":\"December 27, 2023 San Francisco Bay Area weather forecast - MSN\",\"url\":\"https://www.msn.com/en-us/weather/topstories/december-27-2023-san-francisco-bay-area-weather-forecast/vi-AA1m61SY\",\"content\":\"Struggling retailer's CEO blames 'lazy' workers KRON4 Meteorologist John Shrable has the latest update on the unsettled weather system moving in on Wednesday....\",\"score\":0.96286,\"raw_content\":null},{\"title\":\"Weather in December 2023 in San Francisco, California, USA\",\"url\":\"https://www.timeanddate.com/weather/@5391959/historic?month=12&year=2023\",\"content\":\"Currently: 52 °F. Broken clouds. (Weather station: San Francisco International Airport, USA). See more current weather Select month: December 2023 Weather in San Francisco — Graph °F Sun, Dec 17 Lo:55 6 pm Hi:57 4 Mon, Dec 18 Lo:54 12 am Hi:55 7 Lo:54 6 am Hi:55 10 Lo:57 12 pm Hi:64 9 Lo:63 6 pm Hi:64 14 Tue, Dec 19 Lo:61\",\"score\":0.95828,\"raw_content\":null},{\"title\":\"December 27, 2023 San Francisco Bay Area weather forecast - Yahoo News\",\"url\":\"https://news.yahoo.com/december-27-2023-san-francisco-132217865.html\",\"content\":\"Wed, December 27, 2023, 8:22 AM EST KRON4 Meteorologist John Shrable has the latest update on the unsettled weather system moving in on Wednesday....\",\"score\":0.90699,\"raw_content\":null},{\"title\":\"Weather in San Francisco in December 2023\",\"url\":\"https://world-weather.info/forecast/usa/san_francisco/december-2023/\",\"content\":\"Mon Tue Wed Thu Fri Sat 1 +59° +54° 2 +61° +55° 3 +63° +55° 4 +63° +55° 5 +64° +54° 6 +61° +54° 7 +59°\",\"score\":0.90409,\"raw_content\":null},{\"title\":\"San Francisco, CA Hourly Weather Forecast | Weather Underground\",\"url\":\"https://www.wunderground.com/hourly/us/ca/san-francisco/date/2023-12-27\",\"content\":\"Wednesday Night 12/27. 57 % / 0.09 in. Considerable cloudiness with occasional rain showers. Low 54F. Winds SSE at 5 to 10 mph. Chance of rain 60%.\",\"score\":0.90221,\"raw_content\":null}]"      }    ]  }  ------  {    "intermediateSteps": [      {        "action": {          "tool": "tavily_search_results_json",          "toolInput": {            "input": "weather in Los Angeles"          },          "log": "Invoking \"tavily_search_results_json\" with {\"input\":\"weather in Los Angeles\"}\n",          "messageLog": [            {              "lc": 1,              "type": "constructor",              "id": [                "langchain_core",                "messages",                "AIMessage"              ],              "kwargs": {                "content": "",                "additional_kwargs": {                  "function_call": {                    "name": "tavily_search_results_json",                    "arguments": "{\"input\":\"weather in Los Angeles\"}"                  }                }              }            }          ]        },        "observation": "[{\"title\":\"Los Angeles, CA Hourly Weather Forecast | Weather Underground\",\"url\":\"https://www.wunderground.com/hourly/us/ca/los-angeles/date/2023-12-22\",\"content\":\"Hourly Forecast for Friday 12/22 Friday 12/22 67 % / 0.09 in Rain showers early with some sunshine later in the day. High 64F. Winds light and variable. Chance of rain 70%. Friday Night 12/22...\",\"score\":0.97854,\"raw_content\":null},{\"title\":\"Weather in December 2023 in Los Angeles, California, USA - timeanddate.com\",\"url\":\"https://www.timeanddate.com/weather/usa/los-angeles/historic?month=12&year=2023\",\"content\":\"Currently: 61 °F. Clear. (Weather station: Los Angeles / USC Campus Downtown, USA). See more current weather Select month: December 2023 Weather in Los Angeles — Graph °F Sun, Dec 10 Lo:59 6 pm Hi:61 1 Mon, Dec 11 Lo:54 12 am Hi:59 2 Lo:52 6 am Hi:72 1 Lo:63 12 pm Hi:73 0 Lo:54 6 pm Hi:59 0 Tue, Dec 12 Lo:50\",\"score\":0.92493,\"raw_content\":null},{\"title\":\"Los Angeles, California December 2023 Weather Forecast - detailed\",\"url\":\"https://www.weathertab.com/en/g/o/12/united-states/california/los-angeles/\",\"content\":\"Free Long Range Weather Forecast for Los Angeles, California December 2023. Detailed graphs of monthly weather forecast, temperatures, and degree days. Enter any city, zip or place. °F °C. Help. United States ... Helping You Avoid Bad Weather. 30 days and beyond. Daily Forecast Daily;\",\"score\":0.91283,\"raw_content\":null},{\"title\":\"Weather in Los Angeles in December 2023\",\"url\":\"https://world-weather.info/forecast/usa/los_angeles/december-2023/\",\"content\":\"Los Angeles Weather Forecast for December 2023 is based on long term prognosis and previous years' statistical data. 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec December Start Week On Sunday Monday Sun Mon Tue Wed Thu Fri Sat 1 +66° +54° 2 +66° +52° 3 +66° +52° 4 +72° +55° 5 +77° +57° 6 +70°\",\"score\":0.91028,\"raw_content\":null},{\"title\":\"Los Angeles, California Long Range Weather Forecast\",\"url\":\"https://www.weathertab.com/en/c/2023/12/united-states/california/los-angeles/\",\"content\":\"United States Los Angeles, California Long Range Weather Forecast Helping You Avoid Bad Weather. 30 days and beyond. Daily ForecastDaily Calendar ForecastCalendar Detailed ForecastDetail December 2023Dec 2023\",\"score\":0.90321,\"raw_content\":null}]"      }    ]  }  ------  {    "output": "The current weather in San Francisco is 52°F with broken clouds. You can find more details about the weather forecast for San Francisco [here](https://www.timeanddate.com/weather/@5391959/historic?month=12&year=2023).\n\nThe current weather in Los Angeles is 61°F with clear skies. You can find more details about the weather forecast for Los Angeles [here](https://www.timeanddate.com/weather/usa/los-angeles/historic?month=12&year=2023)."  }  ------*/

#### API Reference:

*   [TavilySearchResults](https://api.js.langchain.com/classes/langchain_community_tools_tavily_search.TavilySearchResults.html) from `@langchain/community/tools/tavily_search`
*   [ChatOpenAI](https://api.js.langchain.com/classes/langchain_openai.ChatOpenAI.html) from `@langchain/openai`
*   [ChatPromptTemplate](https://api.js.langchain.com/classes/langchain_core_prompts.ChatPromptTemplate.html) from `@langchain/core/prompts`
*   [Calculator](https://api.js.langchain.com/classes/langchain_community_tools_calculator.Calculator.html) from `@langchain/community/tools/calculator`
*   [pull](https://api.js.langchain.com/functions/langchain_hub.pull.html) from `langchain/hub`
*   [AgentExecutor](https://api.js.langchain.com/classes/langchain_agents.AgentExecutor.html) from `langchain/agents`
*   [createOpenAIFunctionsAgent](https://api.js.langchain.com/functions/langchain_agents.createOpenAIFunctionsAgent.html) from `langchain/agents`

You can see that we get back a bunch of different information. There are two ways to work with this information:

1.  By using the AgentAction or observation directly
2.  By using the messages object

Custom streaming with events[​](#custom-streaming-with-events "Direct link to Custom streaming with events")
------------------------------------------------------------------------------------------------------------

Use the `streamEvents` API in case the default behavior of stream does not work for your application (e.g., if you need to stream individual tokens from the agent or surface steps occuring within tools).

danger

This is a beta API, meaning that some details might change slightly in the future based on usage. You can pass a `version` parameter to tweak the behavior.

Let’s use this API to stream the following events:

1.  Agent Start with inputs
2.  Tool Start with inputs
3.  Tool End with outputs
4.  Stream the agent final anwer token by token
5.  Agent End with outputs

    import { TavilySearchResults } from "@langchain/community/tools/tavily_search";import { ChatOpenAI } from "@langchain/openai";import type { ChatPromptTemplate } from "@langchain/core/prompts";import { pull } from "langchain/hub";import { AgentExecutor, createOpenAIFunctionsAgent } from "langchain/agents";// Define the tools the agent will have access to.const tools = [new TavilySearchResults({})];const llm = new ChatOpenAI({  model: "gpt-3.5-turbo-1106",  temperature: 0,  streaming: true,});// Get the prompt to use - you can modify this!// If you want to see the prompt in full, you can at:// https://smith.langchain.com/hub/hwchase17/openai-functions-agentconst prompt = await pull<ChatPromptTemplate>(  "hwchase17/openai-functions-agent");const agent = await createOpenAIFunctionsAgent({  llm,  tools,  prompt,});const agentExecutor = new AgentExecutor({  agent,  tools,}).withConfig({ runName: "Agent" });const eventStream = await agentExecutor.streamEvents(  {    input: "what is the weather in SF",  },  { version: "v1" });for await (const event of eventStream) {  const eventType = event.event;  if (eventType === "on_chain_start") {    // Was assigned when creating the agent with `.withConfig({"runName": "Agent"})` above    if (event.name === "Agent") {      console.log("\n-----");      console.log(        `Starting agent: ${event.name} with input: ${JSON.stringify(          event.data.input        )}`      );    }  } else if (eventType === "on_chain_end") {    // Was assigned when creating the agent with `.withConfig({"runName": "Agent"})` above    if (event.name === "Agent") {      console.log("\n-----");      console.log(`Finished agent: ${event.name}\n`);      console.log(`Agent output was: ${event.data.output}`);      console.log("\n-----");    }  } else if (eventType === "on_llm_stream") {    const content = event.data?.chunk?.message?.content;    // Empty content in the context of OpenAI means    // that the model is asking for a tool to be invoked via function call.    // So we only print non-empty content    if (content !== undefined && content !== "") {      console.log(`| ${content}`);    }  } else if (eventType === "on_tool_start") {    console.log("\n-----");    console.log(      `Starting tool: ${event.name} with inputs: ${event.data.input}`    );  } else if (eventType === "on_tool_end") {    console.log("\n-----");    console.log(`Finished tool: ${event.name}\n`);    console.log(`Tool output was: ${event.data.output}`);    console.log("\n-----");  }}

#### API Reference:

*   [TavilySearchResults](https://api.js.langchain.com/classes/langchain_community_tools_tavily_search.TavilySearchResults.html) from `@langchain/community/tools/tavily_search`
*   [ChatOpenAI](https://api.js.langchain.com/classes/langchain_openai.ChatOpenAI.html) from `@langchain/openai`
*   [ChatPromptTemplate](https://api.js.langchain.com/classes/langchain_core_prompts.ChatPromptTemplate.html) from `@langchain/core/prompts`
*   [pull](https://api.js.langchain.com/functions/langchain_hub.pull.html) from `langchain/hub`
*   [AgentExecutor](https://api.js.langchain.com/classes/langchain_agents.AgentExecutor.html) from `langchain/agents`
*   [createOpenAIFunctionsAgent](https://api.js.langchain.com/functions/langchain_agents.createOpenAIFunctionsAgent.html) from `langchain/agents`

    -----Starting agent: Agent with input: {"input":"what is the weather in SF"}-----Starting tool: TavilySearchResults with inputs: weather in San Francisco-----Finished tool: TavilySearchResultsTool output was: [{"title":"Weather in San Francisco","url":"https://www.weatherapi.com/","content":"Weather in San Francisco is {'location': {'name': 'San Francisco', 'region': 'California', 'country': 'United States of America', 'lat': 37.78, 'lon': -122.42, 'tz_id': 'America/Los_Angeles', 'localtime_epoch': 1707638479, 'localtime': '2024-02-11 0:01'}, 'current': {'last_updated_epoch': 1707638400, 'last_updated': '2024-02-11 00:00', 'temp_c': 11.1, 'temp_f': 52.0, 'is_day': 0, 'condition': {'text': 'Partly cloudy', 'icon': '//cdn.weatherapi.com/weather/64x64/night/116.png', 'code': 1003}, 'wind_mph': 9.4, 'wind_kph': 15.1, 'wind_degree': 270, 'wind_dir': 'W', 'pressure_mb': 1022.0, 'pressure_in': 30.18, 'precip_mm': 0.0, 'precip_in': 0.0, 'humidity': 83, 'cloud': 25, 'feelslike_c': 11.5, 'feelslike_f': 52.6, 'vis_km': 16.0, 'vis_miles': 9.0, 'uv': 1.0, 'gust_mph': 13.9, 'gust_kph': 22.3}}","score":0.98371,"raw_content":null},{"title":"San Francisco, California November 2024 Weather Forecast","url":"https://www.weathertab.com/en/c/e/11/united-states/california/san-francisco/","content":"Temperature Forecast Temperature Forecast Normal Avg High Temps 60 to 70 °F Avg Low Temps 45 to 55 °F Weather Forecast Legend WeatherTAB helps you plan activities on days with the least risk of rain. Our forecasts are not direct predictions of rain/snow. Not all risky days will have rain/snow.","score":0.9517,"raw_content":null},{"title":"Past Weather in San Francisco, California, USA — Yesterday or Further Back","url":"https://www.timeanddate.com/weather/usa/san-francisco/historic","content":"Past Weather in San Francisco, California, USA — Yesterday and Last 2 Weeks. Weather. Time Zone. DST Changes. Sun & Moon. Weather Today Weather Hourly 14 Day Forecast Yesterday/Past Weather Climate (Averages) Currently: 52 °F. Light rain. Overcast.","score":0.945,"raw_content":null},{"title":"San Francisco, California February 2024 Weather Forecast - detailed","url":"https://www.weathertab.com/en/g/e/02/united-states/california/san-francisco/","content":"Free Long Range Weather Forecast for San Francisco, California February 2024. Detailed graphs of monthly weather forecast, temperatures, and degree days.","score":0.92177,"raw_content":null},{"title":"San Francisco Weather in 2024 - extremeweatherwatch.com","url":"https://www.extremeweatherwatch.com/cities/san-francisco/year-2024","content":"Year: What's the hottest temperature in San Francisco so far this year? As of February 2, the highest temperature recorded in San Francisco, California in 2024 is 73 °F which happened on January 29. Highest Temperatures: All-Time By Year Highest Temperatures in San Francisco in 2024 What's the coldest temperature in San Francisco so far this year?","score":0.91598,"raw_content":null}]-----| The|  current|  weather|  in|  San|  Francisco|  is|  partly|  cloudy|  with|  a|  temperature|  of|| 52| .| 0| °F|  (| 11| .| 1| °C| ).|  The|  wind|  speed|  is|| 15| .| 1|  k| ph|  coming|  from|  the|  west| ,|  and|  the|  humidity|  is|  at|| 83| %.|  If|  you|  need|  more|  detailed|  information| ,|  you|  can|  visit|  [| Weather|  in|  San|  Francisco| ](| https| ://| www| .weather| api| .com| /| ).-----Finished agent: AgentAgent output was: The current weather in San Francisco is partly cloudy with a temperature of 52.0°F (11.1°C). The wind speed is 15.1 kph coming from the west, and the humidity is at 83%. If you need more detailed information, you can visit [Weather in San Francisco](https://www.weatherapi.com/).-----

Other approaches[​](#other-approaches "Direct link to Other approaches")
------------------------------------------------------------------------

### `streamLog`[​](#streamlog "Direct link to streamlog")

You can also use the astream\_log API. This API produces a granular log of all events that occur during execution. The log format is based on the [JSONPatch](https://jsonpatch.com/) standard. It’s granular, but requires effort to parse. For this reason, we created the `streamEvents` API as an easier alternative.

In addition to streaming the final result, you can also stream tokens from each individual step. This will require more complex parsing of the logs.

Note: You will also need to make sure you set the LLM to return streaming output to get the maximum amount of data possible.

    import { TavilySearchResults } from "@langchain/community/tools/tavily_search";import { ChatOpenAI } from "@langchain/openai";import type { ChatPromptTemplate } from "@langchain/core/prompts";import { pull } from "langchain/hub";import { AgentExecutor, createOpenAIFunctionsAgent } from "langchain/agents";// Define the tools the agent will have access to.const tools = [new TavilySearchResults({})];const llm = new ChatOpenAI({  model: "gpt-3.5-turbo-1106",  temperature: 0,  streaming: true,});// Get the prompt to use - you can modify this!// If you want to see the prompt in full, you can at:// https://smith.langchain.com/hub/hwchase17/openai-functions-agentconst prompt = await pull<ChatPromptTemplate>(  "hwchase17/openai-functions-agent");const agent = await createOpenAIFunctionsAgent({  llm,  tools,  prompt,});const agentExecutor = new AgentExecutor({  agent,  tools,});const logStream = await agentExecutor.streamLog({  input: "what is the weather in SF",});// You can optionally aggregate the final state using the .concat() method// as shown below.let finalState;for await (const chunk of logStream) {  if (!finalState) {    finalState = chunk;  } else {    finalState = finalState.concat(chunk);  }  console.log(JSON.stringify(chunk, null, 2));}/*  {    "ops": [      {        "op": "replace",        "path": "",        "value": {          "id": "b45fb674-f391-4976-a13a-93116c1299b3",          "streamed_output": [],          "logs": {}        }      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/RunnableAgent",        "value": {          "id": "347b79d7-28b1-4be4-8de4-a7a6f633b397",          "name": "RunnableAgent",          "type": "chain",          "tags": [],          "metadata": {},          "start_time": "2023-12-27T23:33:49.796Z",          "streamed_output_str": []        }      }    ]  }  ...  {    "ops": [      {        "op": "add",        "path": "/logs/RunnableAgent/final_output",        "value": {          "tool": "tavily_search_results_json",          "toolInput": {            "input": "weather in San Francisco"          },          "log": "Invoking \"tavily_search_results_json\" with {\"input\":\"weather in San Francisco\"}\n",          "messageLog": [            {              "lc": 1,              "type": "constructor",              "id": [                "langchain_core",                "messages",                "AIMessageChunk"              ],              "kwargs": {                "content": "",                "additional_kwargs": {                  "function_call": {                    "name": "tavily_search_results_json",                    "arguments": "{\"input\":\"weather in San Francisco\"}"                  }                }              }            }          ]        }      },      {        "op": "add",        "path": "/logs/RunnableAgent/end_time",        "value": "2023-12-27T23:33:51.902Z"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/TavilySearchResults",        "value": {          "id": "9ee31774-1a96-4d78-93c5-6aac11591667",          "name": "TavilySearchResults",          "type": "tool",          "tags": [],          "metadata": {},          "start_time": "2023-12-27T23:33:51.970Z",          "streamed_output_str": []        }      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/TavilySearchResults/final_output",        "value": {          "output": "[{\"title\":\"December 27, 2023 San Francisco Bay Area weather forecast - Yahoo News\",\"url\":\"https://news.yahoo.com/december-27-2023-san-francisco-132217865.html\",\"content\":\"Wed, December 27, 2023, 8:22 AM EST KRON4 Meteorologist John Shrable has the latest update on the unsettled weather system moving in on Wednesday....\",\"score\":0.9679,\"raw_content\":null},{\"title\":\"San Francisco, CA Hourly Weather Forecast | Weather Underground\",\"url\":\"https://www.wunderground.com/hourly/us/ca/san-francisco/date/2023-12-27\",\"content\":\"Hourly Forecast for Wednesday 12/27 Wednesday 12/27 80 % / 0.28 in Rain likely. High near 60F. Winds SSE at 10 to 20 mph. Chance of rain 80%. Rainfall near a quarter of an inch. Wednesday...\",\"score\":0.95315,\"raw_content\":null},{\"title\":\"December 27, 2023 San Francisco Bay Area weather forecast - MSN\",\"url\":\"https://www.msn.com/en-us/weather/topstories/december-27-2023-san-francisco-bay-area-weather-forecast/vi-AA1m61SY\",\"content\":\"Struggling retailer's CEO blames 'lazy' workers KRON4 Meteorologist John Shrable has the latest update on the unsettled weather system moving in on Wednesday....\",\"score\":0.94448,\"raw_content\":null},{\"title\":\"Weather in December 2023 in San Francisco, California, USA\",\"url\":\"https://www.timeanddate.com/weather/@5391959/historic?month=12&year=2023\",\"content\":\"Currently: 52 °F. Broken clouds. (Weather station: San Francisco International Airport, USA). See more current weather Select month: December 2023 Weather in San Francisco — Graph °F Sun, Dec 17 Lo:55 6 pm Hi:57 4 Mon, Dec 18 Lo:54 12 am Hi:55 7 Lo:54 6 am Hi:55 10 Lo:57 12 pm Hi:64 9 Lo:63 6 pm Hi:64 14 Tue, Dec 19 Lo:61\",\"score\":0.93301,\"raw_content\":null},{\"title\":\"Weather in San Francisco in December 2023\",\"url\":\"https://world-weather.info/forecast/usa/san_francisco/december-2023/\",\"content\":\"Mon Tue Wed Thu Fri Sat 1 +59° +54° 2 +61° +55° 3 +63° +55° 4 +63° +55° 5 +64° +54° 6 +61° +54° 7 +59°\",\"score\":0.91495,\"raw_content\":null}]"        }      },      {        "op": "add",        "path": "/logs/TavilySearchResults/end_time",        "value": "2023-12-27T23:33:53.615Z"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/streamed_output/-",        "value": {          "intermediateSteps": [            {              "action": {                "tool": "tavily_search_results_json",                "toolInput": {                  "input": "weather in San Francisco"                },                "log": "Invoking \"tavily_search_results_json\" with {\"input\":\"weather in San Francisco\"}\n",                "messageLog": [                  {                    "lc": 1,                    "type": "constructor",                    "id": [                      "langchain_core",                      "messages",                      "AIMessageChunk"                    ],                    "kwargs": {                      "content": "",                      "additional_kwargs": {                        "function_call": {                          "name": "tavily_search_results_json",                          "arguments": "{\"input\":\"weather in San Francisco\"}"                        }                      }                    }                  }                ]              },              "observation": "[{\"title\":\"December 27, 2023 San Francisco Bay Area weather forecast - Yahoo News\",\"url\":\"https://news.yahoo.com/december-27-2023-san-francisco-132217865.html\",\"content\":\"Wed, December 27, 2023, 8:22 AM EST KRON4 Meteorologist John Shrable has the latest update on the unsettled weather system moving in on Wednesday....\",\"score\":0.9679,\"raw_content\":null},{\"title\":\"San Francisco, CA Hourly Weather Forecast | Weather Underground\",\"url\":\"https://www.wunderground.com/hourly/us/ca/san-francisco/date/2023-12-27\",\"content\":\"Hourly Forecast for Wednesday 12/27 Wednesday 12/27 80 % / 0.28 in Rain likely. High near 60F. Winds SSE at 10 to 20 mph. Chance of rain 80%. Rainfall near a quarter of an inch. Wednesday...\",\"score\":0.95315,\"raw_content\":null},{\"title\":\"December 27, 2023 San Francisco Bay Area weather forecast - MSN\",\"url\":\"https://www.msn.com/en-us/weather/topstories/december-27-2023-san-francisco-bay-area-weather-forecast/vi-AA1m61SY\",\"content\":\"Struggling retailer's CEO blames 'lazy' workers KRON4 Meteorologist John Shrable has the latest update on the unsettled weather system moving in on Wednesday....\",\"score\":0.94448,\"raw_content\":null},{\"title\":\"Weather in December 2023 in San Francisco, California, USA\",\"url\":\"https://www.timeanddate.com/weather/@5391959/historic?month=12&year=2023\",\"content\":\"Currently: 52 °F. Broken clouds. (Weather station: San Francisco International Airport, USA). See more current weather Select month: December 2023 Weather in San Francisco — Graph °F Sun, Dec 17 Lo:55 6 pm Hi:57 4 Mon, Dec 18 Lo:54 12 am Hi:55 7 Lo:54 6 am Hi:55 10 Lo:57 12 pm Hi:64 9 Lo:63 6 pm Hi:64 14 Tue, Dec 19 Lo:61\",\"score\":0.93301,\"raw_content\":null},{\"title\":\"Weather in San Francisco in December 2023\",\"url\":\"https://world-weather.info/forecast/usa/san_francisco/december-2023/\",\"content\":\"Mon Tue Wed Thu Fri Sat 1 +59° +54° 2 +61° +55° 3 +63° +55° 4 +63° +55° 5 +64° +54° 6 +61° +54° 7 +59°\",\"score\":0.91495,\"raw_content\":null}]"            }          ]        }      }    ]  }  ...  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2",        "value": {          "id": "7c5a39b9-1b03-4291-95d1-a775edc92aee",          "name": "ChatOpenAI",          "type": "llm",          "tags": [            "seq:step:3"          ],          "metadata": {},          "start_time": "2023-12-27T23:33:54.180Z",          "streamed_output_str": []        }      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": ""      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": "The"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": " current"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": " weather"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": " in"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": " San"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": " Francisco"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": " is"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": " "      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": "52"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": "°F"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": " with"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": " broken"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": " clouds"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": "."      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": " There"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": " is"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": " also"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": " a"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": " forecast"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": " for"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": " rain"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": " likely"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": " with"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": " a"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": " high"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": " near"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": " "      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": "60"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": "°F"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": " and"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": " winds"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": " from"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": " the"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": " SSE"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": " at"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": " "      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": "10"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": " to"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": " "      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": "20"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": " mph"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": "."      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": " If"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": " you"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": "'d"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": " like"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": " more"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": " detailed"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": " information"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": ","      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": " you"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": " can"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": " visit"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": " the"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": " ["      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": "San"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": " Francisco"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": ","      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": " CA"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": " Hour"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": "ly"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": " Weather"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": " Forecast"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": "]("      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": "https"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": "://"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": "www"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": ".w"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": "under"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": "ground"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": ".com"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": "/h"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": "our"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": "ly"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": "/us"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": "/ca"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": "/s"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": "an"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": "-fr"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": "anc"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": "isco"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": "/date"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": "/"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": "202"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": "3"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": "-"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": "12"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": "-"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": "27"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": ")"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": " page"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": "."      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": ""      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/final_output",        "value": {          "generations": [            [              {                "text": "The current weather in San Francisco is 52°F with broken clouds. There is also a forecast for rain likely with a high near 60°F and winds from the SSE at 10 to 20 mph. If you'd like more detailed information, you can visit the [San Francisco, CA Hourly Weather Forecast](https://www.wunderground.com/hourly/us/ca/san-francisco/date/2023-12-27) page.",                "generationInfo": {                  "prompt": 0,                  "completion": 0                },                "message": {                  "lc": 1,                  "type": "constructor",                  "id": [                    "langchain_core",                    "messages",                    "AIMessageChunk"                  ],                  "kwargs": {                    "content": "The current weather in San Francisco is 52°F with broken clouds. There is also a forecast for rain likely with a high near 60°F and winds from the SSE at 10 to 20 mph. If you'd like more detailed information, you can visit the [San Francisco, CA Hourly Weather Forecast](https://www.wunderground.com/hourly/us/ca/san-francisco/date/2023-12-27) page.",                    "additional_kwargs": {}                  }                }              }            ]          ],          "llmOutput": {            "estimatedTokenUsage": {              "promptTokens": 720,              "completionTokens": 92,              "totalTokens": 812            }          }        }      },      {        "op": "add",        "path": "/logs/ChatOpenAI:2/end_time",        "value": "2023-12-27T23:33:55.577Z"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/OpenAIFunctionsAgentOutputParser:2",        "value": {          "id": "f58ff4e4-2e65-4dde-8a36-ba188e9eabc7",          "name": "OpenAIFunctionsAgentOutputParser",          "type": "parser",          "tags": [            "seq:step:4"          ],          "metadata": {},          "start_time": "2023-12-27T23:33:55.742Z",          "streamed_output_str": []        }      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/OpenAIFunctionsAgentOutputParser:2/final_output",        "value": {          "returnValues": {            "output": "The current weather in San Francisco is 52°F with broken clouds. There is also a forecast for rain likely with a high near 60°F and winds from the SSE at 10 to 20 mph. If you'd like more detailed information, you can visit the [San Francisco, CA Hourly Weather Forecast](https://www.wunderground.com/hourly/us/ca/san-francisco/date/2023-12-27) page."          },          "log": "The current weather in San Francisco is 52°F with broken clouds. There is also a forecast for rain likely with a high near 60°F and winds from the SSE at 10 to 20 mph. If you'd like more detailed information, you can visit the [San Francisco, CA Hourly Weather Forecast](https://www.wunderground.com/hourly/us/ca/san-francisco/date/2023-12-27) page."        }      },      {        "op": "add",        "path": "/logs/OpenAIFunctionsAgentOutputParser:2/end_time",        "value": "2023-12-27T23:33:55.812Z"      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/logs/RunnableAgent:2/final_output",        "value": {          "returnValues": {            "output": "The current weather in San Francisco is 52°F with broken clouds. There is also a forecast for rain likely with a high near 60°F and winds from the SSE at 10 to 20 mph. If you'd like more detailed information, you can visit the [San Francisco, CA Hourly Weather Forecast](https://www.wunderground.com/hourly/us/ca/san-francisco/date/2023-12-27) page."          },          "log": "The current weather in San Francisco is 52°F with broken clouds. There is also a forecast for rain likely with a high near 60°F and winds from the SSE at 10 to 20 mph. If you'd like more detailed information, you can visit the [San Francisco, CA Hourly Weather Forecast](https://www.wunderground.com/hourly/us/ca/san-francisco/date/2023-12-27) page."        }      },      {        "op": "add",        "path": "/logs/RunnableAgent:2/end_time",        "value": "2023-12-27T23:33:55.872Z"      }    ]  }  {    "ops": [      {        "op": "replace",        "path": "/final_output",        "value": {          "output": "The current weather in San Francisco is 52°F with broken clouds. There is also a forecast for rain likely with a high near 60°F and winds from the SSE at 10 to 20 mph. If you'd like more detailed information, you can visit the [San Francisco, CA Hourly Weather Forecast](https://www.wunderground.com/hourly/us/ca/san-francisco/date/2023-12-27) page."        }      }    ]  }  {    "ops": [      {        "op": "add",        "path": "/streamed_output/-",        "value": {          "output": "The current weather in San Francisco is 52°F with broken clouds. There is also a forecast for rain likely with a high near 60°F and winds from the SSE at 10 to 20 mph. If you'd like more detailed information, you can visit the [San Francisco, CA Hourly Weather Forecast](https://www.wunderground.com/hourly/us/ca/san-francisco/date/2023-12-27) page."        }      }    ]  }*/

#### API Reference:

*   [TavilySearchResults](https://api.js.langchain.com/classes/langchain_community_tools_tavily_search.TavilySearchResults.html) from `@langchain/community/tools/tavily_search`
*   [ChatOpenAI](https://api.js.langchain.com/classes/langchain_openai.ChatOpenAI.html) from `@langchain/openai`
*   [ChatPromptTemplate](https://api.js.langchain.com/classes/langchain_core_prompts.ChatPromptTemplate.html) from `@langchain/core/prompts`
*   [pull](https://api.js.langchain.com/functions/langchain_hub.pull.html) from `langchain/hub`
*   [AgentExecutor](https://api.js.langchain.com/classes/langchain_agents.AgentExecutor.html) from `langchain/agents`
*   [createOpenAIFunctionsAgent](https://api.js.langchain.com/functions/langchain_agents.createOpenAIFunctionsAgent.html) from `langchain/agents`

With some creative parsing, this can be useful for e.g. streaming back just the final response from the agent:

    const logStream = await agentExecutor.streamLog({  input: "what is the weather in SF",});/*  Final streamed output from the OpenAI functions agent will look similar to the below chunk  since intermediate steps are streamed functions rather than strings:  {    "ops": [      {        "op": "add",        "path": "/logs/ChatOpenAI:2/streamed_output_str/-",        "value": "anc"      }    ]  }*/for await (const chunk of logStream) {  if (chunk.ops?.length > 0 && chunk.ops[0].op === "add") {    const addOp = chunk.ops[0];    if (      addOp.path.startsWith("/logs/ChatOpenAI") &&      typeof addOp.value === "string" &&      addOp.value.length    ) {      console.log(addOp.value);    }  }}/*  The  current  weather  in  San  Francisco  is    52  °F  with  broken  clouds  .  There  is  a  chance  of  rain  showers  with  a  low  of    54  °F  .  Winds  are  expected  to  be  from  the  SSE  at    5  to    10  mph  .  For  more  detailed  information  ,  you  can  visit  [  Weather  Underground  ](  https  ://  www  .w  under  ground  .com  /h  our  ly  /us  /ca  /s  an  -fr  anc  isco  /date  /  202  3  -  12  -  27  ).*/

* * *

#### Help us out by providing feedback on this documentation page:

[

Previous

Cap the max number of iterations

](/v0.1/docs/modules/agents/how_to/max_iterations/)[

Next

Timeouts for agents

](/v0.1/docs/modules/agents/how_to/timeouts/)

*   [Streaming intermediate steps](#streaming-intermediate-steps)
*   [Custom streaming with events](#custom-streaming-with-events)
*   [Other approaches](#other-approaches)
    *   [`streamLog`](#streamlog)

Community

*   [Discord](https://discord.gg/cU2adEyC7w)
*   [Twitter](https://twitter.com/LangChainAI)

GitHub

*   [Python](https://github.com/langchain-ai/langchain)
*   [JS/TS](https://github.com/langchain-ai/langchainjs)

More

*   [Homepage](https://langchain.com)
*   [Blog](https://blog.langchain.dev)

Copyright © 2024 LangChain, Inc.