A modern web-based chat application that allows you to interact with AI agents powered by open-source LLMs through Ollama. The agents have access to tools and can perform actions like web browsing.
- π€ AI Agent Integration: Powered by Ollama with configurable open-source models
- π οΈ Native Tool Support: Uses Ollama's built-in tool calling API for reliable function execution
- π¬ Modern Chat UI: Clean, responsive interface with real-time streaming
- π Session Management: Local storage of chat sessions with full history
- π¨ Markdown Support: Rich text rendering with syntax highlighting
- π Tool Visualization: Interactive displays for tool executions and results
- β‘ Streaming Tools: Real-time tool execution with streaming responses
- π³ Docker Ready: Full containerization with Docker Compose
- π Production Ready: Nginx-served frontend with Traefik labels
- Docker and Docker Compose
- At least 4GB RAM for model execution
β‘ New in v2.0: Native Ollama tool calling support! The agent now uses Ollama's built-in function calling API for more reliable and faster tool execution with streaming support.
git clone <your-repo>
cd chat-agent
# Option 1: Create .env file (recommended for development)
cp .env.example .env
# Edit .env with your configuration
# Option 2: Use environment variables directly (recommended for production)
export OLLAMA_URL=http://ollama:11434
# OR
export ZHIPUAI_API_KEY=your_zhipu_api_keydocker-compose up -dThis will start:
- Ollama on port 11434
- Backend API on port 8000
- Frontend on port 3000
# Pull a model (this may take a few minutes)
docker exec ollama ollama pull llama3.2
# Or try other models with tool support:
# docker exec ollama ollama pull llama3.1
# docker exec ollama ollama pull qwen2.5Open your browser and go to http://localhost:3000
You can configure the application using environment variables directly or with a .env file. At minimum, you need one of the following LLM providers:
# For local Ollama instance
OLLAMA_URL=http://ollama:11434
# OR for Zhipu AI cloud service
ZHIPUAI_API_KEY=your_zhipu_api_keyEdit .env to configure additional options:
# LLM Model Configuration
LLM_MODEL=llama3.2 # Choose your model
OLLAMA_URL=http://ollama:11434 # Ollama service URL
CORS_ORIGINS=http://localhost:3000,https://ccoreilly.github.io # Allowed origins
# Agent Configuration
AGENT_TYPE=softcatala_english # Agent type: softcatala_english (default) or softcatala_catalan
# Production (for Traefik)
# TRAEFIK_HOST=your-domain.comThe system supports two different SoftcatalΓ agent types that can be configured using the AGENT_TYPE environment variable:
- System Prompt: English (for better LLM performance)
- Response Language: Catalan only
- Purpose: Optimized SoftcatalΓ assistant with English instructions for better model comprehension
- Best For: Production use with Catalan language support
- System Prompt: Catalan
- Response Language: Catalan only
- Purpose: Fully Catalan SoftcatalΓ assistant
- Best For: Testing prompt effectiveness in Catalan vs English
Usage Examples:
# Use default SoftcatalΓ agent (English prompt, Catalan responses)
AGENT_TYPE=softcatala_english
# Use fully Catalan SoftcatalΓ agent
AGENT_TYPE=softcatala_catalanPopular models you can use:
llama3.1- Latest model with native tool support (4.7GB) βllama3.2- Efficient with tool calling (2.0GB) βqwen2.5- Advanced model with excellent tool support (4.4GB) βmistral- Fast and efficient (4.1GB)codellama- Code-focused (3.8GB)llama2:13b- Larger model for better quality (7.3GB)
β Recommended for tool usage - These models have native training for function calling and provide the best experience with tools.
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Frontend β β Backend β β Ollama β
β (React) βββββΊβ (FastAPI) βββββΊβ (LLM Server) β
β Port 3000 β β Port 8000 β β Port 11434 β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
- Frontend: React TypeScript app with local storage for chat sessions
- Backend: FastAPI server with streaming responses and tool execution
- Agent: LLM integration with tool calling capabilities
- Tools: Extensible system with web browsing tool included
- Ollama: Local LLM server for model inference
GET /- API statusGET /health- Health check with model infoPOST /chat/stream- Streaming chat endpointGET /models- List available models
curl -X POST http://localhost:8000/chat/stream \
-H "Content-Type: application/json" \
-d '{
"messages": [
{"role": "user", "content": "Hello!", "timestamp": "2023-01-01T00:00:00Z"}
],
"session_id": "session-123"
}'- Name:
web_browser - Description: Browse web pages and extract content
- Parameters:
url(required): URL to browseextract_links(optional): Extract links from pagemax_content_length(optional): Limit content length
Note: Tools are now integrated using Ollama's native tool calling API instead of prompt-based approaches, providing better reliability and streaming support.
- Create a new tool class in
backend/tools/:
from .base import BaseTool, ToolDefinition, ToolParameter
class MyCustomTool(BaseTool):
@property
def definition(self) -> ToolDefinition:
return ToolDefinition(
name="my_tool",
description="Description of what the tool does",
parameters=[
ToolParameter(
name="param1",
type="string",
description="Parameter description",
required=True
)
]
)
async def execute(self, **kwargs):
# Tool implementation
return {"result": "success"}- Register the tool in
backend/main.py:
from tools.my_custom_tool import MyCustomTool
my_tool = MyCustomTool()
agent = Agent(tools=[web_browser_tool, my_tool])For development with hot reload:
# Backend
cd backend
pip install -r requirements.txt
uvicorn main:app --reload --port 8000
# Frontend
cd frontend
npm install
npm startchat-agent/
βββ backend/ # FastAPI backend
β βββ main.py # Main application
β βββ agent.py # Agent implementation
β βββ tools/ # Tool implementations
β β βββ base.py # Base tool class
β β βββ web_browser.py # Web browsing tool
β βββ requirements.txt # Python dependencies
β βββ Dockerfile # Backend container
βββ frontend/ # React frontend
β βββ src/
β β βββ components/ # UI components
β β βββ hooks/ # Custom hooks
β β βββ utils/ # Utilities
β β βββ types.ts # TypeScript types
β βββ package.json # Node dependencies
β βββ Dockerfile # Frontend container
βββ docker-compose.yml # Service orchestration
βββ .env.example # Environment template
The services include Traefik labels for production deployment:
# docker-compose.prod.yml
version: '3.8'
services:
frontend:
labels:
- "traefik.enable=true"
- "traefik.http.routers.chat-frontend.rule=Host(`your-domain.com`)"
- "traefik.http.routers.chat-frontend.entrypoints=websecure"
- "traefik.http.routers.chat-frontend.tls.certresolver=letsencrypt"LLM_MODEL=llama3.2
OLLAMA_URL=http://ollama:11434
CORS_ORIGINS=https://your-domain.com
TRAEFIK_HOST=your-domain.com
AGENT_TYPE=softcatala_english-
Ollama not accessible
docker exec ollama ollama list # Check if models are loaded docker logs ollama # Check Ollama logs
-
Frontend can't connect to backend
- Check CORS_ORIGINS in environment
- Verify backend is running on port 8000
-
Model not found
docker exec ollama ollama pull llama3.2 # Pull the model
-
Out of memory
- Try smaller models like
mistral - Increase Docker memory limit
- Try smaller models like
- Use faster models like
mistralfor better response times - Increase model context length for longer conversations
- Use SSD storage for faster model loading
- Fork the repository
- Create a feature branch
- Add your tool or feature
- Submit a pull request
MIT License - see LICENSE file for details