lc_agents/orchestrator/
impls.rs1use async_trait::async_trait;
8use lc_core::language_models::BaseChatModel;
9use lc_rag::RetrieverTrait;
10
11use super::{Orchestrator, RunContext};
12use crate::{
13 AdaptiveRAG, AdaptiveRAGResult, AgentError, CRAGResult, CorrectiveRAGAgent, DeepResearchAgent,
14 PlanExecuteAgent, ResearchReport,
15};
16
17#[async_trait]
18impl Orchestrator for PlanExecuteAgent {
19 type Input = String;
20 type Output = String;
21
22 async fn run_with_context(
23 &self,
24 input: Self::Input,
25 ctx: &RunContext,
26 ) -> Result<Self::Output, AgentError> {
27 log::debug!(
28 target: "lc_agents::orchestrator",
29 "PlanExecuteAgent start, trace_id = {}",
30 ctx.trace_id
31 );
32 self.run(&input)
33 .await
34 .map_err(|e| AgentError::Other(format!("PlanExecute: {e}")))
35 }
36}
37
38#[async_trait]
39impl<M, R> Orchestrator for AdaptiveRAG<M, R>
40where
41 M: BaseChatModel + Send + Sync,
42 M::Error: Send + Sync,
43 R: RetrieverTrait + Send + Sync,
44{
45 type Input = String;
46 type Output = AdaptiveRAGResult;
47
48 async fn run_with_context(
49 &self,
50 input: Self::Input,
51 ctx: &RunContext,
52 ) -> Result<Self::Output, AgentError> {
53 log::debug!(
54 target: "lc_agents::orchestrator",
55 "AdaptiveRAG start, trace_id = {}",
56 ctx.trace_id
57 );
58 self.invoke(&input)
59 .await
60 .map_err(|e| AgentError::Other(format!("AdaptiveRAG: {e}")))
61 }
62}
63
64#[async_trait]
65impl<M, R> Orchestrator for CorrectiveRAGAgent<M, R>
66where
67 M: BaseChatModel + Send + Sync,
68 M::Error: Send + Sync,
69 R: RetrieverTrait + Send + Sync,
70{
71 type Input = String;
72 type Output = CRAGResult;
73
74 async fn run_with_context(
75 &self,
76 input: Self::Input,
77 ctx: &RunContext,
78 ) -> Result<Self::Output, AgentError> {
79 log::debug!(
80 target: "lc_agents::orchestrator",
81 "CorrectiveRAGAgent start, trace_id = {}",
82 ctx.trace_id
83 );
84 self.invoke(&input)
85 .await
86 .map_err(|e| AgentError::Other(format!("CorrectiveRAG: {e}")))
87 }
88}
89
90#[async_trait]
91impl<M> Orchestrator for DeepResearchAgent<M>
92where
93 M: BaseChatModel + Send + Sync,
94 M::Error: Send + Sync,
95{
96 type Input = String;
97 type Output = ResearchReport;
98
99 async fn run_with_context(
100 &self,
101 input: Self::Input,
102 ctx: &RunContext,
103 ) -> Result<Self::Output, AgentError> {
104 log::debug!(
105 target: "lc_agents::orchestrator",
106 "DeepResearchAgent start, trace_id = {}",
107 ctx.trace_id
108 );
109 self.research(&input)
110 .await
111 .map_err(|e| AgentError::Other(format!("DeepResearch: {e}")))
112 }
113}