MCPcopy
hub / github.com/PromtEngineer/localGPT / get_agent

Function get_agent

rag_system/main.py:167–209  ·  view source on GitHub ↗

Factory function to get an instance of the RAG agent based on the specified mode. Args: mode: Configuration mode ("default", "fast") Returns: Configured Agent instance

(mode: str = "default")

Source from the content-addressed store, hash-verified

165# ============================================================================
166
167def get_agent(mode: str = "default") -> Agent:
168 """
169 Factory function to get an instance of the RAG agent based on the specified mode.
170
171 Args:
172 mode: Configuration mode ("default", "fast")
173
174 Returns:
175 Configured Agent instance
176 """
177 load_dotenv()
178
179 # Initialize the appropriate LLM client based on backend configuration
180 if LLM_BACKEND.lower() == "watsonx":
181 from rag_system.utils.watsonx_client import WatsonXClient
182
183 if not WATSONX_CONFIG["api_key"] or not WATSONX_CONFIG["project_id"]:
184 raise ValueError(
185 "Watson X configuration incomplete. Please set WATSONX_API_KEY and WATSONX_PROJECT_ID "
186 "environment variables."
187 )
188
189 llm_client = WatsonXClient(
190 api_key=WATSONX_CONFIG["api_key"],
191 project_id=WATSONX_CONFIG["project_id"],
192 url=WATSONX_CONFIG["url"]
193 )
194 llm_config = WATSONX_CONFIG
195 print(f"🔧 Using Watson X backend with granite models")
196 else:
197 llm_client = OllamaClient(host=OLLAMA_CONFIG["host"])
198 llm_config = OLLAMA_CONFIG
199 print(f"🔧 Using Ollama backend")
200
201 # Get the configuration for the specified mode
202 config = PIPELINE_CONFIGS.get(mode, PIPELINE_CONFIGS['default'])
203
204 agent = Agent(
205 pipeline_configs=config,
206 llm_client=llm_client,
207 ollama_config=llm_config
208 )
209 return agent
210
211def validate_model_config():
212 """

Callers 4

test_indexMethod · 0.90
api_server.pyFile · 0.90

Calls 3

WatsonXClientClass · 0.90
OllamaClientClass · 0.90
AgentClass · 0.90

Tested by 1

test_indexMethod · 0.72