Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ public AgentScopeA2aServer build() {
TransportProperties.builder(TransportProtocol.JSONRPC.asString())
.host(deploymentProperties.host())
.port(deploymentProperties.port())
.path(deploymentProperties.path())
.build());
}
Map<String, TransportWrapperBuilder> allBuilders = loadTransportBuilders();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
import org.slf4j.LoggerFactory;

/**
* Some deployment relative properties, such as server default export port and host.
* Some deployment relative properties, such as server default export port and host and path.
*
* <p>When developers don't specified target {@link TransportProperties}, and want to use default transport, developers
* should create this class and input port at least to make sure AgentScope can generate the url for default transport.
*/
public record DeploymentProperties(String host, int port) {
public record DeploymentProperties(String host, int port, String path) {

private static final Logger log = LoggerFactory.getLogger(DeploymentProperties.class);

Expand All @@ -37,6 +37,8 @@ public static class Builder {

private Integer port;

private String path;

public Builder host(String host) {
this.host = host;
return this;
Expand All @@ -47,6 +49,11 @@ public Builder port(Integer port) {
return this;
}

public Builder path(String path) {
this.path = path;
return this;
}

public DeploymentProperties build() {
if (null == host) {
log.info(
Expand All @@ -61,7 +68,7 @@ public DeploymentProperties build() {
if (null == port) {
throw new IllegalArgumentException("port must be configured.");
}
return new DeploymentProperties(host, port);
return new DeploymentProperties(host, port, path);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,29 @@ class DeploymentPropertiesBuildingTests {
void testBuildWithAllProperties() {
String host = "localhost";
Integer port = 8080;
String path = "/api";

DeploymentProperties deploymentProperties =
new DeploymentProperties.Builder().host(host).port(port).build();
new DeploymentProperties.Builder().host(host).port(port).path(path).build();

assertNotNull(deploymentProperties);
assertEquals(host, deploymentProperties.host());
assertEquals(port, deploymentProperties.port());
assertEquals(path, deploymentProperties.path());
}

@Test
@DisplayName("Should build DeploymentProperties with path only")
void testBuildWithPathOnly() {
Integer port = 8080;
String path = "/api/v1";

DeploymentProperties deploymentProperties =
new DeploymentProperties.Builder().port(port).path(path).build();

assertNotNull(deploymentProperties);
assertEquals(port, deploymentProperties.port());
assertEquals(path, deploymentProperties.path());
}

@Test
Expand Down Expand Up @@ -126,9 +142,10 @@ void testThrowExceptionWhenPortNotSpecified() {
void testBuilderMethodChaining() {
String host = "localhost";
Integer port = 8080;
String path = "/api";

DeploymentProperties.Builder builder = new DeploymentProperties.Builder();
DeploymentProperties.Builder result = builder.host(host).port(port);
DeploymentProperties.Builder result = builder.host(host).port(port).path(path);

assertNotNull(result);
assertSame(builder, result);
Expand All @@ -138,6 +155,7 @@ void testBuilderMethodChaining() {
assertNotNull(deploymentProperties);
assertEquals(host, deploymentProperties.host());
assertEquals(port, deploymentProperties.port());
assertEquals(path, deploymentProperties.path());
}
}

Expand All @@ -150,22 +168,39 @@ class RecordFunctionalityTests {
void testRecordConstructor() {
String host = "localhost";
Integer port = 8080;
String path = "/api";

DeploymentProperties deploymentProperties = new DeploymentProperties(host, port, path);

assertNotNull(deploymentProperties);
assertEquals(host, deploymentProperties.host());
assertEquals(port, deploymentProperties.port());
assertEquals(path, deploymentProperties.path());
}

@Test
@DisplayName("Should create record with null path")
void testRecordConstructorWithNullPath() {
String host = "localhost";
Integer port = 8080;

DeploymentProperties deploymentProperties = new DeploymentProperties(host, port);
DeploymentProperties deploymentProperties = new DeploymentProperties(host, port, null);

assertNotNull(deploymentProperties);
assertEquals(host, deploymentProperties.host());
assertEquals(port, deploymentProperties.port());
assertNull(deploymentProperties.path());
}

@Test
@DisplayName("Should have proper equals and hashCode implementation")
void testEqualsAndHashCode() {
String host = "localhost";
int port = 8080;
String path = "/api";

DeploymentProperties deploymentProperties1 = new DeploymentProperties(host, port);
DeploymentProperties deploymentProperties2 = new DeploymentProperties(host, port);
DeploymentProperties deploymentProperties1 = new DeploymentProperties(host, port, path);
DeploymentProperties deploymentProperties2 = new DeploymentProperties(host, port, path);

assertEquals(deploymentProperties1, deploymentProperties2);
assertEquals(deploymentProperties1.hashCode(), deploymentProperties2.hashCode());
Expand All @@ -176,13 +211,15 @@ void testEqualsAndHashCode() {
void testToString() {
String host = "localhost";
int port = 8080;
String path = "/api";

DeploymentProperties deploymentProperties = new DeploymentProperties(host, port);
DeploymentProperties deploymentProperties = new DeploymentProperties(host, port, path);

String toStringResult = deploymentProperties.toString();
assertNotNull(toStringResult);
assertTrue(toStringResult.contains(host));
assertTrue(toStringResult.contains(Integer.toString(port)));
assertTrue(toStringResult.contains(path));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,10 @@ public AgentScopeA2aServer agentScopeA2aServer(
List<AgentRegistry> agentRegistries,
List<CustomTransportProperties> transportProperties) {
AgentScopeA2aServer.Builder builder = AgentScopeA2aServer.builder(agentRunner);
builder.agentCard(buildConfigurableAgentCard(agentCardProperties));
ConfigurableAgentCard configurableAgentCard =
buildConfigurableAgentCard(agentCardProperties);
DeploymentProperties deploymentProperties = buildDeploymentProperties(environment);
builder.agentCard(configurableAgentCard);
builder.deploymentProperties(deploymentProperties);
builder.agentExecuteProperties(buildAgentExecuteProperties(commonProperties));
transportProperties.stream()
Expand Down Expand Up @@ -188,10 +190,15 @@ private DeploymentProperties buildDeploymentProperties(Environment environment)
environment.getProperty(Constants.DEFAULT_SERVER_EXPORT_PORT, Integer.class, 8080);
String defaultServerExportAddress =
environment.getProperty(Constants.DEFAULT_SERVER_EXPORT_ADDRESS);
String defaultServerExportContextPath =
environment.getProperty(Constants.DEFAULT_SERVER_EXPORT_CONTEXT_PATH);
result.port(defaultServerExportPort);
if (null != defaultServerExportAddress) {
result.host(defaultServerExportAddress);
}
if (null != defaultServerExportContextPath) {
result.path(defaultServerExportContextPath);
}
return result.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@ public class Constants {
public static final String DEFAULT_SERVER_EXPORT_PORT = "server.port";

public static final String DEFAULT_SERVER_EXPORT_ADDRESS = "server.address";

public static final String DEFAULT_SERVER_EXPORT_CONTEXT_PATH = "server.servlet.context-path";
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public TransportProperties toTransportProperties() {
return TransportProperties.builder(TransportProtocol.JSONRPC.asString())
.host(deploymentProperties.host())
.port(deploymentProperties.port())
.path(deploymentProperties.path())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,52 @@ void shouldStartSuccessWithAddressProperties() {
});
}

@Test
void shouldIncludeContextPathInAgentCardUrl() {
WebApplicationContextRunner contextRunner =
new WebApplicationContextRunner()
.withConfiguration(
AutoConfigurations.of(AgentscopeA2aAutoConfiguration.class))
.withBean(
ReActAgent.class,
() -> ReActAgent.builder().name("mockAgent").build())
.withPropertyValues(
"server.address=192.168.1.100",
"server.port=8081",
"server.servlet.context-path=/api");
contextRunner.run(
context -> {
assertThat(context).hasNotFailed();
AgentScopeA2aServer server = context.getBean(AgentScopeA2aServer.class);
AgentCard agentCard = server.getAgentCard();
Assertions.assertEquals("http://192.168.1.100:8081/api", agentCard.url());
// Verify additional interfaces also contain the context-path
assertThat(agentCard.additionalInterfaces()).isNotEmpty();
assertThat(agentCard.additionalInterfaces().get(0).url())
.isEqualTo("http://192.168.1.100:8081/api");
});
}

@Test
void shouldGenerateCorrectUrlWithContextPath() {
WebApplicationContextRunner contextRunner =
new WebApplicationContextRunner()
.withConfiguration(
AutoConfigurations.of(AgentscopeA2aAutoConfiguration.class))
.withBean(
ReActAgent.class,
() -> ReActAgent.builder().name("mockAgent").build())
.withPropertyValues("server.servlet.context-path=/myapp/v1");
contextRunner.run(
context -> {
assertThat(context).hasNotFailed();
AgentScopeA2aServer server = context.getBean(AgentScopeA2aServer.class);
AgentCard agentCard = server.getAgentCard();
// URL should contain the context-path
assertThat(agentCard.url()).contains("/myapp/v1");
});
}

@Test
void shouldCallbackServerReadyListener() {
AgentScopeA2aServer mockServer = mock(AgentScopeA2aServer.class);
Expand Down
Loading