ワンクリックで
agents
AgentExecutor, ChatAgent (ReAct), OpenAIToolsAgent, and the Agent trait.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
AgentExecutor, ChatAgent (ReAct), OpenAIToolsAgent, and the Agent trait.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
JOB-251 — Why Arc<dyn LLM> over LLMClone, migration pattern, and correct LLM ownership model.
All Chain types — LLMChain, ConversationalChain, SequentialChain, StuffDocuments, ConversationalRetrievalQA, SqlDatabaseChain.
Trait conformance tests, property-based tests (proptest), fuzz targets, and boundary contracts for langchainx traits.
Core langchainx patterns — LLMChain, builder pattern, Chain trait, prompt macros, and basic invocation.
Constructing LLM backends (OpenAI, Claude, DeepSeek, Qwen, Ollama) and configuring CallOptions.
JOB-256 — blanket From impl, removing redundant Into impls, RwLock vs Mutex for memory.
| name | agents |
| description | AgentExecutor, ChatAgent (ReAct), OpenAIToolsAgent, and the Agent trait. |
#[async_trait]
pub trait Agent: Send + Sync {
async fn plan(
&self,
intermediate_steps: &[(AgentAction, String)],
inputs: PromptArgs,
) -> Result<AgentEvent, AgentError>;
fn get_tools(&self) -> Vec<Arc<dyn Tool>>;
}
AgentEvent is either Action(Vec<AgentAction>) or Finish(AgentFinish). The executor
calls plan() in a loop until Finish or max_iterations.
Uses OpenAI function-calling API. More reliable than ReAct text parsing.
use std::sync::Arc;
use langchainx::{
agent::{AgentExecutor, OpenAIToolsAgentBuilder},
chain::Chain,
llm::openai::OpenAI,
memory::SimpleMemory,
prompt_args,
tools::Tool,
};
let tools: Vec<Arc<dyn Tool>> = vec![Arc::new(MyTool)];
let agent = OpenAIToolsAgentBuilder::new()
.tools(&tools)
.llm(OpenAI::default())
.build()?;
let executor = AgentExecutor::from_agent(agent)
.with_max_iterations(10)
.with_memory(SimpleMemory::new().into())
.with_break_if_error(false);
// AgentExecutor implements Chain — use the Chain API
let result = executor.invoke(prompt_args! {
"input" => "How many words are in 'hello world'?",
}).await?;
println!("{result}");
## ChatAgent (ReAct)
Uses text-based ReAct reasoning. Works with any LLM but is less reliable than function calling.
use langchainx::agent::{AgentExecutor, ChatAgentBuilder};
let agent = ChatAgentBuilder::new()
.tools(&tools)
.llm(OpenAI::default())
.build()?;
let executor = AgentExecutor::from_agent(agent)
.with_max_iterations(10);
## AgentExecutor Options
AgentExecutor::from_agent(agent)
.with_max_iterations(10) // default: Some(10). None = unlimited (dangerous)
.with_memory(mem.into()) // Arc<Mutex<dyn BaseMemory>>
.with_break_if_error(true) // return Err on tool failure instead of continuing
When max_iterations is reached, the executor returns Ok(GenerateResult) with
generation = "Max iterations reached" — not an error.
When memory is set, the executor:
chat_history into input_variables before each plan() callFinish, saves user input, tool call messages, and AI response to memoryThe required input key is "input" (hardcoded in executor).
let executor = AgentExecutor::from_agent(agent)
.with_memory(SimpleMemory::new().into());
// First turn
executor.invoke(prompt_args! { "input" => "My name is Alice" }).await?;
// Second turn — executor injects chat_history automatically
executor.invoke(prompt_args! { "input" => "What is my name?" }).await?;