Agents combine language models with tools to create systems that can reason about tasks, decide which tools to use, and iteratively work towards solutions. createAgent provides a production-ready ReAct (Reasoning + Acting) agent implementation based on the paper Synergizing Reasoning and Acting in Language Models.
import { createAgent, tool } from "langchain";
import { z } from "zod/v3";
const getWeather = tool((input) => {
if (["sf", "san francisco"].includes(input.location.toLowerCase())) {
return "It's 60 degrees and foggy.";
} else {
return "It's 90 degrees and sunny.";
}
}, {
name: "get_weather",
description: "Call to get the current weather.",
schema: z.object({
location: z.string().describe("Location to get the weather for."),
})
})
const agent = createAgent({
// use chat model from "@langchain/openai"
model: "openai:gpt-4o-mini",
tools: [getWeather]
});
const inputs = {
messages: [{ role: "user", content: "what is the weather in SF?" }],
};
const stream = await agent.stream(inputs, { streamMode: "values" });
for await (const { messages } of stream) {
console.log(messages);
}
// Returns the messages in the state at each step of execution
Agents combine language models with tools to create systems that can reason about tasks, decide which tools to use, and iteratively work towards solutions. createAgent provides a production-ready ReAct (Reasoning + Acting) agent implementation based on the paper Synergizing Reasoning and Acting in Language Models.
import { createAgent, tool } from "langchain";
import { z } from "zod/v3";
const getWeather = tool((input) => {
if (["sf", "san francisco"].includes(input.location.toLowerCase())) {
return "It's 60 degrees and foggy.";
} else {
return "It's 90 degrees and sunny.";
}
}, {
name: "get_weather",
description: "Call to get the current weather.",
schema: z.object({
location: z.string().describe("Location to get the weather for."),
})
})
const agent = createAgent({
// use chat model from "@langchain/openai"
model: "openai:gpt-4o-mini",
tools: [getWeather]
});
const inputs = {
messages: [{ role: "user", content: "what is the weather in SF?" }],
};
const stream = await agent.stream(inputs, { streamMode: "values" });
for await (const { messages } of stream) {
console.log(messages);
}
// Returns the messages in the state at each step of execution
Agents combine language models with tools to create systems that can reason about tasks, decide which tools to use, and iteratively work towards solutions. createAgent provides a production-ready ReAct (Reasoning + Acting) agent implementation based on the paper Synergizing Reasoning and Acting in Language Models.
import { createAgent, tool } from "langchain";
import { z } from "zod/v3";
const getWeather = tool((input) => {
if (["sf", "san francisco"].includes(input.location.toLowerCase())) {
return "It's 60 degrees and foggy.";
} else {
return "It's 90 degrees and sunny.";
}
}, {
name: "get_weather",
description: "Call to get the current weather.",
schema: z.object({
location: z.string().describe("Location to get the weather for."),
})
})
const agent = createAgent({
// use chat model from "@langchain/openai"
model: "openai:gpt-4o-mini",
tools: [getWeather]
});
const inputs = {
messages: [{ role: "user", content: "what is the weather in SF?" }],
};
const stream = await agent.stream(inputs, { streamMode: "values" });
for await (const { messages } of stream) {
console.log(messages);
}
// Returns the messages in the state at each step of execution
Agents combine language models with tools to create systems that can reason about tasks, decide which tools to use, and iteratively work towards solutions. createAgent provides a production-ready ReAct (Reasoning + Acting) agent implementation based on the paper Synergizing Reasoning and Acting in Language Models.
import { createAgent, tool } from "langchain";
import { z } from "zod/v3";
const getWeather = tool((input) => {
if (["sf", "san francisco"].includes(input.location.toLowerCase())) {
return "It's 60 degrees and foggy.";
} else {
return "It's 90 degrees and sunny.";
}
}, {
name: "get_weather",
description: "Call to get the current weather.",
schema: z.object({
location: z.string().describe("Location to get the weather for."),
})
})
const agent = createAgent({
// use chat model from "@langchain/openai"
model: "openai:gpt-4o-mini",
tools: [getWeather]
});
const inputs = {
messages: [{ role: "user", content: "what is the weather in SF?" }],
};
const stream = await agent.stream(inputs, { streamMode: "values" });
for await (const { messages } of stream) {
console.log(messages);
}
// Returns the messages in the state at each step of execution
Agents combine language models with tools to create systems that can reason about tasks, decide which tools to use, and iteratively work towards solutions. createAgent provides a production-ready ReAct (Reasoning + Acting) agent implementation based on the paper Synergizing Reasoning and Acting in Language Models.
import { createAgent, tool } from "langchain";
import { z } from "zod/v3";
const getWeather = tool((input) => {
if (["sf", "san francisco"].includes(input.location.toLowerCase())) {
return "It's 60 degrees and foggy.";
} else {
return "It's 90 degrees and sunny.";
}
}, {
name: "get_weather",
description: "Call to get the current weather.",
schema: z.object({
location: z.string().describe("Location to get the weather for."),
})
})
const agent = createAgent({
// use chat model from "@langchain/openai"
model: "openai:gpt-4o-mini",
tools: [getWeather]
});
const inputs = {
messages: [{ role: "user", content: "what is the weather in SF?" }],
};
const stream = await agent.stream(inputs, { streamMode: "values" });
for await (const { messages } of stream) {
console.log(messages);
}
// Returns the messages in the state at each step of execution
Agents combine language models with tools to create systems that can reason about tasks, decide which tools to use, and iteratively work towards solutions. createAgent provides a production-ready ReAct (Reasoning + Acting) agent implementation based on the paper Synergizing Reasoning and Acting in Language Models.
import { createAgent, tool } from "langchain";
import { z } from "zod/v3";
const getWeather = tool((input) => {
if (["sf", "san francisco"].includes(input.location.toLowerCase())) {
return "It's 60 degrees and foggy.";
} else {
return "It's 90 degrees and sunny.";
}
}, {
name: "get_weather",
description: "Call to get the current weather.",
schema: z.object({
location: z.string().describe("Location to get the weather for."),
})
})
const agent = createAgent({
// use chat model from "@langchain/openai"
model: "openai:gpt-4o-mini",
tools: [getWeather]
});
const inputs = {
messages: [{ role: "user", content: "what is the weather in SF?" }],
};
const stream = await agent.stream(inputs, { streamMode: "values" });
for await (const { messages } of stream) {
console.log(messages);
}
// Returns the messages in the state at each step of execution
Agents combine language models with tools to create systems that can reason about tasks, decide which tools to use, and iteratively work towards solutions. createAgent provides a production-ready ReAct (Reasoning + Acting) agent implementation based on the paper Synergizing Reasoning and Acting in Language Models.
import { createAgent, tool } from "langchain";
import { z } from "zod/v3";
const getWeather = tool((input) => {
if (["sf", "san francisco"].includes(input.location.toLowerCase())) {
return "It's 60 degrees and foggy.";
} else {
return "It's 90 degrees and sunny.";
}
}, {
name: "get_weather",
description: "Call to get the current weather.",
schema: z.object({
location: z.string().describe("Location to get the weather for."),
})
})
const agent = createAgent({
// use chat model from "@langchain/openai"
model: "openai:gpt-4o-mini",
tools: [getWeather]
});
const inputs = {
messages: [{ role: "user", content: "what is the weather in SF?" }],
};
const stream = await agent.stream(inputs, { streamMode: "values" });
for await (const { messages } of stream) {
console.log(messages);
}
// Returns the messages in the state at each step of execution
Agents combine language models with tools to create systems that can reason about tasks, decide which tools to use, and iteratively work towards solutions. createAgent provides a production-ready ReAct (Reasoning + Acting) agent implementation based on the paper Synergizing Reasoning and Acting in Language Models.
import { createAgent, tool } from "langchain";
import { z } from "zod/v3";
const getWeather = tool((input) => {
if (["sf", "san francisco"].includes(input.location.toLowerCase())) {
return "It's 60 degrees and foggy.";
} else {
return "It's 90 degrees and sunny.";
}
}, {
name: "get_weather",
description: "Call to get the current weather.",
schema: z.object({
location: z.string().describe("Location to get the weather for."),
})
})
const agent = createAgent({
// use chat model from "@langchain/openai"
model: "openai:gpt-4o-mini",
tools: [getWeather]
});
const inputs = {
messages: [{ role: "user", content: "what is the weather in SF?" }],
};
const stream = await agent.stream(inputs, { streamMode: "values" });
for await (const { messages } of stream) {
console.log(messages);
}
// Returns the messages in the state at each step of execution
Agents combine language models with tools to create systems that can reason about tasks, decide which tools to use, and iteratively work towards solutions. createAgent provides a production-ready ReAct (Reasoning + Acting) agent implementation based on the paper Synergizing Reasoning and Acting in Language Models.
import { createAgent, tool } from "langchain";
import { z } from "zod/v3";
const getWeather = tool((input) => {
if (["sf", "san francisco"].includes(input.location.toLowerCase())) {
return "It's 60 degrees and foggy.";
} else {
return "It's 90 degrees and sunny.";
}
}, {
name: "get_weather",
description: "Call to get the current weather.",
schema: z.object({
location: z.string().describe("Location to get the weather for."),
})
})
const agent = createAgent({
// use chat model from "@langchain/openai"
model: "openai:gpt-4o-mini",
tools: [getWeather]
});
const inputs = {
messages: [{ role: "user", content: "what is the weather in SF?" }],
};
const stream = await agent.stream(inputs, { streamMode: "values" });
for await (const { messages } of stream) {
console.log(messages);
}
// Returns the messages in the state at each step of execution
Agents combine language models with tools to create systems that can reason about tasks, decide which tools to use, and iteratively work towards solutions. createAgent provides a production-ready ReAct (Reasoning + Acting) agent implementation based on the paper Synergizing Reasoning and Acting in Language Models.
import { createAgent, tool } from "langchain";
import { z } from "zod/v3";
const getWeather = tool((input) => {
if (["sf", "san francisco"].includes(input.location.toLowerCase())) {
return "It's 60 degrees and foggy.";
} else {
return "It's 90 degrees and sunny.";
}
}, {
name: "get_weather",
description: "Call to get the current weather.",
schema: z.object({
location: z.string().describe("Location to get the weather for."),
})
})
const agent = createAgent({
// use chat model from "@langchain/openai"
model: "openai:gpt-4o-mini",
tools: [getWeather]
});
const inputs = {
messages: [{ role: "user", content: "what is the weather in SF?" }],
};
const stream = await agent.stream(inputs, { streamMode: "values" });
for await (const { messages } of stream) {
console.log(messages);
}
// Returns the messages in the state at each step of execution
Agents combine language models with tools to create systems that can reason about tasks, decide which tools to use, and iteratively work towards solutions. createAgent provides a production-ready ReAct (Reasoning + Acting) agent implementation based on the paper Synergizing Reasoning and Acting in Language Models.
import { createAgent, tool } from "langchain";
import { z } from "zod/v3";
const getWeather = tool((input) => {
if (["sf", "san francisco"].includes(input.location.toLowerCase())) {
return "It's 60 degrees and foggy.";
} else {
return "It's 90 degrees and sunny.";
}
}, {
name: "get_weather",
description: "Call to get the current weather.",
schema: z.object({
location: z.string().describe("Location to get the weather for."),
})
})
const agent = createAgent({
// use chat model from "@langchain/openai"
model: "openai:gpt-4o-mini",
tools: [getWeather]
});
const inputs = {
messages: [{ role: "user", content: "what is the weather in SF?" }],
};
const stream = await agent.stream(inputs, { streamMode: "values" });
for await (const { messages } of stream) {
console.log(messages);
}
// Returns the messages in the state at each step of execution
Agents combine language models with tools to create systems that can reason about tasks, decide which tools to use, and iteratively work towards solutions. createAgent provides a production-ready ReAct (Reasoning + Acting) agent implementation based on the paper Synergizing Reasoning and Acting in Language Models.
import { createAgent, tool } from "langchain";
import { z } from "zod/v3";
const getWeather = tool((input) => {
if (["sf", "san francisco"].includes(input.location.toLowerCase())) {
return "It's 60 degrees and foggy.";
} else {
return "It's 90 degrees and sunny.";
}
}, {
name: "get_weather",
description: "Call to get the current weather.",
schema: z.object({
location: z.string().describe("Location to get the weather for."),
})
})
const agent = createAgent({
// use chat model from "@langchain/openai"
model: "openai:gpt-4o-mini",
tools: [getWeather]
});
const inputs = {
messages: [{ role: "user", content: "what is the weather in SF?" }],
};
const stream = await agent.stream(inputs, { streamMode: "values" });
for await (const { messages } of stream) {
console.log(messages);
}
// Returns the messages in the state at each step of execution
Agents combine language models with tools to create systems that can reason about tasks, decide which tools to use, and iteratively work towards solutions. createAgent provides a production-ready ReAct (Reasoning + Acting) agent implementation based on the paper Synergizing Reasoning and Acting in Language Models.
import { createAgent, tool } from "langchain";
import { z } from "zod/v3";
const getWeather = tool((input) => {
if (["sf", "san francisco"].includes(input.location.toLowerCase())) {
return "It's 60 degrees and foggy.";
} else {
return "It's 90 degrees and sunny.";
}
}, {
name: "get_weather",
description: "Call to get the current weather.",
schema: z.object({
location: z.string().describe("Location to get the weather for."),
})
})
const agent = createAgent({
// use chat model from "@langchain/openai"
model: "openai:gpt-4o-mini",
tools: [getWeather]
});
const inputs = {
messages: [{ role: "user", content: "what is the weather in SF?" }],
};
const stream = await agent.stream(inputs, { streamMode: "values" });
for await (const { messages } of stream) {
console.log(messages);
}
// Returns the messages in the state at each step of execution
Agents combine language models with tools to create systems that can reason about tasks, decide which tools to use, and iteratively work towards solutions. createAgent provides a production-ready ReAct (Reasoning + Acting) agent implementation based on the paper Synergizing Reasoning and Acting in Language Models.
import { createAgent, tool } from "langchain";
import { z } from "zod/v3";
const getWeather = tool((input) => {
if (["sf", "san francisco"].includes(input.location.toLowerCase())) {
return "It's 60 degrees and foggy.";
} else {
return "It's 90 degrees and sunny.";
}
}, {
name: "get_weather",
description: "Call to get the current weather.",
schema: z.object({
location: z.string().describe("Location to get the weather for."),
})
})
const agent = createAgent({
// use chat model from "@langchain/openai"
model: "openai:gpt-4o-mini",
tools: [getWeather]
});
const inputs = {
messages: [{ role: "user", content: "what is the weather in SF?" }],
};
const stream = await agent.stream(inputs, { streamMode: "values" });
for await (const { messages } of stream) {
console.log(messages);
}
// Returns the messages in the state at each step of execution
Agents combine language models with tools to create systems that can reason about tasks, decide which tools to use, and iteratively work towards solutions. createAgent provides a production-ready ReAct (Reasoning + Acting) agent implementation based on the paper Synergizing Reasoning and Acting in Language Models.
import { createAgent, tool } from "langchain";
import { z } from "zod/v3";
const getWeather = tool((input) => {
if (["sf", "san francisco"].includes(input.location.toLowerCase())) {
return "It's 60 degrees and foggy.";
} else {
return "It's 90 degrees and sunny.";
}
}, {
name: "get_weather",
description: "Call to get the current weather.",
schema: z.object({
location: z.string().describe("Location to get the weather for."),
})
})
const agent = createAgent({
// use chat model from "@langchain/openai"
model: "openai:gpt-4o-mini",
tools: [getWeather]
});
const inputs = {
messages: [{ role: "user", content: "what is the weather in SF?" }],
};
const stream = await agent.stream(inputs, { streamMode: "values" });
for await (const { messages } of stream) {
console.log(messages);
}
// Returns the messages in the state at each step of execution
Agents combine language models with tools to create systems that can reason about tasks, decide which tools to use, and iteratively work towards solutions. createAgent provides a production-ready ReAct (Reasoning + Acting) agent implementation based on the paper Synergizing Reasoning and Acting in Language Models.
import { createAgent, tool } from "langchain";
import { z } from "zod/v3";
const getWeather = tool((input) => {
if (["sf", "san francisco"].includes(input.location.toLowerCase())) {
return "It's 60 degrees and foggy.";
} else {
return "It's 90 degrees and sunny.";
}
}, {
name: "get_weather",
description: "Call to get the current weather.",
schema: z.object({
location: z.string().describe("Location to get the weather for."),
})
})
const agent = createAgent({
// use chat model from "@langchain/openai"
model: "openai:gpt-4o-mini",
tools: [getWeather]
});
const inputs = {
messages: [{ role: "user", content: "what is the weather in SF?" }],
};
const stream = await agent.stream(inputs, { streamMode: "values" });
for await (const { messages } of stream) {
console.log(messages);
}
// Returns the messages in the state at each step of execution
Agents combine language models with tools to create systems that can reason about tasks, decide which tools to use, and iteratively work towards solutions. createAgent provides a production-ready ReAct (Reasoning + Acting) agent implementation based on the paper Synergizing Reasoning and Acting in Language Models.
import { createAgent, tool } from "langchain";
import { z } from "zod/v3";
const getWeather = tool((input) => {
if (["sf", "san francisco"].includes(input.location.toLowerCase())) {
return "It's 60 degrees and foggy.";
} else {
return "It's 90 degrees and sunny.";
}
}, {
name: "get_weather",
description: "Call to get the current weather.",
schema: z.object({
location: z.string().describe("Location to get the weather for."),
})
})
const agent = createAgent({
// use chat model from "@langchain/openai"
model: "openai:gpt-4o-mini",
tools: [getWeather]
});
const inputs = {
messages: [{ role: "user", content: "what is the weather in SF?" }],
};
const stream = await agent.stream(inputs, { streamMode: "values" });
for await (const { messages } of stream) {
console.log(messages);
}
// Returns the messages in the state at each step of execution
Agents combine language models with tools to create systems that can reason about tasks, decide which tools to use, and iteratively work towards solutions. createAgent provides a production-ready ReAct (Reasoning + Acting) agent implementation based on the paper Synergizing Reasoning and Acting in Language Models.
import { createAgent, tool } from "langchain";
import { z } from "zod/v3";
const getWeather = tool((input) => {
if (["sf", "san francisco"].includes(input.location.toLowerCase())) {
return "It's 60 degrees and foggy.";
} else {
return "It's 90 degrees and sunny.";
}
}, {
name: "get_weather",
description: "Call to get the current weather.",
schema: z.object({
location: z.string().describe("Location to get the weather for."),
})
})
const agent = createAgent({
// use chat model from "@langchain/openai"
model: "openai:gpt-4o-mini",
tools: [getWeather]
});
const inputs = {
messages: [{ role: "user", content: "what is the weather in SF?" }],
};
const stream = await agent.stream(inputs, { streamMode: "values" });
for await (const { messages } of stream) {
console.log(messages);
}
// Returns the messages in the state at each step of execution
Agents combine language models with tools to create systems that can reason about tasks, decide which tools to use, and iteratively work towards solutions. createAgent provides a production-ready ReAct (Reasoning + Acting) agent implementation based on the paper Synergizing Reasoning and Acting in Language Models.
import { createAgent, tool } from "langchain";
import { z } from "zod/v3";
const getWeather = tool((input) => {
if (["sf", "san francisco"].includes(input.location.toLowerCase())) {
return "It's 60 degrees and foggy.";
} else {
return "It's 90 degrees and sunny.";
}
}, {
name: "get_weather",
description: "Call to get the current weather.",
schema: z.object({
location: z.string().describe("Location to get the weather for."),
})
})
const agent = createAgent({
// use chat model from "@langchain/openai"
model: "openai:gpt-4o-mini",
tools: [getWeather]
});
const inputs = {
messages: [{ role: "user", content: "what is the weather in SF?" }],
};
const stream = await agent.stream(inputs, { streamMode: "values" });
for await (const { messages } of stream) {
console.log(messages);
}
// Returns the messages in the state at each step of execution
Agents combine language models with tools to create systems that can reason about tasks, decide which tools to use, and iteratively work towards solutions. createAgent provides a production-ready ReAct (Reasoning + Acting) agent implementation based on the paper Synergizing Reasoning and Acting in Language Models.
import { createAgent, tool } from "langchain";
import { z } from "zod/v3";
const getWeather = tool((input) => {
if (["sf", "san francisco"].includes(input.location.toLowerCase())) {
return "It's 60 degrees and foggy.";
} else {
return "It's 90 degrees and sunny.";
}
}, {
name: "get_weather",
description: "Call to get the current weather.",
schema: z.object({
location: z.string().describe("Location to get the weather for."),
})
})
const agent = createAgent({
// use chat model from "@langchain/openai"
model: "openai:gpt-4o-mini",
tools: [getWeather]
});
const inputs = {
messages: [{ role: "user", content: "what is the weather in SF?" }],
};
const stream = await agent.stream(inputs, { streamMode: "values" });
for await (const { messages } of stream) {
console.log(messages);
}
// Returns the messages in the state at each step of execution
Agents combine language models with tools to create systems that can reason about tasks, decide which tools to use, and iteratively work towards solutions. createAgent provides a production-ready ReAct (Reasoning + Acting) agent implementation based on the paper Synergizing Reasoning and Acting in Language Models.
import { createAgent, tool } from "langchain";
import { z } from "zod/v3";
const getWeather = tool((input) => {
if (["sf", "san francisco"].includes(input.location.toLowerCase())) {
return "It's 60 degrees and foggy.";
} else {
return "It's 90 degrees and sunny.";
}
}, {
name: "get_weather",
description: "Call to get the current weather.",
schema: z.object({
location: z.string().describe("Location to get the weather for."),
})
})
const agent = createAgent({
// use chat model from "@langchain/openai"
model: "openai:gpt-4o-mini",
tools: [getWeather]
});
const inputs = {
messages: [{ role: "user", content: "what is the weather in SF?" }],
};
const stream = await agent.stream(inputs, { streamMode: "values" });
for await (const { messages } of stream) {
console.log(messages);
}
// Returns the messages in the state at each step of execution
Agents combine language models with tools to create systems that can reason about tasks, decide which tools to use, and iteratively work towards solutions. createAgent provides a production-ready ReAct (Reasoning + Acting) agent implementation based on the paper Synergizing Reasoning and Acting in Language Models.
import { createAgent, tool } from "langchain";
import { z } from "zod/v3";
const getWeather = tool((input) => {
if (["sf", "san francisco"].includes(input.location.toLowerCase())) {
return "It's 60 degrees and foggy.";
} else {
return "It's 90 degrees and sunny.";
}
}, {
name: "get_weather",
description: "Call to get the current weather.",
schema: z.object({
location: z.string().describe("Location to get the weather for."),
})
})
const agent = createAgent({
// use chat model from "@langchain/openai"
model: "openai:gpt-4o-mini",
tools: [getWeather]
});
const inputs = {
messages: [{ role: "user", content: "what is the weather in SF?" }],
};
const stream = await agent.stream(inputs, { streamMode: "values" });
for await (const { messages } of stream) {
console.log(messages);
}
// Returns the messages in the state at each step of execution
LangChain Agents