Skip to Content
Internal docs are powered by Nextra Docs Theme.
SystemsRailsAI request inventory

Rails AI Request Inventory

Last audited: 2026-06-20

This inventory tracks AI requests still initiated from rulebase-api Rails. It includes direct OpenAI SDK calls, RubyLLM calls, OpenAI file/vector-store API calls, and Rails-owned calls into Rulebase/Modal ML services. It does not treat plain email template rendering as model inference.

How This Was Audited

Primary searches:

  • OPENAI_CLIENT, DIRECT_OPENAI_CLIENT, OpenAI::Client.new, OpenAI::Client.for_prompt
  • responses.create, responses.stream, chat.completions.create, audio.speech.create, embeddings.create
  • RubyLLM.chat, RubyLLM::Chat.new
  • files.create, files.delete, vector_stores.*
  • TRANSCRIBE_FN, TRANSLATE_FN, REDACT_FN, REDACT_MULTI_TURN_BATCH_FN, EMBED_FN
  • Rulebase::TopicModeling

Shared clients and wrappers:

  • rulebase-api/config/initializers/openai.rb defines DIRECT_OPENAI_CLIENT against https://api.openai.com/v1 and OPENAI_CLIENT against OpenaiConfig.new.uri_base.
  • rulebase-api/lib/open_ai/client.rb adds OpenAI::Client.for_prompt, a Helicone-wrapped client with prompt/environment headers.
  • rulebase-api/lib/open_ai/realtime_client.rb defines a Realtime WebSocket client, but no Rails call sites were found outside that wrapper.
  • rulebase-api/config/initializers/ruby_llm.rb points RubyLLM at the same OpenAI-compatible base URL.
  • rulebase-api/config/initializers/rulebase.rb defines Modal-backed TRANSCRIBE_FN, TRANSLATE_FN, REDACT_FN, REDACT_MULTI_TURN_BATCH_FN, and EMBED_FN.
  • rulebase-api/config/initializers/assembly_ai.rb defines ASSEMBLY_AI, but no Rails call sites were found for it.

Migration Priority

  1. QA evaluation and feedback retrieval: highest volume, customer-facing, and already shaped like API2 agent/run-step work.
  2. Rails agent loops: Sentinel, workflow agents, compliance risk-factor generation, tests/sheets, marketing review.
  3. Translation/transcription/redaction/chunk embedding service calls: Rails still orchestrates them, even when model work is behind Modal services.
  4. Knowledge-base/vector-store lifecycle and retrieval: large surface area, important dependency for QA and agents.
  5. Reports, digests, simulations, and enrichment jobs: useful to migrate, but easier to batch behind stable API2 endpoints.
  6. Deprecated/demo/legacy helpers: prefer pruning before migrating where possible.

1. QA Evaluation And Feedback

AreaRails call sitesRequest typeNotes
Conversation-level QA runnerapp/services/evaluations/conversation_qa_evaluation_runner.rbOPENAI_CLIENT.responses.create with tools and follow-up tool outputsMain customer-facing QA evaluation loop. Uses org evaluation model, reasoning effort, flex service tier, metadata, and tool budget enforcement.
Scorecard criterion evaluationapp/models/qa_agent_evaluation_scorecard_result.rbOPENAI_CLIENT.responses.create for initial/follow-up leaf and parent criterion evaluationHandles KB tool loops and structured AgentCriterionResult / AgentParentCriterionResult.
Criterion-level human feedback expansionapp/models/qa_agent_evaluation_scorecard_criterion_result.rb, app/models/evaluation_scorecard_criterion_result_comment.rbOPENAI_CLIENT.responses.createGenerates expanded comments from human corrections for future evaluation guidance.
Evaluation-level human feedback expansionapp/models/qa_agent_evaluation.rbOPENAI_CLIENT.responses.createGenerates expanded feedback from corrected full QA evaluations.
Feedback vector store uploadapp/models/evaluation_scorecard_criterion_result_comment.rb, app/models/feedback_vector_store.rb, app/models/organization.rbfiles.create, vector_stores.files.create/delete, vector_stores.create/deleteStores expanded feedback in OpenAI vector stores.
Feedback chunk embeddingsapp/models/evaluation_scorecard_criterion_result_comment/chunk_embedding_sync.rb, app/models/qa_agent_evaluation_scorecard_criterion_result/chunk_embedding_sync.rbEMBED_FN.runModal embedding service creates local DocumentChunk rows.
QA retrieval toolsapp/tool_calls/qa_evaluation/ask_feedback_store.rb, app/tool_calls/qa_evaluation/ask_knowledge_base.rb, app/tool_calls/qa_evaluation/ask_feedback_vector_store.rbembeddings.create or KnowledgeBase.askMixed local vector search and OpenAI file-search vector-store retrieval.
Score option justification generationapp/models/scorecard_criterion_score_option_justification_option.rbRubyLLM.chat(...).askGenerates justification options from score options.

2. Translation, Transcription, Redaction, Embedding Services

AreaRails call sitesRequest typeNotes
Conversation translationapp/models/conversation/translation_event.rb, app/jobs/translate_conversation_job.rbTRANSLATE_FN.runRails builds utterance/key-phrase payloads, calls Modal translation, writes text_english / body_english, and tracks credits.
Call transcriptionapp/models/conversation_part_call_detail/transcription/service.rb, app/jobs/transcribe_conversation_part_call_detail_job.rb, app/jobs/transcribe_conversation_job.rb, app/jobs/process_qa_evaluation_request_job.rbTRANSCRIBE_FN.runProvider currently passed as elevenlabs; Rails manages recordings, expected languages, transcript messages, credits, and downstream CX risk.
Single-text redactionapp/models/conversation.rb, app/models/organization/redaction.rbREDACT_FN.runPresidio-backed service call for PII redaction.
Multi-turn/batch redactionapp/models/conversation/redaction_event.rbREDACT_MULTI_TURN_BATCH_FN.runHandles call transcript messages plus other text parts in one redaction request.
Chunk embeddingsapp/models/knowledge_base_document/chunk_embedding_sync.rb, app/models/evaluation_scorecard_criterion_result_comment/chunk_embedding_sync.rb, app/models/qa_agent_evaluation_scorecard_criterion_result/chunk_embedding_sync.rbEMBED_FN.runProduces chunk embeddings for local nearest-neighbor search.
Topic modelingapp/models/organization.rb, app/models/complaint_report.rbRulebase::TopicModeling.analyzeClusters unassigned product/service issues and complaints.

3. Knowledge Base And OpenAI Vector Stores

AreaRails call sitesRequest typeNotes
Vector-store creation/deletionapp/models/organization.rb, app/models/knowledge_base.rb, app/models/framework.rb, maintenance tasksvector_stores.create/deleteCreates KB, feedback, framework, and compliance-policy stores.
KB queryapp/models/knowledge_base.rb, app/controllers/knowledge_base_responses_controller.rb, app/models/framework.rb, app/models/organization.rb, app/models/compliance_profile.rb, app/models/workflow_node/run/ask_knowledge_base.rb, app/tool_calls/compliance_agent/search_framework_documents.rb, app/tool_calls/marketing_review/search_framework_documents.rb, app/models/sentinel_conversation_message/tools/search_policies.rbresponses.create / responses.stream with file_searchCentral wrapper used by QA, compliance agents, Sentinel tools, workflow KB tools, and direct KB responses.
KB document uploadapp/models/knowledge_base_document.rb, app/models/procedure.rb, app/models/framework_document.rbfiles.create, vector_stores.files.create/delete, files.deleteSyncs KB/procedure/framework content to OpenAI vector stores.
Compliance policy uploadapp/models/compliance_policy.rb, app/jobs/delete_compliance_policy_from_openai_job.rbfiles.create/delete, vector_stores.files.create/deleteUploads policy files, links them to compliance policy vector store, and extracts titles.
KB crawler extractionapp/models/knowledge_base_crawl_task.rb, app/models/framework_document/scraper.rbOpenAI::Client.for_prompt(...).responses.createExtracts article content from raw HTML and decides crawl links.
Vector-store maintenanceapp/tasks/maintenance/rebuild_knowledge_base_vector_store_task.rb, backfill_knowledge_base_document_* tasksvector_stores.create, vector_stores.files.updateRebuilds/stamps vector store metadata.

4. Compliance, Risk, Complaints, Disputes

AreaRails call sitesRequest typeNotes
CX risk snapshotsapp/models/conversation_cx_risk_snapshot.rb, app/models/conversation.rbOpenAI::Client.for_prompt(...).responses.create, embeddings.createConversation risk summary/classification and embeddings.
Complaint detection/follow-upapp/models/evaluation_check/checks/complaint.rbresponses.createChecks whether a conversation contains a complaint and whether it follows up an existing complaint.
Customer issue detection/assignmentapp/models/evaluation_check/checks/customer_issue.rb, app/models/customer_issue.rb, app/models/conversation.rbresponses.create, embeddings.createGenerates issue summaries, embeds descriptions, labels clusters, and assigns conversations to issue categories.
Complaint/customer issue themesapp/models/complaint_theme_snapshot.rb, app/models/customer_issue_theme_snapshot.rb, report generatorsresponses.createLabels clusters and writes theme snapshot analysis.
Compliance rules and criteriaapp/models/compliance_rule_document.rb, app/models/compliance_criterion_group.rb, app/models/compliance_review.rb, app/models/compliance_review/upload_file/plain_text.rbresponses.createChecks rules, reviews criterion groups, extracts text from uploaded plain text, summarizes compliance reviews.
Compliance agentapp/models/compliance_agent.rb, app/tool_calls/compliance_agent/query_program_documents.rbresponses.create, responses.stream, files.create/deleteGenerates program setup, risk factors, test question polarity, uploads generation files, and queries program documents.
Compliance policiesapp/models/compliance_policy.rbresponses.create, files/vector-store APIsExtracts policy titles and stores policy documents.
Disputesapp/models/dispute.rbOpenAI::Client.for_prompt(...).responses.createChecks dispute acknowledgement in transcript.
Scoring guidesapp/models/scoring_guide.rbresponses.create, files.create/deleteRates conversations against scoring guides, optionally with uploaded content files.
Customer sentimentapp/models/conversation_customer_sentiment_summary.rbOPENAI_CLIENT.responses.createCalculates sentiment score and summary for notifications.
QA risk summariesapp/models/organization_risk_level_configuration.rbresponses.createSummarizes QA risk from score/results/transcript.
Knowledge gap reportsapp/models/agent_knowledge_gap_report.rb, app/models/workflow_node/run/agent/tools/knowledge_base_gaps.rbresponses.createGenerates weekly knowledge gaps from evaluation evidence.

5. Rails Agents, Workflows, Sheets, Tests, Marketing Review

AreaRails call sitesRequest typeNotes
Sentinel conversationsapp/models/sentinel_conversation.rb, app/models/sentinel_conversation_message.rb, app/jobs/upload_sentinel_conversation_message_attachment_to_openai_job.rbconversations.create, responses.create/stream, files.createDirect streaming agent loop with tools and OpenAI conversation state.
Sentinel helpersapp/models/sentinel_report.rb, app/models/sentinel_conversation_message/functions/check_customer_request.rb, preview_upload.rb, tools/search_policies.rbchat.completions.create, KnowledgeBase.askReport generation, upload parsing, request checking, and policy search.
Workflow executionapp/models/workflow_run.rb, app/models/workflow_node/run/agent.rbRubyLLM::Chat.new, RubyLLM.chat, responses.createOld and new workflow agent runtimes still run from Rails.
Jira workflow nodesapp/models/workflow_node/run/create_jira_issue_comment.rb, create_jira_issue_from_ticket.rbOPENAI_CLIENT.responses.createGenerates Jira comments and issue payloads from ticket context.
Workflow email ingestionapp/mailboxes/workflow_mailbox.rbOPENAI_CLIENT.responses.createGenerates synthetic content for workflow-trigger emails.
Marketing reviewapp/models/marketing_review.rbfiles.create/delete, responses.create with toolsFile/image review agent loop.
Test report generationapp/models/test_report.rbDIRECT_OPENAI_CLIENT.responses.streamStreams report generation with tools.
Test row and sheet fillapp/models/test_row.rb, app/models/sheet.rbresponses.create with toolsFills test/sheet columns with LLM tool loops.
Image analysislib/image_analysis/vision_analyzer.rb, app/models/conversation_part.rbresponses.create with image inputsGeneric workflow vision analysis and image caption generation.
Page AI writeapp/models/page.rbOPENAI_CLIENT.responses.createGenerates page text edits.

6. Simulations And Voice/Call Demos

AreaRails call sitesRequest typeNotes
Simulation runtimeapp/models/simulation.rbconversations.create, responses.create, responses.stream, embeddings.create, files.createLarge direct surface: persona/scenario/setup generation, simulated conversation, agent feedback, report evaluation, scorecard criterion evaluation, KB embeddings, matched ticket planning/distillation, document scenario handling.
Simulation setup runapp/models/simulation_generate_setup_run.rbOPENAI_CLIENT.responses.createGenerates combined setup payload with structured schema.
Call scenario personasapp/models/call_scenario_persona.rbaudio.speech.create, chat.completions.createGenerates sample introduction text and OpenAI TTS audio.
Demo conversation generatorlib/demo_conversation_generator.rbDIRECT_OPENAI_CLIENT.chat.completions.createGenerates demo conversations.

7. Reports And Digests

AreaRails call sitesRequest typeNotes
Report generator baseapp/models/report/generators/base.rbOPENAI_CLIENT.responses.createShared helper for report generators.
Report generatorsagent_performance.rb, compliance.rb, customer_insights.rb, complaint_theme_snapshot.rb, customer_issue_theme_snapshot.rb, weekend_recap.rbresponses.createCompliance/customer insights generators are marked deprecated in favor of DigestEmail, but still contain direct calls.
Agent performance reportsapp/models/agent_performance_report.rbOPENAI_CLIENT.responses.createGenerates report summary, trends, and coaching content.
Digest agent runnerapp/models/digest_email/agent_runner.rbRubyLLM.chat(...).with_tools(...).askCustomer insights digest agent with tool calls to create/read digest data.
Digest supervisor reviewapp/models/digest_email/supervisor_review.rbOpenAI::Client.for_prompt(...).responses.createReviews generated digest content and returns JSON verdict.
Digest grouping and quotesapp/models/digest_email/issue_category_grouper.rb, app/models/digest_email/tools/get_conversation_details.rbRubyLLM.chat(...).askGenerates category labels and relevant customer quotes.

8. Conversation Enrichment, Filters, And Legacy Helpers

AreaRails call sitesRequest typeNotes
Language detectionapp/models/conversation.rbOpenAI::Client.new.responses.createDetects language from conversation text. Uses a direct OpenAI::Client.new, not the shared configured constants.
Call script adherence and agent summaryapp/models/conversation.rbOPENAI_CLIENT.responses.createReviews call-script adherence and generates agent-facing summary.
Conversation context and live summaryapp/models/conversation.rbchat.completions.createPrevious-conversation context and live summary/action suggestions.
Related conversation and issue assignmentapp/models/conversation.rbOpenAI::Client.new.responses.createIdentifies follow-up conversations and selects best customer issue.
Jira issue draft suggestionsapp/models/conversation.rbOpenAI::Client.new.responses.createSuggests Jira workflow actions from ticket transcript.
Conversation filtersapp/models/conversation_filter.rbOPENAI_CLIENT.responses.createGenerates filter names and checks whether conversations match filters.
Call and call script legacy modelsapp/models/call.rb, app/models/call_script.rb, app/models/call_script_guideline.rbchat.completions.create, embeddings.createRisk summaries, script previews, and guideline embeddings. CallScript is deprecated.
Risk/social summariesapp/models/customer_account.rb, app/models/location.rb, app/models/social_media_post.rbchat.completions.createLegacy risk/social monitoring summaries.
Braintrust smoke testlib/tasks/test_braintrust.rakechat.completions.createRake task only.

Cleanup Notes

  • Several paths still use chat.completions.create; new migrations should probably land on API2 Responses/AI SDK patterns instead of preserving Chat Completions.
  • Conversation, ConversationPart, Sheet, and TestRow instantiate direct clients (OpenAI::Client.new or local constants) instead of consistently using Rails’ configured OPENAI_CLIENT/DIRECT_OPENAI_CLIENT.
  • ASSEMBLY_AI is configured but appears unused by Rails.
  • OpenAI::RealtimeClient is defined but appears unused by Rails.
  • Deprecated surfaces worth pruning before migration: CallScript, legacy Report::Generators::Compliance, and legacy Report::Generators::CustomerInsights.
  • OpenAI vector-store/file lifecycle is deeply coupled to Rails models. Moving generation to API2 without deciding vector-store ownership will leave Rails with many non-generation OpenAI API calls.
Last updated on