This guide explains how to use the Droidrun framework with Ollama, an open-source platform for running large language models (LLMs) locally. By integrating Ollama with Droidrun, you can leverage powerful local LLMs to automate Android devices, build intelligent agents, and experiment with advanced workflows.
Ollama lets you run, manage, and interact with LLMs on your own machine. It supports a variety of modern models (e.g., Qwen2.5vl, Gemma3, DeepSeek, Llama 4, etc.) and provides a simple HTTP API for integration.
Here is a minimal example of using Droidrun with Ollama as the LLM backend (using a modern model, e.g., Qwen2.5vl):
Copy
Ask AI
import asynciofrom llama_index.llms.ollama import Ollamafrom droidrun import DroidAgent, AdbToolsasync def main(): # load adb tools for the first connected device tools = AdbTools() # Set up the Ollama LLM with a modern model llm = Ollama( model="qwen2.5vl", # or "gemma3", "deepseek", "llama4", etc. base_url="http://localhost:11434", # default Ollama endpoint context_window=8192, # limit the max context window to prevent running out of memory. request_timeout=120.0 # increase the request timeout ) # Create the DroidAgent agent = DroidAgent( goal="Open Settings and check battery level", llm=llm, tools=tools, vision=False, # Optional: enable vision. use vision=True only in conjunction with a vision model reasoning=True, # Optional: enable planning/reasoning. Read more about the agent configuration in Core-Concepts/Agent ) # Run the agent result = await agent.run() print(f"Success: {result['success']}") if result.get('output'): print(f"Output: {result['output']}")if __name__ == "__main__": asyncio.run(main())
Limiting the llm’s context_window reduces memory usage, but degrades the agent’s performance too. For the best results try extending it as much as possible.