A ReactAgent instance with invoke and stream methods
import { createAgent, tool } from "langchain";
import { z } from "zod";
const search = tool(
({ query }) => `Results for: ${query}`,
{
name: "search",
description: "Search for information",
schema: z.object({
query: z.string().describe("The search query"),
})
}
);
const agent = createAgent({
llm: "openai:gpt-4o",
tools: [search],
});
const result = await agent.invoke({
messages: [{ role: "user", content: "Search for ReAct agents" }],
});
import { createAgent } from "langchain";
import { z } from "zod";
const ContactInfo = z.object({
name: z.string(),
email: z.string(),
phone: z.string(),
});
const agent = createAgent({
llm: "openai:gpt-4o",
tools: [],
responseFormat: ContactInfo,
});
const result = await agent.invoke({
messages: [{
role: "user",
content: "Extract: John Doe, john@example.com, (555) 123-4567"
}],
});
console.log(result.structuredResponse);
// { name: 'John Doe', email: 'john@example.com', phone: '(555) 123-4567' }
Creates a production-ready ReAct (Reasoning + Acting) agent that combines language models with tools and middleware to create systems that can reason about tasks, decide which tools to use, and iteratively work towards solutions.
The agent follows the ReAct pattern, interleaving reasoning steps with tool calls to iteratively work towards solutions. It can handle multiple tool calls in sequence or parallel, maintain state across interactions, and provide auditable decision processes.
The reasoning engine can be specified as:
"openai:gpt-4o" for simple setupTools give agents the ability to take actions:
tool functionToolNode for custom error handlingShape how your agent approaches tasks:
Middleware allows you to extend the agent's behavior:
responseFormat with a Zod schema to get typed responsesA ReactAgent instance with invoke and stream methods
import { createAgent, tool } from "langchain";
import { z } from "zod";
const search = tool(
({ query }) => `Results for: ${query}`,
{
name: "search",
description: "Search for information",
schema: z.object({
query: z.string().describe("The search query"),
})
}
);
const agent = createAgent({
llm: "openai:gpt-4o",
tools: [search],
});
const result = await agent.invoke({
messages: [{ role: "user", content: "Search for ReAct agents" }],
});
import { createAgent } from "langchain";
import { z } from "zod";
const ContactInfo = z.object({
name: z.string(),
email: z.string(),
phone: z.string(),
});
const agent = createAgent({
llm: "openai:gpt-4o",
tools: [],
responseFormat: ContactInfo,
});
const result = await agent.invoke({
messages: [{
role: "user",
content: "Extract: John Doe, john@example.com, (555) 123-4567"
}],
});
console.log(result.structuredResponse);
// { name: 'John Doe', email: 'john@example.com', phone: '(555) 123-4567' }
Creates a production-ready ReAct (Reasoning + Acting) agent that combines language models with tools and middleware to create systems that can reason about tasks, decide which tools to use, and iteratively work towards solutions.
The agent follows the ReAct pattern, interleaving reasoning steps with tool calls to iteratively work towards solutions. It can handle multiple tool calls in sequence or parallel, maintain state across interactions, and provide auditable decision processes.
The reasoning engine can be specified as:
"openai:gpt-4o" for simple setupTools give agents the ability to take actions:
tool functionToolNode for custom error handlingShape how your agent approaches tasks:
Middleware allows you to extend the agent's behavior:
responseFormat with a Zod schema to get typed responsesA ReactAgent instance with invoke and stream methods
import { createAgent, tool } from "langchain";
import { z } from "zod";
const search = tool(
({ query }) => `Results for: ${query}`,
{
name: "search",
description: "Search for information",
schema: z.object({
query: z.string().describe("The search query"),
})
}
);
const agent = createAgent({
llm: "openai:gpt-4o",
tools: [search],
});
const result = await agent.invoke({
messages: [{ role: "user", content: "Search for ReAct agents" }],
});
import { createAgent } from "langchain";
import { z } from "zod";
const ContactInfo = z.object({
name: z.string(),
email: z.string(),
phone: z.string(),
});
const agent = createAgent({
llm: "openai:gpt-4o",
tools: [],
responseFormat: ContactInfo,
});
const result = await agent.invoke({
messages: [{
role: "user",
content: "Extract: John Doe, john@example.com, (555) 123-4567"
}],
});
console.log(result.structuredResponse);
// { name: 'John Doe', email: 'john@example.com', phone: '(555) 123-4567' }
Creates a production-ready ReAct (Reasoning + Acting) agent that combines language models with tools and middleware to create systems that can reason about tasks, decide which tools to use, and iteratively work towards solutions.
The agent follows the ReAct pattern, interleaving reasoning steps with tool calls to iteratively work towards solutions. It can handle multiple tool calls in sequence or parallel, maintain state across interactions, and provide auditable decision processes.
The reasoning engine can be specified as:
"openai:gpt-4o" for simple setupTools give agents the ability to take actions:
tool functionToolNode for custom error handlingShape how your agent approaches tasks:
Middleware allows you to extend the agent's behavior:
responseFormat with a Zod schema to get typed responsesA ReactAgent instance with invoke and stream methods
import { createAgent, tool } from "langchain";
import { z } from "zod";
const search = tool(
({ query }) => `Results for: ${query}`,
{
name: "search",
description: "Search for information",
schema: z.object({
query: z.string().describe("The search query"),
})
}
);
const agent = createAgent({
llm: "openai:gpt-4o",
tools: [search],
});
const result = await agent.invoke({
messages: [{ role: "user", content: "Search for ReAct agents" }],
});
import { createAgent } from "langchain";
import { z } from "zod";
const ContactInfo = z.object({
name: z.string(),
email: z.string(),
phone: z.string(),
});
const agent = createAgent({
llm: "openai:gpt-4o",
tools: [],
responseFormat: ContactInfo,
});
const result = await agent.invoke({
messages: [{
role: "user",
content: "Extract: John Doe, john@example.com, (555) 123-4567"
}],
});
console.log(result.structuredResponse);
// { name: 'John Doe', email: 'john@example.com', phone: '(555) 123-4567' }
Creates a production-ready ReAct (Reasoning + Acting) agent that combines language models with tools and middleware to create systems that can reason about tasks, decide which tools to use, and iteratively work towards solutions.
The agent follows the ReAct pattern, interleaving reasoning steps with tool calls to iteratively work towards solutions. It can handle multiple tool calls in sequence or parallel, maintain state across interactions, and provide auditable decision processes.
The reasoning engine can be specified as:
"openai:gpt-4o" for simple setupTools give agents the ability to take actions:
tool functionToolNode for custom error handlingShape how your agent approaches tasks:
Middleware allows you to extend the agent's behavior:
responseFormat with a Zod schema to get typed responsesA ReactAgent instance with invoke and stream methods
import { createAgent, tool } from "langchain";
import { z } from "zod";
const search = tool(
({ query }) => `Results for: ${query}`,
{
name: "search",
description: "Search for information",
schema: z.object({
query: z.string().describe("The search query"),
})
}
);
const agent = createAgent({
llm: "openai:gpt-4o",
tools: [search],
});
const result = await agent.invoke({
messages: [{ role: "user", content: "Search for ReAct agents" }],
});
import { createAgent } from "langchain";
import { z } from "zod";
const ContactInfo = z.object({
name: z.string(),
email: z.string(),
phone: z.string(),
});
const agent = createAgent({
llm: "openai:gpt-4o",
tools: [],
responseFormat: ContactInfo,
});
const result = await agent.invoke({
messages: [{
role: "user",
content: "Extract: John Doe, john@example.com, (555) 123-4567"
}],
});
console.log(result.structuredResponse);
// { name: 'John Doe', email: 'john@example.com', phone: '(555) 123-4567' }
Creates a production-ready ReAct (Reasoning + Acting) agent that combines language models with tools and middleware to create systems that can reason about tasks, decide which tools to use, and iteratively work towards solutions.
The agent follows the ReAct pattern, interleaving reasoning steps with tool calls to iteratively work towards solutions. It can handle multiple tool calls in sequence or parallel, maintain state across interactions, and provide auditable decision processes.
The reasoning engine can be specified as:
"openai:gpt-4o" for simple setupTools give agents the ability to take actions:
tool functionToolNode for custom error handlingShape how your agent approaches tasks:
Middleware allows you to extend the agent's behavior:
responseFormat with a Zod schema to get typed responsesA ReactAgent instance with invoke and stream methods
import { createAgent, tool } from "langchain";
import { z } from "zod";
const search = tool(
({ query }) => `Results for: ${query}`,
{
name: "search",
description: "Search for information",
schema: z.object({
query: z.string().describe("The search query"),
})
}
);
const agent = createAgent({
llm: "openai:gpt-4o",
tools: [search],
});
const result = await agent.invoke({
messages: [{ role: "user", content: "Search for ReAct agents" }],
});
import { createAgent } from "langchain";
import { z } from "zod";
const ContactInfo = z.object({
name: z.string(),
email: z.string(),
phone: z.string(),
});
const agent = createAgent({
llm: "openai:gpt-4o",
tools: [],
responseFormat: ContactInfo,
});
const result = await agent.invoke({
messages: [{
role: "user",
content: "Extract: John Doe, john@example.com, (555) 123-4567"
}],
});
console.log(result.structuredResponse);
// { name: 'John Doe', email: 'john@example.com', phone: '(555) 123-4567' }
Creates a production-ready ReAct (Reasoning + Acting) agent that combines language models with tools and middleware to create systems that can reason about tasks, decide which tools to use, and iteratively work towards solutions.
The agent follows the ReAct pattern, interleaving reasoning steps with tool calls to iteratively work towards solutions. It can handle multiple tool calls in sequence or parallel, maintain state across interactions, and provide auditable decision processes.
The reasoning engine can be specified as:
"openai:gpt-4o" for simple setupTools give agents the ability to take actions:
tool functionToolNode for custom error handlingShape how your agent approaches tasks:
Middleware allows you to extend the agent's behavior:
responseFormat with a Zod schema to get typed responsesA ReactAgent instance with invoke and stream methods
import { createAgent, tool } from "langchain";
import { z } from "zod";
const search = tool(
({ query }) => `Results for: ${query}`,
{
name: "search",
description: "Search for information",
schema: z.object({
query: z.string().describe("The search query"),
})
}
);
const agent = createAgent({
llm: "openai:gpt-4o",
tools: [search],
});
const result = await agent.invoke({
messages: [{ role: "user", content: "Search for ReAct agents" }],
});
import { createAgent } from "langchain";
import { z } from "zod";
const ContactInfo = z.object({
name: z.string(),
email: z.string(),
phone: z.string(),
});
const agent = createAgent({
llm: "openai:gpt-4o",
tools: [],
responseFormat: ContactInfo,
});
const result = await agent.invoke({
messages: [{
role: "user",
content: "Extract: John Doe, john@example.com, (555) 123-4567"
}],
});
console.log(result.structuredResponse);
// { name: 'John Doe', email: 'john@example.com', phone: '(555) 123-4567' }
Creates a production-ready ReAct (Reasoning + Acting) agent that combines language models with tools and middleware to create systems that can reason about tasks, decide which tools to use, and iteratively work towards solutions.
The agent follows the ReAct pattern, interleaving reasoning steps with tool calls to iteratively work towards solutions. It can handle multiple tool calls in sequence or parallel, maintain state across interactions, and provide auditable decision processes.
The reasoning engine can be specified as:
"openai:gpt-4o" for simple setupTools give agents the ability to take actions:
tool functionToolNode for custom error handlingShape how your agent approaches tasks:
Middleware allows you to extend the agent's behavior:
responseFormat with a Zod schema to get typed responsesA ReactAgent instance with invoke and stream methods
import { createAgent, tool } from "langchain";
import { z } from "zod";
const search = tool(
({ query }) => `Results for: ${query}`,
{
name: "search",
description: "Search for information",
schema: z.object({
query: z.string().describe("The search query"),
})
}
);
const agent = createAgent({
llm: "openai:gpt-4o",
tools: [search],
});
const result = await agent.invoke({
messages: [{ role: "user", content: "Search for ReAct agents" }],
});
import { createAgent } from "langchain";
import { z } from "zod";
const ContactInfo = z.object({
name: z.string(),
email: z.string(),
phone: z.string(),
});
const agent = createAgent({
llm: "openai:gpt-4o",
tools: [],
responseFormat: ContactInfo,
});
const result = await agent.invoke({
messages: [{
role: "user",
content: "Extract: John Doe, john@example.com, (555) 123-4567"
}],
});
console.log(result.structuredResponse);
// { name: 'John Doe', email: 'john@example.com', phone: '(555) 123-4567' }
Creates a production-ready ReAct (Reasoning + Acting) agent that combines language models with tools and middleware to create systems that can reason about tasks, decide which tools to use, and iteratively work towards solutions.
The agent follows the ReAct pattern, interleaving reasoning steps with tool calls to iteratively work towards solutions. It can handle multiple tool calls in sequence or parallel, maintain state across interactions, and provide auditable decision processes.
The reasoning engine can be specified as:
"openai:gpt-4o" for simple setupTools give agents the ability to take actions:
tool functionToolNode for custom error handlingShape how your agent approaches tasks:
Middleware allows you to extend the agent's behavior:
responseFormat with a Zod schema to get typed responsesA ReactAgent instance with invoke and stream methods
import { createAgent, tool } from "langchain";
import { z } from "zod";
const search = tool(
({ query }) => `Results for: ${query}`,
{
name: "search",
description: "Search for information",
schema: z.object({
query: z.string().describe("The search query"),
})
}
);
const agent = createAgent({
llm: "openai:gpt-4o",
tools: [search],
});
const result = await agent.invoke({
messages: [{ role: "user", content: "Search for ReAct agents" }],
});
import { createAgent } from "langchain";
import { z } from "zod";
const ContactInfo = z.object({
name: z.string(),
email: z.string(),
phone: z.string(),
});
const agent = createAgent({
llm: "openai:gpt-4o",
tools: [],
responseFormat: ContactInfo,
});
const result = await agent.invoke({
messages: [{
role: "user",
content: "Extract: John Doe, john@example.com, (555) 123-4567"
}],
});
console.log(result.structuredResponse);
// { name: 'John Doe', email: 'john@example.com', phone: '(555) 123-4567' }
Creates a production-ready ReAct (Reasoning + Acting) agent that combines language models with tools and middleware to create systems that can reason about tasks, decide which tools to use, and iteratively work towards solutions.
The agent follows the ReAct pattern, interleaving reasoning steps with tool calls to iteratively work towards solutions. It can handle multiple tool calls in sequence or parallel, maintain state across interactions, and provide auditable decision processes.
The reasoning engine can be specified as:
"openai:gpt-4o" for simple setupTools give agents the ability to take actions:
tool functionToolNode for custom error handlingShape how your agent approaches tasks:
Middleware allows you to extend the agent's behavior:
responseFormat with a Zod schema to get typed responsesA ReactAgent instance with invoke and stream methods
import { createAgent, tool } from "langchain";
import { z } from "zod";
const search = tool(
({ query }) => `Results for: ${query}`,
{
name: "search",
description: "Search for information",
schema: z.object({
query: z.string().describe("The search query"),
})
}
);
const agent = createAgent({
llm: "openai:gpt-4o",
tools: [search],
});
const result = await agent.invoke({
messages: [{ role: "user", content: "Search for ReAct agents" }],
});
import { createAgent } from "langchain";
import { z } from "zod";
const ContactInfo = z.object({
name: z.string(),
email: z.string(),
phone: z.string(),
});
const agent = createAgent({
llm: "openai:gpt-4o",
tools: [],
responseFormat: ContactInfo,
});
const result = await agent.invoke({
messages: [{
role: "user",
content: "Extract: John Doe, john@example.com, (555) 123-4567"
}],
});
console.log(result.structuredResponse);
// { name: 'John Doe', email: 'john@example.com', phone: '(555) 123-4567' }
Creates a production-ready ReAct (Reasoning + Acting) agent that combines language models with tools and middleware to create systems that can reason about tasks, decide which tools to use, and iteratively work towards solutions.
The agent follows the ReAct pattern, interleaving reasoning steps with tool calls to iteratively work towards solutions. It can handle multiple tool calls in sequence or parallel, maintain state across interactions, and provide auditable decision processes.
The reasoning engine can be specified as:
"openai:gpt-4o" for simple setupTools give agents the ability to take actions:
tool functionToolNode for custom error handlingShape how your agent approaches tasks:
Middleware allows you to extend the agent's behavior:
responseFormat with a Zod schema to get typed responsesA ReactAgent instance with invoke and stream methods
import { createAgent, tool } from "langchain";
import { z } from "zod";
const search = tool(
({ query }) => `Results for: ${query}`,
{
name: "search",
description: "Search for information",
schema: z.object({
query: z.string().describe("The search query"),
})
}
);
const agent = createAgent({
llm: "openai:gpt-4o",
tools: [search],
});
const result = await agent.invoke({
messages: [{ role: "user", content: "Search for ReAct agents" }],
});
import { createAgent } from "langchain";
import { z } from "zod";
const ContactInfo = z.object({
name: z.string(),
email: z.string(),
phone: z.string(),
});
const agent = createAgent({
llm: "openai:gpt-4o",
tools: [],
responseFormat: ContactInfo,
});
const result = await agent.invoke({
messages: [{
role: "user",
content: "Extract: John Doe, john@example.com, (555) 123-4567"
}],
});
console.log(result.structuredResponse);
// { name: 'John Doe', email: 'john@example.com', phone: '(555) 123-4567' }
Creates a production-ready ReAct (Reasoning + Acting) agent that combines language models with tools and middleware to create systems that can reason about tasks, decide which tools to use, and iteratively work towards solutions.
The agent follows the ReAct pattern, interleaving reasoning steps with tool calls to iteratively work towards solutions. It can handle multiple tool calls in sequence or parallel, maintain state across interactions, and provide auditable decision processes.
Core Components
Model
The reasoning engine can be specified as:
"openai:gpt-4o"for simple setupTools
Tools give agents the ability to take actions:
toolfunctionToolNodefor custom error handlingPrompt
Shape how your agent approaches tasks:
Middleware
Middleware allows you to extend the agent's behavior:
Advanced Features
responseFormatwith a Zod schema to get typed responses