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

DATATypeDescription
cModelCharacterOllama model name (default "deepseek-r1:14b")
cUrlCharacterAPI URL (default "http://localhost:11434/api/chat")
cSystemPromptCharacterSystem prompt defining agent behavior
aToolsArrayArray of tool definitions for the agent

Methods

MethodDescription
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

Veja Também