Skip to content

Langgraph

Type Annotations

Langgraph SDK highly invovles following Python type annotations:

  • typed dictionary
  • union
  • optional
  • any
  • lambda function

Langgraph Elements

  • State: shared data structure stores information
  • Nodes: individual processing units
  • Graph: represents the workflow
  • Edges: determine which node to execute next
  • Conditional edge: based on specific conditions
  • Start
  • End
  • Tools
  • ToolNode: the main job is to run a tool
  • StateGraph
  • Runnable: can be executed
  • Messages
  • Human Message
  • AI Message
  • System Message
  • Tool Message
  • Function Message

Python Tricks

Annotated

Annotated can provide additional context without affecting the type system.

email = Annotated[str, "a valid email address"]
print(email.__metadata__)

Docstring

In Langgraph, tool functions must have docstrings if description not provided.