or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

tessl/pypi-langgraph-prebuilt

Library with high-level APIs for creating and executing LangGraph agents and tools.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/langgraph-prebuilt@0.6.x

To install, run

npx @tessl/cli install tessl/pypi-langgraph-prebuilt@0.6.0

0

# LangGraph Prebuilt

1

2

LangGraph Prebuilt provides high-level APIs for creating and executing LangGraph agents and tools. It offers pre-built components that abstract complex agent orchestration patterns while maintaining flexibility for customization, focusing on simplicity and ease of use for building AI-powered applications.

3

4

## Package Information

5

6

- **Package Name**: langgraph-prebuilt

7

- **Package Type**: pip

8

- **Language**: Python

9

- **Installation**: `pip install langgraph` (bundled with LangGraph)

10

11

## Core Imports

12

13

```python

14

from langgraph.prebuilt import (

15

create_react_agent,

16

ToolNode,

17

tools_condition,

18

ValidationNode,

19

InjectedState,

20

InjectedStore,

21

)

22

23

# Human-in-the-Loop schemas (imported from submodule)

24

from langgraph.prebuilt.interrupt import (

25

HumanInterrupt,

26

HumanResponse,

27

ActionRequest,

28

HumanInterruptConfig,

29

)

30

```

31

32

## Basic Usage

33

34

```python

35

from langchain_anthropic import ChatAnthropic

36

from langchain_core.tools import tool

37

from langgraph.prebuilt import create_react_agent

38

39

# Define a tool for the agent to use

40

@tool

41

def search(query: str) -> str:

42

"""Search for information on the web."""

43

# This is a placeholder implementation

44

if "sf" in query.lower():

45

return "It's 60 degrees and foggy in San Francisco."

46

return "It's 90 degrees and sunny."

47

48

# Create the agent

49

model = ChatAnthropic(model="claude-3-7-sonnet-latest")

50

agent = create_react_agent(model, [search])

51

52

# Run the agent

53

result = agent.invoke({

54

"messages": [{"role": "user", "content": "what is the weather in sf"}]

55

})

56

```

57

58

## Architecture

59

60

LangGraph Prebuilt is built around several key components:

61

62

- **ReAct Agents**: Tool-calling agents that follow the ReAct (Reasoning and Acting) pattern with `create_react_agent`

63

- **Tool Execution**: `ToolNode` for parallel tool execution with comprehensive error handling

64

- **State Management**: Flexible state schemas supporting both TypedDict and Pydantic models

65

- **Validation System**: Schema-based validation with `ValidationNode` for structured output generation

66

- **Context Injection**: `InjectedState` and `InjectedStore` for providing tools with graph context

67

- **Human-in-the-Loop**: Agent Inbox integration schemas for interactive agent experiences

68

69

## Capabilities

70

71

### Agent Creation

72

73

ReAct-style agent creation with dynamic model selection, tool calling, and customizable workflows. Supports both simple and complex agent architectures with pre/post-model hooks.

74

75

```python { .api }

76

def create_react_agent(

77

model: Union[

78

str,

79

LanguageModelLike,

80

Callable[[StateSchema, Runtime[ContextT]], BaseChatModel],

81

Callable[[StateSchema, Runtime[ContextT]], Awaitable[BaseChatModel]],

82

Callable[

83

[StateSchema, Runtime[ContextT]], Runnable[LanguageModelInput, BaseMessage]

84

],

85

Callable[

86

[StateSchema, Runtime[ContextT]],

87

Awaitable[Runnable[LanguageModelInput, BaseMessage]],

88

],

89

],

90

tools: Union[Sequence[Union[BaseTool, Callable, dict[str, Any]]], ToolNode],

91

*,

92

prompt: Optional[Prompt] = None,

93

response_format: Optional[

94

Union[StructuredResponseSchema, tuple[str, StructuredResponseSchema]]

95

] = None,

96

pre_model_hook: Optional[RunnableLike] = None,

97

post_model_hook: Optional[RunnableLike] = None,

98

state_schema: Optional[StateSchemaType] = None,

99

context_schema: Optional[Type[Any]] = None,

100

checkpointer: Optional[Checkpointer] = None,

101

store: Optional[BaseStore] = None,

102

interrupt_before: Optional[list[str]] = None,

103

interrupt_after: Optional[list[str]] = None,

104

debug: bool = False,

105

version: Literal["v1", "v2"] = "v2",

106

name: Optional[str] = None,

107

**deprecated_kwargs: Any,

108

) -> CompiledStateGraph

109

```

110

111

[Agent Creation](./agent-creation.md)

112

113

### Tool Execution

114

115

Tool execution node that processes tool calls from AI messages with parallel execution, comprehensive error handling, and state injection capabilities.

116

117

```python { .api }

118

class ToolNode(RunnableCallable):

119

def __init__(

120

self,

121

tools: Sequence[Union[BaseTool, Callable]],

122

*,

123

name: str = "tools",

124

tags: Optional[list[str]] = None,

125

handle_tool_errors: Union[

126

bool, str, Callable[..., str], tuple[type[Exception], ...]

127

] = True,

128

messages_key: str = "messages",

129

) -> None: ...

130

131

def tools_condition(

132

state: Union[list[AnyMessage], dict[str, Any], BaseModel],

133

messages_key: str = "messages",

134

) -> Literal["tools", "__end__"]

135

```

136

137

[Tool Execution](./tool-execution.md)

138

139

### State and Store Injection

140

141

Annotations for injecting graph state and persistent storage into tool arguments, enabling context-aware tools without exposing internal state to the model.

142

143

```python { .api }

144

class InjectedState(InjectedToolArg):

145

def __init__(self, field: Optional[str] = None) -> None: ...

146

147

class InjectedStore(InjectedToolArg): ...

148

```

149

150

[State and Store Injection](./state-store-injection.md)

151

152

### Tool Validation

153

154

Schema-based validation node for validating tool calls against Pydantic schemas, useful for structured output generation and data extraction workflows.

155

156

```python { .api }

157

class ValidationNode(RunnableCallable):

158

def __init__(

159

self,

160

schemas: Sequence[Union[BaseTool, Type[BaseModel], Callable]],

161

*,

162

format_error: Optional[

163

Callable[[BaseException, ToolCall, Type[BaseModel]], str]

164

] = None,

165

name: str = "validation",

166

tags: Optional[list[str]] = None,

167

) -> None: ...

168

```

169

170

[Tool Validation](./tool-validation.md)

171

172

### Human-in-the-Loop Integration

173

174

TypedDict schemas for Agent Inbox integration, enabling human intervention and approval workflows within agent execution.

175

176

```python { .api }

177

class HumanInterrupt(TypedDict):

178

action_request: ActionRequest

179

config: HumanInterruptConfig

180

description: Optional[str]

181

182

class HumanResponse(TypedDict):

183

type: Literal["accept", "ignore", "response", "edit"]

184

args: Union[None, str, ActionRequest]

185

```

186

187

[Human-in-the-Loop Integration](./human-in-the-loop.md)

188

189

## State Management Types

190

191

```python { .api }

192

class AgentState(TypedDict):

193

messages: Annotated[Sequence[BaseMessage], add_messages]

194

remaining_steps: NotRequired[RemainingSteps]

195

196

class AgentStatePydantic(BaseModel):

197

messages: Annotated[Sequence[BaseMessage], add_messages]

198

remaining_steps: RemainingSteps = 25

199

200

class AgentStateWithStructuredResponse(AgentState):

201

structured_response: StructuredResponse

202

203

class AgentStateWithStructuredResponsePydantic(AgentStatePydantic):

204

structured_response: StructuredResponse

205

```

206

207

## Type Definitions

208

209

```python { .api }

210

# Core type aliases

211

StructuredResponse = Union[dict, BaseModel]

212

StructuredResponseSchema = Union[dict, type[BaseModel]]

213

214

# State management types

215

StateSchema = TypeVar("StateSchema", bound=Union[AgentState, AgentStatePydantic])

216

StateSchemaType = Type[StateSchema]

217

218

# Prompt types

219

Prompt = Union[

220

SystemMessage,

221

str,

222

Callable[[StateSchema], LanguageModelInput],

223

Runnable[StateSchema, LanguageModelInput],

224

]

225

226

# Message and tool types (from langchain-core)

227

ToolCall = dict[str, Any] # Tool call dictionary with name, args, id, type fields

228

BaseMessage = Any # From langchain_core.messages

229

AIMessage = Any # From langchain_core.messages

230

ToolMessage = Any # From langchain_core.messages

231

SystemMessage = Any # From langchain_core.messages

232

AnyMessage = Union[BaseMessage, AIMessage, ToolMessage, SystemMessage] # From langchain_core.messages

233

LanguageModelInput = Union[str, Sequence[BaseMessage]] # From langchain-core

234

235

# LangChain types

236

BaseChatModel = Any # From langchain_core.language_models

237

BaseTool = Any # From langchain_core.tools

238

Runnable = Any # From langchain_core.runnables

239

RunnableLike = Union[Runnable, Callable]

240

LanguageModelLike = Union[BaseChatModel, Runnable[LanguageModelInput, BaseMessage]]

241

242

# LangGraph types

243

Checkpointer = Any # From langgraph-checkpoint

244

BaseStore = Any # From langgraph.store.base

245

Runtime = Any # From langgraph.runtime

246

CompiledStateGraph = Any # From langgraph.graph.state

247

RemainingSteps = int # From langgraph.managed

248

Command = Any # From langgraph.types

249

Send = Any # From langgraph.types

250

251

# Type variables

252

ContextT = TypeVar("ContextT") # Runtime context type variable

253

```