Invocation

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/19

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 10:59 PM on 8/3/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

20 Terms

1
New cards

What does calling invoke() on a chat model do?

Sends a request to the model and waits for the complete response all at once.

2
New cards

When should you use invoke instead of stream?

When you need the full result immediately; with no intermediate output.

3
New cards

What does calling stream() on a chat model return?

An iterator that yields output chunks as they are produced.

4
New cards

Why is stream preferred for chat interfaces?

Because it matters that the user sees the response right away instead of waiting for generation to finish; which improves UX by showing the model 'thinking'.

5
New cards

What does a reasoning content block represent when streaming?

The model's chain of thought (CoT) — the model 'thinking out loud' before answering; e.g. Claude's extended thinking feature.

6
New cards

What does a tool_call_chunk block let you do; and why is this critical for agents?

It lets you receive a tool call progressively — first the name; then the arguments — which is critical for agents.

7
New cards

What is the difference between a stream chunk and a streaming event from astream_events?

A chunk is just a piece of text; while a streaming event is a structured; semantic record of what happened at a given moment in the model's execution lifecycle.

8
New cards

What two benefits does astream_events() provide?

It simplifies filtering based on event types and other metadata; and it aggregates the full message in the background.

9
New cards

When does LangChain automatically enable 'auto-streaming' for a chat model called via invoke()?

When it detects that the overall application is being streamed; such as when a LangGraph agent graph is run in a streaming mode.

10
New cards

What LangChain callback event is triggered while a chat model is being auto-streamed inside an invoke() call?

The on_llm_new_token event in LangChain's callback system.

11
New cards

What does batch() do?

Sends multiple requests in a single batch for efficient processing.

12
New cards

Why might you use batch instead of calling invoke in a loop?

It's faster and cheaper than calling invoke in a loop; since the model can optimize processing of parallel requests.

13
New cards

What does batch() return by default?

Only the final output for the entire batch.

14
New cards

How does batch_as_completed() differ from batch()?

batch_as_completed() streams the output for each individual input as it finishes generating; rather than waiting for the whole batch like batch() does.

15
New cards

What role does each message's 'role' field serve in a list of messages passed to a chat model?

Models use it to indicate who sent the message in the conversation.

16
New cards

python for chunk in model.stream('What color is the sky?'): for block in chunk.content_blocks: if block['type'] == 'reasoning' and (reasoning := block.get('reasoning')): print(f'Reasoning: {reasoning}') elif block['type'] == '________': print(f'Tool call chunk: {block}') elif block['type'] == 'text': print(block['text']) else: …

python for chunk in model.stream('What color is the sky?'): for block in chunk.content_blocks: if block['type'] == 'reasoning' and (reasoning := block.get('reasoning')): print(f'Reasoning: {reasoning}') elif block['type'] == 'tool_call_chunk': print(f'Tool call chunk: {block}') elif block['type'] == 'text': print(block['text']) else: ...

17
New cards

python async for event in model.________('Hello'): if event['event'] == 'on_chat_model_start': print(f'Input: {event['data']['input']}') elif event['event'] == 'on_chat_model_stream': print(f'Token: {event['data']['chunk'].text}') elif event['event'] == 'on_chat_model_end': print(f'Full message: {event['data']['output'].text}') else: pass

python async for event in model.astream_events('Hello'): if event['event'] == 'on_chat_model_start': print(f'Input: {event['data']['input']}') elif event['event'] == 'on_chat_model_stream': print(f'Token: {event['data']['chunk'].text}') elif event['event'] == 'on_chat_model_end': print(f'Full message: {event['data']['output'].text}') else: pass

18
New cards

python for response in model.________([ 'Why do parrots talk?'; 'why does husky look like a wolf?'; 'What is cloud computing' ]): print(response)

python for response in model.batch_as_completed([ 'Why do parrots talk?'; 'why does husky look like a wolf?'; 'What is cloud computing' ]): print(response)

19
New cards

python from langchain.messages import ________; ________; ________ conversation = [ SystemMessage('You are a helpful assistant that translates English to French.'); HumanMessage('Translate: I love programming.'); AIMessage('J'adore la programmation.'); HumanMessage('Translate: I love building applications.') ] response = model.invoke(conversation)

python from langchain.messages import HumanMessage; AIMessage; SystemMessage conversation = [ SystemMessage('You are a helpful assistant that translates English to French.'); HumanMessage('Translate: I love programming.'); AIMessage('J'adore la programmation.'); HumanMessage('Translate: I love building applications.') ] response = model.invoke(conversation)

20
New cards

python full = None # None | AIMessageChunk for chunk in model.stream('What color is the sky?'): full = chunk if full is None else full + chunk print(full.________)

python full = None # None | AIMessageChunk for chunk in model.stream('What color is the sky?'): full = chunk if full is None else full + chunk print(full.text)