generated from coulomb/repo-seed
feat: integrate llm-connect FR-1/FR-3/FR-4 into IHF bridge
Some checks failed
Test / test (push) Has been cancelled
Some checks failed
Test / test (push) Has been cancelled
FR-3 (async_execute_prompt): CollectiveProposals now invokes all agents
concurrently via callAgentsBatch → single bridge subprocess with
asyncio.gather. Latency scales with slowest agent, not sum.
FR-4 (BudgetTracker): AgentDelegations passes tokenBudget to bridge;
llm-connect enforces it natively via BudgetTracker in RunConfig.
BudgetExceededError is a first-class BridgeError variant with total/
consumed/requested fields surfaced to the operator.
FR-1 (LLMServer passthrough): bridge accepts optional serverUrl field;
if present, calls POST {serverUrl}/execute instead of spawning a new
adapter. Infrastructure ready for hot-agent pre-warming (no schema
change required).
AgentBridge.hs: adds callAgentsBatch, callAgentWithBudget,
BudgetExceededError constructor, bridgeErrorMessage helper, defaultRequest,
requestToJson. All controllers updated to use bridgeErrorMessage.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,11 +1,16 @@
|
||||
module Web.Controller.AgentDelegations where
|
||||
|
||||
-- IHF Phase 11 — Advanced AI Federation (IHUB-WP-0012 T06)
|
||||
-- Updated: delegation token budget enforced natively by llm-connect BudgetTracker (FR-4).
|
||||
|
||||
import Web.Controller.Prelude
|
||||
import Web.View.AgentDelegations.Index
|
||||
import Web.View.AgentDelegations.Show
|
||||
import Application.Helper.AgentBridge (callBridge, BridgeRequest(..))
|
||||
import Application.Helper.AgentBridge
|
||||
( callAgentWithBudget
|
||||
, BridgeError(..)
|
||||
, bridgeErrorMessage
|
||||
)
|
||||
|
||||
instance Controller AgentDelegationsController where
|
||||
|
||||
@@ -44,24 +49,32 @@ instance Controller AgentDelegationsController where
|
||||
|> set #status "pending"
|
||||
|> createRecord
|
||||
|
||||
result <- liftIO $ callBridge BridgeRequest
|
||||
{ provider = receivingAgent.provider
|
||||
, model = receivingAgent.modelName
|
||||
, systemPrompt = receivingAgent.systemPrompt
|
||||
, prompt = scope
|
||||
, maxTokens = tokenBudget
|
||||
, temperature = 0.7
|
||||
}
|
||||
-- FR-4: token budget passed to bridge → llm-connect BudgetTracker enforces it
|
||||
-- natively, raising LLMBudgetExceededError if the call would exceed the cap.
|
||||
result <- liftIO $ callAgentWithBudget receivingAgent scope tokenBudget 0
|
||||
|
||||
now <- getCurrentTime
|
||||
case result of
|
||||
Left BudgetExceededError { errorMessage, budgetTotal, budgetConsumed, budgetRequested } -> do
|
||||
delegation
|
||||
|> set #status "failed"
|
||||
|> set #result (Just . A.toJSON $ A.object
|
||||
[ "error" A..= errorMessage
|
||||
, "budgetTotal" A..= budgetTotal
|
||||
, "budgetConsumed" A..= budgetConsumed
|
||||
, "budgetRequested" A..= budgetRequested
|
||||
])
|
||||
|> set #completedAt (Just now)
|
||||
|> updateRecord
|
||||
setErrorMessage ("Budget exceeded: requested " <> show budgetRequested
|
||||
<> " tokens but only " <> show (budgetTotal - budgetConsumed) <> " remain")
|
||||
Left err -> do
|
||||
delegation
|
||||
|> set #status "failed"
|
||||
|> set #result (Just . A.toJSON $ A.object ["error" A..= err.errorMessage])
|
||||
|> set #result (Just . A.toJSON $ A.object ["error" A..= bridgeErrorMessage err])
|
||||
|> set #completedAt (Just now)
|
||||
|> updateRecord
|
||||
setErrorMessage ("Delegation failed: " <> err.errorMessage)
|
||||
setErrorMessage ("Delegation failed: " <> bridgeErrorMessage err)
|
||||
Right resp -> do
|
||||
delegation
|
||||
|> set #status "completed"
|
||||
|
||||
Reference in New Issue
Block a user