TAgent / TOLlama
Fonte: source/classes/tollama.prg
TOLlama: Standalone | TAgent: Uses TOLlama internally
TOLlama provides integration with locally running Ollama LLM models via the Ollama REST API. It supports text prompts, streaming responses, and image analysis (for multimodal models). TAgent builds on TOLlama to create an AI agent that can invoke Harbour Funções as tools, enabling LLM-driven automation.
Key DATA Members
| DATA | Type | Description |
|---|---|---|
cModel | Character | Ollama model name (default "deepseek-r1:14b") |
cUrl | Character | API URL (default "http://localhost:11434/api/chat") |
cSystemPrompt | Character | System prompt defining agent behavior |
aTools | Array | Array of tool definitions for the agent |
Methods
| Method | Description |
|---|---|
New( cModel ) | Create an Ollama client with the specified model |
Send( cPrompt ) | Send a prompt; returns the complete response |
SendStream( cPrompt, bWriteFunction ) | Send with streaming callback for real-time token output |
SendImage( cImageFile, cPrompt ) | Send image + prompt for multimodal models |
GetValue() | Parse JSON response and extract content text |
End() | Clean up the libcurl handle |
SetSystemPrompt( c ) | Set the system prompt for the agent |
AddTool( cName, cDesc, bAction ) | Register a Harbour function as a callable tool |
Run( cPrompt ) | Execute a prompt through the agent; returns result |
Example: Agent with Calculator Tool
#include "FiveWin.ch"
function Main()
local oAgent
oAgent := TAgent():New( "deepseek-r1:14b" )
oAgent:SetSystemPrompt( "You are a helpful assistant." )
oAgent:AddTool( "calculator", "Add two numbers", { |a,b| a + b } )
? oAgent:Run( "What is 123 + 456?" )
return nil
Notes
- TOLlama requires a local Ollama server running on port 11434.
- Uses libcurl (
hbcurl.ch) for HTTP communication with the Ollama API. SendStreamenables incremental display of generated tokens as they arrive.SendImageworks with multimodal models like LLaVA or bakllava.- TAgent organizes tools by category, providing an extensible LLM tool-use framework.