invoke and ainvoke
invoke(input) blocks the current Python thread until one result is ready. await ainvoke(input) lets an async application yield control while it waits.
Tiny example
Section titled “Tiny example”# A command-line scriptreply = model.invoke("Summarize incident INC-104")
# An async FastAPI route or workerasync def summarize(ticket: str): reply = await model.ainvoke(f"Summarize {ticket}") return {"summary": reply.text}await is Python syntax. It does not mean “retry,” “sleep,” or “run in parallel.” The base Runnable async implementation may call synchronous code in a thread pool; a subclass can provide native async behavior.
Failure note
Section titled “Failure note”Calling invoke() inside an async web handler can block its event-loop thread. Calling ainvoke() does not remove provider rate limits, connection limits, or the need for a timeout.