Packages
langchain
0.8.2
0.9.2
0.9.1
0.9.0
0.8.14
0.8.13
0.8.12
0.8.11
0.8.10
0.8.9
0.8.8
0.8.7
0.8.6
0.8.5
0.8.4
0.8.3
0.8.2
0.8.1
0.8.0
0.7.0
0.6.3
0.6.2
0.6.1
0.6.0
0.5.2
0.5.1
0.5.0
0.4.1
0.4.0
0.4.0-rc.3
0.4.0-rc.2
0.4.0-rc.1
0.4.0-rc.0
0.3.3
0.3.2
0.3.1
0.3.0
0.3.0-rc.2
0.3.0-rc.1
0.3.0-rc.0
0.2.0
0.1.10
0.1.9
0.1.8
0.1.7
0.1.6
0.1.5
0.1.4
0.1.3
0.1.2
0.1.1
0.1.0
Elixir implementation of a LangChain style framework that lets Elixir projects integrate with and leverage LLMs.
Current section
Files
Jump to
Current section
Files
lib/chains/llm_chain/modes/while_needs_response.ex
defmodule LangChain.Chains.LLMChain.Modes.WhileNeedsResponse do
@moduledoc """
Execution mode that loops while the chain needs a response.
After each LLM call, if the response contains tool calls, this mode:
1. Executes the pending tool calls
2. Calls the LLM again with the tool results
3. Repeats until `needs_response` is false (no more tool calls)
The LLM always gets the last word after tool execution.
## Usage
LLMChain.run(chain, mode: :while_needs_response)
# or
LLMChain.run(chain, mode: LangChain.Chains.LLMChain.Modes.WhileNeedsResponse)
"""
@behaviour LangChain.Chains.LLMChain.Mode
import LangChain.Chains.LLMChain.Mode.Steps
alias LangChain.Chains.LLMChain
@impl true
def run(%LLMChain{needs_response: false} = chain, _opts) do
{:ok, chain}
end
def run(%LLMChain{} = chain, opts) do
chain = ensure_mode_state(chain)
{:continue, chain}
|> execute_tools()
|> call_llm()
|> continue_or_done(&run/2, opts)
end
end