This project demonstrates a simple but effective pattern for using LLMs with tools, serving as a stepping stone towards more complex agentic systems. It shows how to:
- Use an LLM to recognize when a tool should be used
- Delegate the actual task to a specialized tool
- Process and return the results
non_agentic_llm_with_tool.py
: Main script demonstrating the LLM + tool patternjson_conversion_tool.py
: Tool implementation for converting structured text to JSON
- Create a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
- Ensure Ollama is running locally with the qwen2:7b model:
ollama pull qwen2:7b
Run the main script to see examples of different types of structured data being converted to JSON:
python non_agentic_llm_with_tool.py
The script includes examples for:
- Project Information
- Personal Information
- Product Information
- Weather Data
-
The LLM is given a system prompt that instructs it to:
- Recognize JSON conversion requests
- Not attempt the conversion itself
- Acknowledge that it will use the tool
-
When a JSON conversion is requested:
- The LLM acknowledges the request
- The
process_llm_response
function detects this acknowledgment - The
format_to_json
tool is called with the original input - The tool uses another LLM call to perform the actual conversion
-
The result is returned as a properly formatted JSON object
- Clear separation of concerns between LLM and tool
- Robust error handling
- Flexible input format
- Customizable messages
- Multiple example use cases
See requirements.txt
for full list of dependencies.
This implementation represents a "pre-agentic" pattern where:
- The LLM is used for recognition and routing
- Tools handle the actual task execution
- The system is deterministic and predictable
It serves as a good foundation for understanding how to build more complex agentic systems.