IR
irwinrodriguez.dev
Back to docs

Configuration

Custom tools (UDTs)

FoxAgent supports user-defined tools (UDTs) that your AI agent can invoke. UDTs are VFP classes that inherit from FoxAgentTool and expose parameters and execution logic.

UDT example

* GetSaldoTool.prg - Coloca este archivo en tu carpeta Tools\

DEFINE CLASS GetSaldoTool AS FoxAgentTool

  ToolName = "get_saldo"
  ToolDescription = "Obtiene el saldo de un cliente por su codigo"

  FUNCTION DefineParameters()
    THIS.AddParam("clienteCode", "number", "Codigo del cliente", .T.)
  ENDFUNC

  FUNCTION Execute(toContext)
    LOCAL lnCode, lcResult
    lnCode = THIS.GetParam("clienteCode")
    
    * Tu logica de negocio aqui
    lcResult = "Cliente " + TRANSFORM(lnCode) + ": $1500.00"
    
    RETURN THIS.Ok(lcResult)
  ENDFUNC

ENDDEFINE

Supported parameter types

When defining parameters with AddParam(), you can use the following types:

Type Description Example
"string" Text of any length THIS.AddParam("nombre", "string", "Nombre del cliente", .T.)
"number" Integer or decimal number THIS.AddParam("cantidad", "number", "Cantidad", .T.)
"boolean" Logical value (.T. or .F.) THIS.AddParam("activo", "boolean", "Esta activo?", .F.)
"date" Date (YYYY-MM-DD format) THIS.AddParam("fecha", "date", "Fecha de inicio", .F.)
"object" Complex JSON object THIS.AddParam("filtro", "object", "Filtros avanzados", .F.)

The fourth parameter of AddParam() indicates whether the parameter is required (.T.) or optional (.F.).

Example with multiple parameters

* SearchClientsTool.prg

DEFINE CLASS SearchClientsTool AS FoxAgentTool

  ToolName = "search_clients"
  ToolDescription = "Busca clientes por nombre, codigo postal o saldo minimo"

  FUNCTION DefineParameters()
    THIS.AddParam("searchText", "string", "Texto a buscar en nombre o codigo", .T.)
    THIS.AddParam("postalCode", "string", "Filtrar por codigo postal", .F.)
    THIS.AddParam("minBalance", "number", "Saldo minimo requerido", .F.)
    THIS.AddParam("activeOnly", "boolean", "Solo clientes activos", .F.)
  ENDFUNC

  FUNCTION Execute(toContext)
    LOCAL lcSearch, lcPostal, lnMinBal, llActive
    LOCAL lcQuery, lcResult
    
    lcSearch  = THIS.GetParam("searchText")
    lcPostal  = THIS.GetParam("postalCode")
    lnMinBal  = THIS.GetParam("minBalance")
    llActive  = THIS.GetParam("activeOnly")
    
    * Construir consulta dinamica
    lcQuery = "SELECT * FROM CLIENTES WHERE "
    lcQuery = lcQuery + "(cNombre LIKE '%" + lcSearch + "%' OR cCodigo = '" + lcSearch + "')"
    
    IF !EMPTY(lcPostal)
      lcQuery = lcQuery + " AND cCodPost = '" + lcPostal + "'"
    ENDIF
    
    IF lnMinBal > 0
      lcQuery = lcQuery + " AND nSaldo >= " + TRANSFORM(lnMinBal)
    ENDIF
    
    IF llActive
      lcQuery = lcQuery + " AND lActivo = .T."
    ENDIF
    
    * Ejecutar y retornar resultados
    &lcQuery INTO CURSOR curResult
    
    SELECT * FROM curResult INTO ARRAY laResult
    lcResult = TRANSFORM(ALEN(laResult,1)) + " clientes encontrados"
    
    RETURN THIS.Ok(lcResult)
  ENDFUNC

ENDDEFINE

Automatic discovery

UDTs are automatically loaded from the folder configured with SetToolsFolder(). Just place your .prg files in that folder and FoxAgent will discover them when connecting.

LOCAL loBridge
loBridge = CREATEOBJECT("FoxAgent.Bridge")
loBridge.SetInstance(_VFP)
loBridge.SetToolsFolder("C:\MiProyecto\Tools")  && Scan automatico
loBridge.Connect("mi-app-001", "Mi App", 3)
SDK included The FoxAgent installer includes the base class FoxAgentTool.prg and a template MyToolTemplate.prg in the SDK folder. Copy them to your project as a starting point.

Role system

FoxAgent has 4 permission levels that control which tools your AI agent can use:

Level Name Access
0 Observer Read-only: list instances, view variables, cursors, forms
1 Operator Read + write: set_variable, exec_command, UDTs
2 Developer Operator + get_call_stack, get_object_members, reload_procedure
3 Admin Developer + close_cursors, execute_tool, build_project

The role is set when connecting with Connect(instanceId, displayName, role) and can be changed on-the-fly with set_role.

License

FoxAgent uses validated licenses. Place the foxagent.lic file next to the Broker executable:

# License path
C:\Program Files\FoxAgent\foxagent.lic

# Without license, Broker starts in evaluation mode
Evaluation mode Without a license file, the Broker starts normally in evaluation mode. The license is only required for production use.

Built-in tools

FoxAgent includes 33 built-in tools organized by level:

Inspection (Level 0)

  • list_instances — View connected VFP instances
  • get_variables — Read public variables
  • get_cursors — View open cursors
  • get_cursor_data — Read cursor rows
  • get_active_form — Active form
  • get_form_controls — Form controls
  • take_screenshot — Screenshot
  • eval_expression — Evaluate VFP expression

Execution (Level 1)

  • set_variable — Assign variable
  • exec_command — Execute VFP command
  • set_control_value — Change control value
  • refresh_form — Refresh form

Development (Level 2)

  • get_call_stack — Call stack
  • get_object_members — Object members
  • reload_procedure — Reload PRG
  • run_report — Run report
  • get_project_structure — Project structure
  • get_source_file — Source code
  • build_project — Build project

Admin (Level 3)

  • close_cursors — Close cursors
  • execute_tool — Execute UDT
  • get_tools — Tool list