Class: Assistant::PostgresChatToolBuilder
- Inherits:
-
Object
- Object
- Assistant::PostgresChatToolBuilder
- Defined in:
- app/services/assistant/postgres_chat_tool_builder.rb
Overview
Builds RubyLLM::Tool subclasses for PostgreSQL database access.
Provides execute_sql, schema exploration, and activity notes search.
Named PostgresChatToolBuilder to distinguish from ::PostgresToolBuilder
(MCP server tools in app/mcp/).
Usage (via ChatToolBuilder):
tools = Assistant::PostgresChatToolBuilder.tools(
service_key, role:, allowed_objects:, audit_context:
)
Constant Summary collapse
- TOOL_CONFIG =
{ 'app_db' => { prefix: 'app_db', label: 'App DB' }, 'postgres_versions' => { prefix: 'versions_db', label: 'Versions DB' } }.freeze
- DESCRIBE_SUMMARY_DESC_LIMIT =
Max length of per-object descriptions returned by the no-args summary
of build_describe_available_data_tool. The full description (and per-column
metadata) is available via theview_name:detail call. Truncating here
keeps the initial schema dump small enough that thinking-capable models
don't burn most of their turn duration just reading it
(see Assistant::ToolLoopGuard::MAX_TURN_DURATION). 80
Class Method Summary collapse
Class Method Details
.tools(service_key, role: :employee, allowed_objects: nil, audit_context: {}) ⇒ Object
30 31 32 33 34 35 |
# File 'app/services/assistant/postgres_chat_tool_builder.rb', line 30 def tools(service_key, role: :employee, allowed_objects: nil, audit_context: {}) ao_hash = allowed_objects ? Digest::MD5.hexdigest(allowed_objects.to_a.sort.join(',')) : 'nil' cache_key = "#{service_key}:#{role}:#{ao_hash}:#{audit_context[:conversation_id]}:#{audit_context[:user_id]}" @cache ||= {} @cache[cache_key] ||= build_tools(service_key, role: role, allowed_objects: allowed_objects, audit_context: audit_context) end |