Aggiungi documentazione OllamaToolAgent con tool calling

This commit is contained in:
opencode committed 2026-03-23 19:14:11 +01:00
1 parent f9def3e389
commit 4fef38b740
1 file changed
+111
+111
View File
@@ -802,6 +802,117 @@ Gli strumenti Ollama specifici sono ancora disponibili per retrocompatibilità:
- `ollama_status`: Controlla se Ollama è in esecuzione
- `ollama_running_models`: Mostra i modelli attualmente in esecuzione
## Ollama Agent con Tool Calling
LangCode Agent include `OllamaToolAgent` che supporta il tool calling per modelli Ollama locali senza bisogno di API keys esterne.
### Caratteristiche Principali
- **Tool calling locale**: Nessuna dipendenza da API esterne
- **Intent detection**: Riconosce automaticamente le intenzioni dell'utente
- **Strumenti built-in**: Sistema, filesystem, ricerca, esecuzione comandi
- **Supporto multilingua**: Pattern in italiano e inglese
### Strumenti Disponibili
| Strumento | Descrizione | Esempio |
|-----------|-------------|---------|
| `system_info` | Informazioni di sistema (OS, Python, directory, utente) | "Che OS stai usando?" |
| `ls` | Lista file in una directory | "Cosa c'è in questa cartella?" |
| `read_file` | Leggi il contenuto di un file | "Leggi il file requirements.txt" |
| `write_file` | Scrivi contenuto in un file | "Scrivi un file test.txt con dentro 'Hello'" |
| `search` | Cerca file per pattern | "Cerca i file *.py" |
| `execute` | Esegui comandi shell | "ls -lha", "git status" |
### Pattern di Intent Detection
L'agent riconosce automaticamente le intenzioni basandosi su parole chiave:
**System Info:**
- "sistema operativo", "che OS", "che sistema"
- "system info", "what os", "operating system"
**Lista File:**
- "lista file", "mostrami", "cosa c'è"
- "list files", "show me", "ls"
**Leggi File:**
- "leggi", "leggere", "mostrami il file"
- "read", "show me", "open"
**Scrivi File:**
- "scrivi", "crea", "salva"
- "write", "create", "save"
**Cerca File:**
- "cerca", "trova"
- "search", "find"
**Esegui Comandi:**
- Comandi shell con argomenti: `ls -lha`, `git status`, `cat file.txt`
- "esegui", "run", "comando"
### Esempi di Utilizzo
```
👤 You: Che OS stai usando?
🤖 LangCode: OS: Linux 5.15.0, Python: 3.12.0, Current dir: /home/user, User: user
👤 You: Cosa c'è in questa cartella?
🤖 LangCode: FILE: main.py
FILE: requirements.txt
DIR: tests
👤 You: Leggi il file requirements.txt
🤖 LangCode: langchain>=0.3.0
requests>=2.31.0
...
👤 You: Scrivi un file test.txt con dentro "Hello World"
🤖 LangCode: Successfully wrote to test.txt
👤 You: Cerca i file *.py
🤖 LangCode: Found 15 matches:
main.py
utils.py
...
👤 You: ls -lha
🤖 LangCode: STDOUT:
-rw-r--r-- 1 user 11 Mar 23 test.txt
```
### Configurazione
L'OllamaToolAgent viene caricato automaticamente quando usi Ollama come provider:
```bash
# Configura Ollama
langcode config add -n ollama -p ollama -m qwen3.5:4b -u http://192.168.0.50:11434 --set-active
# Avvia l'agent
langcode
# Oppure direttamente
python langcode.py
```
### Struttura del Codice
```python
# ollama_agent.py
from langcode_agent.ollama_agent import create_ollama_tool_agent
# Crea l'agent con tool integrati
agent = create_ollama_tool_agent(
model=llm,
include_builtin_tools=True # system_info, ls, read_file, etc.
)
# Usa l'agent
result = agent.invoke({"messages": [HumanMessage(content="Che OS usi?")]})
```
## Sistema di Plugin
LangCode Agent include un sistema di plugin per estendere le funzionalità.