#!/usr/bin/env python3 """ Debug script to check LlamaIndex version and ReActAgent API """ import subprocess import sys def check_llama_index_version(): """Check what version of llama-index is installed.""" try: result = subprocess.run(['pip', 'show', 'llama-index'], capture_output=True, text=True) print("=== LLAMA-INDEX VERSION ===") print(result.stdout) except Exception as e: print(f"Error checking version: {e}") def check_react_agent_api(): """Check ReActAgent available methods.""" try: from llama_index.core.agent import ReActAgent import inspect print("=== REACTAGENT API ===") methods = [m for m in dir(ReActAgent) if not m.startswith('_') and callable(getattr(ReActAgent, m))] print(f"Available methods: {sorted(methods)}") # Check specific methods we're interested in for method_name in ['chat', 'run', 'achat', 'arun']: if hasattr(ReActAgent, method_name): method = getattr(ReActAgent, method_name) sig = inspect.signature(method) is_async = inspect.iscoroutinefunction(method) print(f"{method_name}: exists, async={is_async}, sig={sig}") else: print(f"{method_name}: NOT FOUND") except Exception as e: print(f"Error checking ReActAgent API: {e}") def test_workflow_handler(): """Test what WorkflowHandler actually returns and what methods it has.""" try: print("\n=== WORKFLOW HANDLER TEST ===") # Import what we need from llama_index.core.agent import ReActAgent from llama_index.core.tools import BaseTool, FunctionTool from llama_index.core.llms.mock import MockLLM import inspect # Create a simple mock tool def mock_tool(query: str) -> str: """A simple mock tool.""" return f"Mock response for: {query}" tool = FunctionTool.from_defaults(fn=mock_tool, name="mock_tool") # Create a mock LLM llm = MockLLM(max_tokens=100) # Create ReActAgent agent = ReActAgent(tools=[tool], llm=llm, verbose=True) print(f"āœ… Created ReActAgent successfully") # Test the run method print("šŸ” Testing agent.run()...") workflow_handler = agent.run(user_msg="Hello test") print(f"šŸ” WorkflowHandler type: {type(workflow_handler)}") print(f"šŸ” WorkflowHandler module: {type(workflow_handler).__module__}") # Check WorkflowHandler methods wh_methods = [m for m in dir(workflow_handler) if not m.startswith('_')] print(f"šŸ” WorkflowHandler methods: {sorted(wh_methods)}") # Check for specific methods we're interested in for method_name in ['result', 'get_result', 'run', '__iter__', '__next__', 'wait', 'done']: if hasattr(workflow_handler, method_name): method = getattr(workflow_handler, method_name) if callable(method): try: sig = inspect.signature(method) is_async = inspect.iscoroutinefunction(method) print(f"āœ… {method_name}: exists, callable, async={is_async}, sig={sig}") except: print(f"āœ… {method_name}: exists, callable (signature unavailable)") else: print(f"āœ… {method_name}: exists, not callable, value={method}") else: print(f"āŒ {method_name}: NOT FOUND") # Test iteration print("\nšŸ” Testing iteration...") try: step_count = 0 for step in workflow_handler: step_count += 1 print(f" Step {step_count}: {type(step)} = {str(step)[:100]}...") if step_count >= 3: # Limit to avoid infinite loops break print(f"āœ… Iteration completed with {step_count} steps") except Exception as e: print(f"āŒ Iteration failed: {e}") # Test result() method if it exists print("\nšŸ” Testing .result() method...") try: if hasattr(workflow_handler, 'result'): result = workflow_handler.result() print(f"āœ… .result() returned: {type(result)} = {str(result)[:100]}...") else: print("āŒ No .result() method") except Exception as e: print(f"āŒ .result() failed: {e}") except Exception as e: print(f"āŒ WorkflowHandler test failed: {e}") import traceback traceback.print_exc() if __name__ == "__main__": check_llama_index_version() check_react_agent_api() test_workflow_handler()