MCPcopy Create free account
hub / github.com/Alibaba-NLP/VRAG / run

Method run

demo/vimrag_agent.py:339–453  ·  view source on GitHub ↗

Run the VimRAG agent on a sample query. Yields progress events in real-time. Args: sample: Dict with 'query' key Yields: Dict with 'event' key and event-specific data: - {"event": "think", "content": str} - Thinking c

(self, sample)

Source from the content-addressed store, hash-verified

337 multimodal_memory[last_graph_node['id']] = node_memory
338
339 def run(self, sample):
340 """
341 Run the VimRAG agent on a sample query. Yields progress events in real-time.
342
343 Args:
344 sample: Dict with 'query' key
345
346 Yields:
347 Dict with 'event' key and event-specific data:
348 - {"event": "think", "content": str} - Thinking content chunk
349 - {"event": "content", "content": str} - Output content chunk
350 - {"event": "search", "query": str} - Search initiated
351 - {"event": "search_done", "results": dict} - Search completed
352 - {"event": "memorize", "summary": str} - Memorize action
353 - {"event": "answer", "content": str, "sample": dict} - Final answer
354 - {"event": "error", "content": str} - Error occurred
355 - {"event": "max_steps", "content": str} - Maximum steps reached
356 """
357 question = sample['query']
358 trajectory = []
359 search_results_list = []
360
361 # Initialize action graph with root node
362 action_graph = [{
363 "id": "root",
364 "name": "Initial Node",
365 "content": f"Initial query from user: {question}"
366 }]
367 multimodal_memory = {}
368
369 need_update_context = True
370 can_search = True
371 last_graph_node = None
372 vision_ids_dict = None
373 generate_times = 0
374 steps_remaining = self.max_mem_steps
375
376 while steps_remaining > 0:
377 steps_remaining -= 1
378
379 # Build or update context
380 if need_update_context:
381 messages = self._build_initial_messages(question, action_graph)
382 self._update_messages_with_memory(messages, action_graph, multimodal_memory)
383 need_update_context = False
384 can_search = True
385
386 try:
387 # Generate model response with streaming
388 messages_base64 = fast_process_messages(messages)
389
390 # 流式收集模型输出
391 full_response = ""
392 full_reasoning = ""
393 for chunk in self._model_generate(messages_base64):
394 if chunk["type"] == "think":
395 yield {"event": "think", "content": chunk["content"]}
396 elif chunk["type"] == "content":

Callers 2

mainFunction · 0.95
vimrag_agent.pyFile · 0.45

Calls 8

_model_generateMethod · 0.95
_parse_responseMethod · 0.95
_handle_search_nodeMethod · 0.95
fast_process_messagesFunction · 0.90
getMethod · 0.45

Tested by

no test coverage detected