-
Notifications
You must be signed in to change notification settings - Fork 1
Introduce config.ai_call: pluggable AI surface (messages-array) #122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
HamptonMakes
merged 2 commits into
hampton/coplan-23/remove-review-bots
from
hampton/coplan-23/ai-call-abstraction
Jun 2, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,61 @@ | ||
| module CoPlan | ||
| # Provider-agnostic facade for AI calls where the caller doesn't care | ||
| # which underlying provider runs the prompt. Use this from any place | ||
| # that just wants "an AI" (e.g. SummarizePlanJob). | ||
| # Provider-agnostic facade for single-shot AI completions. Delegates to | ||
| # `CoPlan.configuration.ai_call` — a callable the host wires up — so the | ||
| # engine never needs to know which model, provider, or LLM gateway is | ||
| # actually serving the request. | ||
| # | ||
| # The provider chosen here is an implementation detail; swap it without | ||
| # touching callers. Raises CoPlan::Ai::Error on provider failure so | ||
| # callers can `discard_on` without knowing which provider is in use. | ||
| # ## Usage | ||
| # | ||
| # # Convenience sugar (90% case): | ||
| # CoPlan::Ai.call(system: "You are concise.", user: "Hi") | ||
| # | ||
| # # General form (multi-turn, future-proof): | ||
| # CoPlan::Ai.call(messages: [ | ||
| # { role: :system, content: "You are concise." }, | ||
| # { role: :user, content: "Hi" }, | ||
| # { role: :assistant, content: "Hello." }, | ||
| # { role: :user, content: "Capital of France?" }, | ||
| # ]) | ||
| # | ||
| # The messages array is the canonical wire format every provider speaks | ||
| # (OpenAI chat completions, Anthropic messages, Gondola, Bedrock, etc.), | ||
| # so the host's `ai_call` lambda can pass it straight through with zero | ||
| # translation. | ||
| # | ||
| # ## Errors | ||
| # | ||
| # Any exception raised inside the configured `ai_call` is wrapped in | ||
| # CoPlan::Ai::Error, so callers can `discard_on CoPlan::Ai::Error` | ||
| # without coupling to the underlying provider. | ||
| # | ||
| # When a host has explicitly disabled AI by setting | ||
| # `config.ai_call = nil`, raises CoPlan::Ai::NoProviderError (a subclass | ||
| # of Error) so jobs still `discard_on` cleanly. | ||
| module Ai | ||
| class Error < StandardError; end | ||
| class NoProviderError < Error; end | ||
|
|
||
| def self.call(messages: nil, system: nil, user: nil) | ||
| messages ||= [ | ||
| ({ role: :system, content: system } if system), | ||
| ({ role: :user, content: user } if user), | ||
| ].compact | ||
|
|
||
| if messages.empty? | ||
| raise ArgumentError, "CoPlan::Ai.call requires `messages:`, or `system:` and/or `user:`" | ||
| end | ||
|
|
||
| callable = CoPlan.configuration.ai_call | ||
| unless callable | ||
| raise NoProviderError, | ||
| "No AI provider configured. Set CoPlan.configuration.ai_call in your host initializer." | ||
| end | ||
|
|
||
| def self.call(system_prompt:, user_content:) | ||
| AiProviders::OpenAi.call(system_prompt: system_prompt, user_content: user_content) | ||
| rescue AiProviders::OpenAi::Error => e | ||
| raise Error, e.message | ||
| begin | ||
| callable.call(messages: messages) | ||
| rescue => e | ||
| raise Error, e.message | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The in-repo host guide still instructs hosts to set
config.ai_api_key/config.ai_modelandconfig.ai_base_url(docs/HOST_APP_GUIDE.mdlines 66-68 and 140-142). After these accessors are removed, any host initializer following the current docs or upgrading before migrating toconfig.ai_callwill raiseNoMethodErrorduring boot, before the app can start. Either keep deprecated setters as compatibility shims or update the documented migration path in this change.Useful? React with 👍 / 👎.