mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-08-20 14:42:28 +02:00
245 KiB
245 KiB
In [1]:
!pip install langchain-openaiIn [2]:
from langchain_openai import ChatOpenAI
from langchain_community.tools.tavily_search import TavilySearchResults
from langgraph.prebuilt import chat_agent_executorIn [ ]:
# Optional to not need .env
import os
os.environ['TAVILY_API_KEY']='foo'
os.environ['OPENAI_API_KEY'] = 'foo'
tools=[TavilySearchResults(max_results=1)]
model=ChatOpenAI()In [ ]:
app=chat_agent_executor.create_function_calling_executor(model, tools)In [ ]:
app.get_graph().print_ascii()In [ ]:
print(app.get_graph().draw_mermaid())In [ ]:
from IPython.display import ImageIn [8]:
# !pip install pygraphvizIn [ ]:
Image(app.get_graph().draw_png())In [10]:
# !pip install pyppeteerIn [ ]:
from langchain_core.runnables.graph import CurveStyle, NodeColors, MermaidDrawMethod
Image(app.get_graph().draw_mermaid_png(
curve_style=CurveStyle.LINEAR,
node_colors=NodeColors(start="#ffdfba", end="#baffc9", other="#fad7de"),
wrap_label_n_words=9,
output_file_path=None,
draw_method=MermaidDrawMethod.PYPPETEER,
background_color="white",
padding=10
))In [12]:
Image(app.get_graph().draw_mermaid_png(
draw_method=MermaidDrawMethod.API,
))In [ ]:
Image(app.get_graph(add_condition_nodes=False).draw_mermaid_png(
draw_method=MermaidDrawMethod.API,
))In [ ]: