fix(server): wire tool registry and executor into OrchestratorEngines so LLM receives tool definitions

This commit is contained in:
2026-05-18 22:03:31 +04:00
parent d2518849d7
commit 03615dc5b9
2 changed files with 60 additions and 44 deletions
+3
View File
@@ -27,6 +27,9 @@ dependencies {
implementation project(':infrastructure:inference') implementation project(':infrastructure:inference')
implementation project(':infrastructure:inference:llama_cpp') implementation project(':infrastructure:inference:llama_cpp')
implementation project(':infrastructure:inference:commons') implementation project(':infrastructure:inference:commons')
implementation project(':core:tools')
implementation project(':infrastructure:tools')
implementation project(':infrastructure:tools:filesystem')
implementation "com.github.ajalt.clikt:clikt:5.0.1" implementation "com.github.ajalt.clikt:clikt:5.0.1"
@@ -26,79 +26,92 @@ import com.correx.core.validation.artifact.ArtifactPayloadValidator
import com.correx.core.validation.pipeline.ValidationPipeline import com.correx.core.validation.pipeline.ValidationPipeline
import com.correx.apps.server.logging.LoggingEventStore import com.correx.apps.server.logging.LoggingEventStore
import com.correx.infrastructure.InfrastructureModule import com.correx.infrastructure.InfrastructureModule
import com.correx.infrastructure.artifactscas.DefaultMaterializingArtifactWriter
import com.correx.infrastructure.inference.DefaultProviderRegistry import com.correx.infrastructure.inference.DefaultProviderRegistry
import com.correx.infrastructure.inference.FirstAvailableRoutingStrategy import com.correx.infrastructure.inference.FirstAvailableRoutingStrategy
import com.correx.infrastructure.tools.FileWriteConfig
import com.correx.infrastructure.tools.ShellConfig
import com.correx.infrastructure.tools.ToolConfig
import com.correx.core.events.EventDispatcher
import io.ktor.server.engine.embeddedServer import io.ktor.server.engine.embeddedServer
import io.ktor.server.netty.Netty import io.ktor.server.netty.Netty
import java.nio.file.Paths
fun main() { fun main() {
val artifactStore = InfrastructureModule.createArtifactStore() val artifactStore = InfrastructureModule.createArtifactStore()
val eventStore = LoggingEventStore(InfrastructureModule.createEventStore(artifactStore)) val eventStore = LoggingEventStore(InfrastructureModule.createEventStore(artifactStore))
val infraRegistry = InfrastructureModule.createProviderRegistry(listOf(buildLlamaProvider()))
val llamaProvider = InfrastructureModule.createLlamaCppProvider( val repositories = buildRepositories(eventStore)
modelId = System.getenv("CORREX_MODEL_ID") ?: "default", val approvalEngine = DefaultApprovalEngine()
modelPath = System.getenv("CORREX_MODEL_PATH") ?: "", val sandboxRoot = Paths.get(System.getProperty("user.home"), ".config", "correx", "sandbox")
baseUrl = System.getenv("CORREX_LLAMA_URL") ?: "http://127.0.0.1:10000", val toolRegistry = InfrastructureModule.createToolRegistry(buildToolConfig(artifactStore, sandboxRoot))
) val toolExecutor = InfrastructureModule.createToolExecutor(
val infraRegistry = InfrastructureModule.createProviderRegistry(listOf(llamaProvider)) registry = toolRegistry,
approvalEngine = approvalEngine,
val artifactRepository = InfrastructureModule.createArtifactRepository(eventStore)
val sessionRepository = DefaultSessionRepository(
DefaultEventReplayer(eventStore, SessionProjector(DefaultSessionReducer()))
)
val inferenceRepository = InferenceRepository(
DefaultEventReplayer(eventStore, InferenceProjector())
)
val orchestrationRepository = OrchestrationRepository(
DefaultEventReplayer(eventStore, OrchestrationProjector(DefaultOrchestrationReducer()))
)
val inferenceRouter = DefaultInferenceRouter(infraRegistry, FirstAvailableRoutingStrategy())
val promptLoader = InfrastructureModule.createPromptLoader()
val promptResolver = PromptResolver { path -> promptLoader.load(path) }
val repositories = OrchestratorRepositories(
eventStore = eventStore, eventStore = eventStore,
inferenceRepository = inferenceRepository, eventDispatcher = EventDispatcher(eventStore),
orchestrationRepository = orchestrationRepository, workDir = sandboxRoot,
sessionRepository = sessionRepository,
artifactRepository = artifactRepository,
) )
val engines = OrchestratorEngines( val engines = OrchestratorEngines(
transitionResolver = DefaultTransitionResolver { condition, ctx -> condition.evaluate(ctx) }, transitionResolver = DefaultTransitionResolver { condition, ctx -> condition.evaluate(ctx) },
contextPackBuilder = DefaultContextPackBuilder(DefaultContextCompressor()), contextPackBuilder = DefaultContextPackBuilder(DefaultContextCompressor()),
inferenceRouter = inferenceRouter, inferenceRouter = DefaultInferenceRouter(infraRegistry, FirstAvailableRoutingStrategy()),
validationPipeline = ValidationPipeline(validators = listOf(ArtifactPayloadValidator(artifactStore))), validationPipeline = ValidationPipeline(validators = listOf(ArtifactPayloadValidator(artifactStore))),
approvalEngine = DefaultApprovalEngine(), approvalEngine = approvalEngine,
riskAssessor = DefaultRiskAssessor(), riskAssessor = DefaultRiskAssessor(),
promptResolver = promptResolver, promptResolver = { path -> InfrastructureModule.createPromptLoader().load(path) },
toolRegistry = toolRegistry,
toolExecutor = toolExecutor,
) )
val orchestrator = DefaultSessionOrchestrator( val orchestrator = DefaultSessionOrchestrator(
repositories = repositories, repositories = repositories,
engines = engines, engines = engines,
retryCoordinator = DefaultRetryCoordinator(eventStore), retryCoordinator = DefaultRetryCoordinator(eventStore),
artifactStore = artifactStore, artifactStore = artifactStore,
) )
val workflowRegistry = FileSystemWorkflowRegistry(InfrastructureModule.createWorkflowLoader())
val module = ServerModule( val module = ServerModule(
orchestrator = orchestrator, orchestrator = orchestrator,
eventStore = eventStore, eventStore = eventStore,
sessionRepository = sessionRepository, sessionRepository = repositories.sessionRepository,
workflowRegistry = workflowRegistry, workflowRegistry = FileSystemWorkflowRegistry(InfrastructureModule.createWorkflowLoader()),
providerRegistry = infraRegistry.asServerRegistry(), providerRegistry = infraRegistry.asServerRegistry(),
) )
embeddedServer(Netty, port = 8080) { configureServer(module) }.start(wait = true)
embeddedServer(Netty, port = 8080) {
configureServer(module)
}.start(wait = true)
} }
private fun buildLlamaProvider() = InfrastructureModule.createLlamaCppProvider(
modelId = System.getenv("CORREX_MODEL_ID") ?: "default",
modelPath = System.getenv("CORREX_MODEL_PATH") ?: "",
baseUrl = System.getenv("CORREX_LLAMA_URL") ?: "http://127.0.0.1:10000",
)
private fun buildRepositories(
eventStore: com.correx.core.events.stores.EventStore,
) = OrchestratorRepositories(
eventStore = eventStore,
inferenceRepository = InferenceRepository(DefaultEventReplayer(eventStore, InferenceProjector())),
orchestrationRepository = OrchestrationRepository(
DefaultEventReplayer(eventStore, OrchestrationProjector(DefaultOrchestrationReducer()))
),
sessionRepository = DefaultSessionRepository(
DefaultEventReplayer(eventStore, SessionProjector(DefaultSessionReducer()))
),
artifactRepository = InfrastructureModule.createArtifactRepository(eventStore),
)
private fun buildToolConfig(
artifactStore: com.correx.core.artifactstore.ArtifactStore,
sandboxRoot: java.nio.file.Path,
) = ToolConfig(
shell = ShellConfig(enabled = true),
fileWrite = FileWriteConfig(
enabled = true,
artifactStore = artifactStore,
materializingWriter = DefaultMaterializingArtifactWriter(),
sandboxRoot = sandboxRoot,
),
)
private fun DefaultProviderRegistry.asServerRegistry(): ProviderRegistry = object : ProviderRegistry { private fun DefaultProviderRegistry.asServerRegistry(): ProviderRegistry = object : ProviderRegistry {
override fun listAll() = this@asServerRegistry.listAll() override fun listAll() = this@asServerRegistry.listAll()
override suspend fun healthCheckAll() = this@asServerRegistry.healthCheckAll() override suspend fun healthCheckAll() = this@asServerRegistry.healthCheckAll()