NexAgent is a CLI-based AI agent that bridges natural language and OS-level execution. By leveraging Llama 3.1 via the Groq API, it interprets complex user intent and safely executes local file system operations, shell commands, and web searches.
I built NexAgent to explore the transition from traditional CLIs to AI-native operating environments. Instead of memorizing syntax, users interact with their system through high-level intent. This project demonstrates how an LLM can act as a reasoning engine for an OS, chaining multiple tools to solve non-trivial automation tasks while maintaining safety and auditability.
NexAgent is equipped with six core tools that enable it to manage your environment:
list_files: Recursively explore directory structures.read_file: Extract content from local files for context or analysis.write_file: Generate or update documents, scripts, or logs.create_folder: Organize project structures on the fly.run_command: Execute arbitrary shell commands (with safety filtering).get_weather: Dedicated weather service for fast, accurate local reports.search_web: Retrieve real-time information from the internet via DuckDuckGo.update_memory: [NEW] Proactively save user facts and preferences to long-term storage.
| Technology | Purpose |
|---|---|
| Python 3.11 | Core logic and tool implementation |
| Groq (Llama 3.1 8B) | High-speed LLM reasoning and function calling |
| Click | Robust CLI argument parsing and interactive REPL |
| JSON Storage | Persistent Long-Term Memory (LTM) engine |
| DuckDuckGo API | Live web search integration |
| Logging | Production-grade UTF-8 session tracking |
+-------------+ +-------------+ +-----------------+
| User | <----> | CLI | <----> | Agent |
| (English) | | (main.py) | | (agent.py) |
+-------------+ +--------+--------+
|
v
+------+--------+
| LLM (Groq) |
| (Reasoning) |
+------+--------+
|
+------+--------+
| Local Tools |
| (tools.py) |
+------+--------+
|
+------+--------+
| Memory (JSON) |
+---------------+
graph TD
A[User Input] --> B[CLI REPL]
B --> C{Agent.run}
C --> D[Send to Groq LLM]
D --> E{Tool Call?}
E -- Yes --> F[Execute Local Tool]
F --> G[Log Tool Result]
G --> D
E -- No --> H[Final Response]
H --> I[CLI Display]
I --> B
- Python 3.11+
- Groq API Key: Obtain one from the Groq Console.
- Clone the repository:
git clone https://github.com/imHardik1606/NexAgent.git cd NexAgent - Setup environment:
python -m venv .venv source .venv/bin/activate # Windows: .venv\Scripts\activate pip install -r requirements.txt
- Configure API Key:
Create a
.envfile in the root:GROQ_API_KEY=your_key_here
python main.py# Build the image
docker build -t nexagent .
# Run interactively with your .env
docker run -it --env-file .env nexagent- File Management:
Create a folder called 'src' and inside it create 'app.py' with a hello world print. - System Intel:
How many files are in the current directory and what is their total size? - Web-to-Local:
Search for the latest Python release version and write it to VERSION.txt. - Command execution:
List the active network connections using a system command.
NexAgent/
├── agent.py # LLM orchestration and tool calling logic
├── main.py # CLI entry point and interactive loop
├── tools.py # OS and Web tool implementations
├── logger.py # Session logging and formatting
├── config.py # Environment and global configuration
├── requirements.txt # Project dependencies
├── Dockerfile # Container configuration
└── PHASES.md # Detailed development roadmap
- The Function Calling Paradox: I learned that LLMs are excellent at choosing tools but require strict output schemas. Implementing recursive tool loops taught me how to handle multi-step reasoning where the output of one tool serves as the input for the next.
- Safety as a First-Class Citizen: Building the
run_commandtool required a "deny-list" approach to prevent destructive actions (likerm -rf /). I realized that an AI-native OS is only as good as its security sandbox. - Interactive UI in CLI: Integrating
Clickwith an LLM-driven REPL highlighted the importance of user feedback (like "Thinking..." indicators) to manage the latency of remote inference calls. - State Persistence: Managing conversation history while preventing token overflow taught me how to balance context retention with API efficiency.
- Enhanced Session Tracking: Implemented visually distinct session start/end headers in logs, including a timestamp and total interaction count for better session auditing.
- Path Resolution Logic: Added a
BASE_PATHconfiguration that locks the agent into a specific user directory (C:\Users\HP). All relative and drive-root paths are automatically resolved to this home directory for improved safety. - Refined Interface: Removed excessive emojis from system messages and headers to provide a cleaner, more professional CLI experience.
- Robust Test Suite: Expanded the internal testing framework in
tools.pyto cover nested directory creation, path resolution edge cases, and command execution timeouts.