Skip to content

LLM Integration

Sudhanshu edited this page Nov 11, 2026 · 1 revision

Optional OpenAI Integration

There are precisely two opt-in hosted-model demonstrations: llm_node (string prompt/response) and messages_state_llm (chat messages). All other examples run without model API requests.

sequenceDiagram
 participant Developer
 participant CLI as main(argv)
 participant Demo as LLM example
 participant Secrets as OS environment / local .env
 participant Model as ChatOpenAI
 participant API as Hosted OpenAI API
 Developer->>CLI: --with-llm or --topic llm_node
 CLI->>Demo: run selected LLM example
 Demo->>Secrets: load_dotenv; check OPENAI_API_KEY
 alt Key configured
   Demo->>Model: instantiate model
   Demo->>Model: invoke(prompt or messages)
   Model->>API: HTTPS API request
   API-->>Model: model response
   Model-->>Demo: response content
   Demo-->>CLI: output dict
 else Missing key
   Demo-->>CLI: RuntimeError (configuration)
 end
 CLI-->>Developer: output / error
Loading

Setup

Create a local .env (the .gitignore excludes it):

OPENAI_API_KEY=YOUR_API_KEY_HERE
OPENAI_MODEL=YOUR_AVAILABLE_MODEL_NAME

Then invoke one model example explicitly:

python .\langgraph_example_multi_agents.py --topic llm_node --model YOUR_AVAILABLE_MODEL_NAME

To include both OpenAI examples in the full CLI run, use --with-llm instead. Calls require internet/model access and can incur charges. The example does not implement tool calling, retrieval, tracing, persistent memory or multi-agent model cooperation.

API key correction

The attached Python script originally checked the wrong environment variable, even though its error message said OPENAI_API_KEY. The publishable source package fixes the check to OPENAI_API_KEY to match the notebook and setup guide. Do not print or commit credentials.

Clone this wiki locally