Skip to content

Commit 2e93316

Browse files
authored
Allow configuring custom host in FeatureMessageRemoteServer (#256)
1 parent c31fd5f commit 2e93316

File tree

4 files changed

+28
-15
lines changed

4 files changed

+28
-15
lines changed

agents/agents-core/src/commonMain/kotlin/ai/koog/agents/core/feature/remote/server/config/AIAgentFeatureServerConnectionConfig.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ package ai.koog.agents.core.feature.remote.server.config
33
import ai.koog.agents.core.feature.agentFeatureMessageSerializersModule
44
import ai.koog.agents.features.common.remote.server.config.ServerConnectionConfig
55

6-
public class AIAgentFeatureServerConnectionConfig(port: Int) : ServerConnectionConfig(port) {
6+
/**
7+
* Configuration class for setting up an agent feature server connection.
8+
* Properties:
9+
* host - The host on which the server will listen to.
10+
* port - The port number on which the server will listen to.
11+
*/
12+
public class AIAgentFeatureServerConnectionConfig(host: String, port: Int) :
13+
ServerConnectionConfig(host = host, port = port) {
714

815
init {
916
appendSerializersModule(agentFeatureMessageSerializersModule)

agents/agents-features/agents-features-common/src/commonMain/kotlin/ai/koog/agents/features/common/remote/server/FeatureMessageRemoteServer.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public class FeatureMessageRemoteServer(
8181
return
8282
}
8383

84-
startServer(port = connectionConfig.port)
84+
startServer(host = connectionConfig.host, port = connectionConfig.port)
8585
logger.debug { "Feature Message Remote Server. Initialized successfully on port ${connectionConfig.port}" }
8686

8787
isInitialized = true
@@ -112,9 +112,9 @@ public class FeatureMessageRemoteServer(
112112

113113
//region Private Methods
114114

115-
private fun startServer(port: Int) {
115+
private fun startServer(host: String, port: Int) {
116116
try {
117-
val server = createServer(port = port)
117+
val server = createServer(host = host, port = port)
118118
server.start(wait = false)
119119
}
120120
catch (t: CancellationException) {
@@ -131,12 +131,12 @@ public class FeatureMessageRemoteServer(
131131
}
132132
}
133133

134-
private fun createServer(port: Int): EmbeddedServer<ApplicationEngine, ApplicationEngine.Configuration> {
134+
private fun createServer(host: String, port: Int): EmbeddedServer<ApplicationEngine, ApplicationEngine.Configuration> {
135135

136136
logger.debug { "Feature Message Remote Server. Start creating server on port: $port" }
137137

138138
val factory = engineFactoryProvider()
139-
server = embeddedServer(factory = factory, host = "127.0.0.1", port = port) {
139+
server = embeddedServer(factory = factory, host = host, port = port) {
140140
install(SSE)
141141

142142
routing {

agents/agents-features/agents-features-common/src/commonMain/kotlin/ai/koog/agents/features/common/remote/server/config/ServerConnectionConfig.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,18 @@ import ai.koog.agents.features.common.remote.ConnectionConfig
55
/**
66
* Configuration class for setting up a server connection.
77
*
8+
* @property host The host on which the server will listen to. Defaults to 127.0.0.1 (localhost);
89
* @property port The port number on which the server will listen to. Defaults to 8080;
910
* @property jsonConfig The effective JSON configuration to be used, falling back to a default configuration
1011
* if a custom configuration is not provided;
1112
*/
12-
public abstract class ServerConnectionConfig(public val port: Int = DEFAULT_PORT) : ConnectionConfig() {
13+
public abstract class ServerConnectionConfig(
14+
public val host: String = DEFAULT_HOST,
15+
public val port: Int = DEFAULT_PORT
16+
) : ConnectionConfig() {
1317

1418
private companion object {
1519
private const val DEFAULT_PORT = 8080
20+
private const val DEFAULT_HOST = "127.0.0.1"
1621
}
1722
}

agents/agents-features/agents-features-trace/src/jvmTest/kotlin/ai/koog/agents/features/tracing/writer/TraceFeatureMessageRemoteWriterTest.kt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class TraceFeatureMessageRemoteWriterTest {
2626
companion object {
2727
private val logger = KotlinLogging.logger { }
2828
private val defaultClientServerTimeout = 5.seconds
29+
private val host = "127.0.0.1"
2930
}
3031

3132
private class TestFeatureMessageWriter : FeatureMessageProcessor() {
@@ -43,9 +44,9 @@ class TraceFeatureMessageRemoteWriterTest {
4344
fun `test health check on agent run`() = runBlocking {
4445

4546
val port = findAvailablePort()
46-
val serverConfig = AIAgentFeatureServerConnectionConfig(port = port)
47+
val serverConfig = AIAgentFeatureServerConnectionConfig(host = host, port = port)
4748
val clientConfig =
48-
AIAgentFeatureClientConnectionConfig(host = "127.0.0.1", port = port, protocol = URLProtocol.HTTP)
49+
AIAgentFeatureClientConnectionConfig(host = host, port = port, protocol = URLProtocol.HTTP)
4950

5051
val isServerStarted = CompletableDeferred<Boolean>()
5152
val isClientFinished = CompletableDeferred<Boolean>()
@@ -98,9 +99,9 @@ class TraceFeatureMessageRemoteWriterTest {
9899
val strategyName = "tracing-test-strategy"
99100

100101
val port = findAvailablePort()
101-
val serverConfig = AIAgentFeatureServerConnectionConfig(port = port)
102+
val serverConfig = AIAgentFeatureServerConnectionConfig(host = host, port = port)
102103
val clientConfig =
103-
AIAgentFeatureClientConnectionConfig(host = "127.0.0.1", port = port, protocol = URLProtocol.HTTP)
104+
AIAgentFeatureClientConnectionConfig(host = host, port = port, protocol = URLProtocol.HTTP)
104105

105106
val userPrompt = "Test user prompt"
106107
val systemPrompt = "Test system prompt"
@@ -225,9 +226,9 @@ class TraceFeatureMessageRemoteWriterTest {
225226
val strategyName = "tracing-test-strategy"
226227

227228
val port = findAvailablePort()
228-
val serverConfig = AIAgentFeatureServerConnectionConfig(port = port)
229+
val serverConfig = AIAgentFeatureServerConnectionConfig(host = host, port = port)
229230
val clientConfig =
230-
AIAgentFeatureClientConnectionConfig(host = "127.0.0.1", port = port, protocol = URLProtocol.HTTP)
231+
AIAgentFeatureClientConnectionConfig(host = host, port = port, protocol = URLProtocol.HTTP)
231232

232233
val actualEvents = mutableListOf<FeatureMessage>()
233234

@@ -304,9 +305,9 @@ class TraceFeatureMessageRemoteWriterTest {
304305
val strategyName = "tracing-test-strategy"
305306

306307
val port = findAvailablePort()
307-
val serverConfig = AIAgentFeatureServerConnectionConfig(port = port)
308+
val serverConfig = AIAgentFeatureServerConnectionConfig(host = host, port = port)
308309
val clientConfig =
309-
AIAgentFeatureClientConnectionConfig(host = "127.0.0.1", port = port, protocol = URLProtocol.HTTP)
310+
AIAgentFeatureClientConnectionConfig(host = host, port = port, protocol = URLProtocol.HTTP)
310311

311312
val userPrompt = "Test user prompt"
312313
val systemPrompt = "Test system prompt"

0 commit comments

Comments
 (0)