AgentApp
public class AgentApp
io/agentscope/runtime/app/AgentApp.java:81–616智能体应用,承载智能体的部署、调度与服务化运行。位于 io.agentscope.runtime.app 包。核心成员包括 endpointPath、host、port、stream、responseType、deployManager。
AgentApp class represents an application that runs as an agent.
This class serves as the server startup entry point for starting Spring Boot Server, assembling configuration and components (Controller/Endpoint, etc.), and initializing Runner (which proxies AgentAdapter).
Key responsibilities:
-
Initialize Runner with AgentAdapter
-
Start Spring Boot Server via DeployManager
-
Manage application lifecycle
-
Configure endpoints and protocols
Usage example:
`AgentAdapter adapter = new AgentScopeAgentAdapter(...);
AgentApp app = new AgentApp(adapter);
app.deployManager(localDeployManager);
app.run("0.0.0.0", 8090);
`
嵌套类摘要Nested Class Summary
| 类Class | 类型Kind | 说明Description |
|---|---|---|
EndpointInfo | 类class | 端点信息,承载智能体的部署、调度与服务化运行。 Endpoint information. |
ComponentProvider | 接口interface | 定义 Component 提供者契约的接口。 An interface in io.agentscope.runtime.app that defines the contract for components that deploys, schedules and serves agents. |
StateServiceProvider | 接口interface | 定义状态服务提供者契约的接口。 An interface in io.agentscope.runtime.app that defines the contract for components that deploys, schedules and serves agents. |
SessionHistoryServiceProvider | 接口interface | 定义会话历史服务提供者契约的接口。 An interface in io.agentscope.runtime.app that defines the contract for components that deploys, schedules and serves agents. |
MemoryServiceProvider | 接口interface | 定义记忆服务提供者契约的接口。 An interface in io.agentscope.runtime.app that defines the contract for components that deploys, schedules and serves agents. |
SandboxServiceProvider | 接口interface | 定义沙箱服务提供者契约的接口。 An interface in io.agentscope.runtime.app that defines the contract for components that deploys, schedules and serves agents. |
AgentHandlerProvider | 接口interface | 定义智能体处理器提供者契约的接口。 An interface in io.agentscope.runtime.app that defines the contract for components that deploys, schedules and serves agents. |
ServiceComponentManager | 类class | 服务 Component 管理器,承载智能体的部署、调度与服务化运行。 A class in io.agentscope.runtime.app that deploys, schedules and serves agents. |
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
public AgentApp(String[] args) | 初始化 `AgentApp` 实例。 Constructor with command line arguments |
public AgentApp(AgentHandler adapter) | 初始化 `AgentApp` 实例。 Constructor with AgentAdapter and Celery configuration. |
方法摘要Method Summary
构造器详情Constructor Detail
AgentApp
public AgentApp(String[] args)
初始化 AgentApp 实例。
Constructor with command line arguments
| 名称Name | 类型Type | 说明Description |
|---|---|---|
args | String[] | 参数(类型 `String[]`)。Command line arguments |
io/agentscope/runtime/app/AgentApp.java:115–174AgentApp
public AgentApp(AgentHandler adapter)
初始化 AgentApp 实例。
Constructor with AgentAdapter and Celery configuration.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
adapter | AgentHandler | AgentAdapter 实例到使用。the AgentAdapter instance to use |
io/agentscope/runtime/app/AgentApp.java:244–253方法详情Method Detail
endpointPath
public AgentApp endpointPath(String endpointPath)
设置端点路径用于智能体服务。
Set the endpoint path for the agent service.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
endpointPath | String | 端点路径(类型 `String`)。the endpoint path (default: "/process") |
AgentAppio/agentscope/runtime/app/AgentApp.java:261–264host
public AgentApp host(String host)
设置该参数。
Set the host address to bind to.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
host | String | host(类型 `String`)。the host address (default: "0.0.0.0") |
AgentAppio/agentscope/runtime/app/AgentApp.java:272–275port
public AgentApp port(int port)
设置该参数。
Set the port number to serve on.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
port | int | port(类型 `int`)。the port number (default: 8090) |
AgentAppio/agentscope/runtime/app/AgentApp.java:283–286stream
public AgentApp stream(boolean stream)
设置流。
Set whether to enable streaming responses.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
stream | boolean | 流(类型 `boolean`)。true to enable streaming (default: true) |
AgentAppio/agentscope/runtime/app/AgentApp.java:294–297responseType
public AgentApp responseType(String responseType)
设置响应类型。
Set the response type.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
responseType | String | 响应类型:"SSE","JSON",或"文本"(默认:"SSE")。the response type: "sse", "json", or "text" (default: "sse") |
AgentAppio/agentscope/runtime/app/AgentApp.java:305–308deployManager
public AgentApp deployManager(DeployManager deployManager)
设置DeployManager 到使用用于部署。
Set the DeployManager to use for deployment.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
deployManager | DeployManager | DeployManager 实例。the DeployManager instance |
AgentAppio/agentscope/runtime/app/AgentApp.java:316–319cors
public AgentApp cors(Consumer<CorsRegistry> corsConfigurer)
设置该参数。
Configure Cross-Origin Resource Sharing (CORS).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
corsConfigurer | Consumer<CorsRegistry> | cors Configurer(类型 `Consumer`)。consumer to customize `CorsRegistry` |
AgentAppio/agentscope/runtime/app/AgentApp.java:335–338buildRunner
public synchronized AgentApp buildRunner()
构建运行器。
Build the Runner instance by proxying the AgentAdapter.
AgentAppio/agentscope/runtime/app/AgentApp.java:347–353getRunner
public Runner getRunner()
获取运行器实例。
Get the Runner instance.
Runnerio/agentscope/runtime/app/AgentApp.java:360–362query
public AgentApp query(String framework, Function<Map<String, Object>, Object> handler)
执行查询相关操作。
Register a query handler with optional framework type.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
framework | String | framework(类型 `String`)。the framework type (must be one of: agentscope, saa, langchain4j) |
handler | Function<Map<String, Object>, Object> | 处理器(类型 `Function , Object>`)。the query handler function that takes a request map and returns a response |
AgentAppIllegalArgumentException可能抛出 `IllegalArgumentException`。if framework type is not supported
io/agentscope/runtime/app/AgentApp.java:386–400query
public AgentApp query(java.util.function.Function<Map<String, Object>, Object> handler)
设置查询。
Register a query handler with default framework type ("agentscope").
| 名称Name | 类型Type | 说明Description |
|---|---|---|
handler | java.util.function.Function<Map<String, Object>, Object> | 查询处理器函数。the query handler function |
AgentAppio/agentscope/runtime/app/AgentApp.java:408–410run
public void run()
执行运行相关操作。
Run the application by starting the Spring Boot Server.
IllegalStateException当if DeployManager是不设置时抛出 `IllegalStateException`。if DeployManager is not set
io/agentscope/runtime/app/AgentApp.java:424–426run
public void run(int port)
设置运行。
Performs the run operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
port | int | port(类型 `int`)。The port. |
io/agentscope/runtime/app/AgentApp.java:428–430run
public void run(String host, int port)
执行运行相关操作。
Run the application with specified host and port.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
host | String | host(类型 `String`)。the host address to bind to |
port | int | port(类型 `int`)。the port number to serve on |
IllegalStateException当if DeployManager是不设置时抛出 `IllegalStateException`。if DeployManager is not set
io/agentscope/runtime/app/AgentApp.java:440–457endpoint
public AgentApp endpoint(String path, List<String> methods, Function<Map<String, Object>, Object> handler)
执行端点相关操作。
Register custom endpoint.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
path | String | 路径(类型 `String`)。The path. |
methods | List<String> | methods(类型 `List`)。The methods. |
handler | Function<Map<String, Object>, Object> | 处理器(类型 `Function , Object>`)。The handler. |
AgentAppio/agentscope/runtime/app/AgentApp.java:462–474getEndpointPath
public String getEndpointPath()
获取端点路径。
Returns the endpoint path.
Stringio/agentscope/runtime/app/AgentApp.java:477–479setEndpointPath
public void setEndpointPath(String endpointPath)
设置端点路径。
Sets the endpoint path.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
endpointPath | String | 端点路径(类型 `String`)。The endpoint path. |
io/agentscope/runtime/app/AgentApp.java:481–483getHost
public String getHost()
获取 getHost。
Returns the host.
Stringio/agentscope/runtime/app/AgentApp.java:485–487getPort
public int getPort()
获取 getPort。
Returns the port.
intio/agentscope/runtime/app/AgentApp.java:489–491getResponseType
public String getResponseType()
获取响应类型。
Returns the response type.
Stringio/agentscope/runtime/app/AgentApp.java:493–495setResponseType
public void setResponseType(String responseType)
设置响应类型。
Sets the response type.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
responseType | String | 响应类型(类型 `String`)。The response type. |
io/agentscope/runtime/app/AgentApp.java:497–499isStream
public boolean isStream()
判断是否流。
Returns whether the stream.
booleanio/agentscope/runtime/app/AgentApp.java:501–503setStream
public void setStream(boolean stream)
设置流。
Sets the stream.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
stream | boolean | 流(类型 `boolean`)。The stream. |
io/agentscope/runtime/app/AgentApp.java:505–507getCustomEndpoints
public List<EndpointInfo> getCustomEndpoints()
获取 getCustomEndpoints。
Returns the custom endpoints.
List<EndpointInfo>io/agentscope/runtime/app/AgentApp.java:509–511port
protected int port(Object value, int defaultValue)
执行 port 方法。
Performs the port operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
value | Object | 值(类型 `Object`)。The value. |
defaultValue | int | 默认值(类型 `int`)。The default value. |
intio/agentscope/runtime/app/AgentApp.java:527–533嵌套类详情Nested Class Detail
EndpointInfo
public static class EndpointInfo端点信息,承载智能体的部署、调度与服务化运行。位于 io.agentscope.runtime.app 包。核心成员包括 path、handler、methods。
Endpoint information.
ComponentProvider
public interface ComponentProvider<T>定义 Component 提供者契约的接口。位于 io.agentscope.runtime.app 包。核心成员包括 get。
An interface in io.agentscope.runtime.app that defines the contract for components that deploys, schedules and serves agents. Declared in io.agentscope.runtime.app.
StateServiceProvider
@FunctionalInterface public interface StateServiceProvider extends ComponentProvider<StateService>定义状态服务提供者契约的接口。位于 io.agentscope.runtime.app 包,实现 ComponentProvider<StateService>。核心成员包括 get。
An interface in io.agentscope.runtime.app that defines the contract for components that deploys, schedules and serves agents. Declared in io.agentscope.runtime.app. Implements ComponentProvider
SessionHistoryServiceProvider
@FunctionalInterface public interface SessionHistoryServiceProvider extends ComponentProvider<SessionHistoryService>定义会话历史服务提供者契约的接口。位于 io.agentscope.runtime.app 包,实现 ComponentProvider<SessionHistoryService>。核心成员包括 get。
An interface in io.agentscope.runtime.app that defines the contract for components that deploys, schedules and serves agents. Declared in io.agentscope.runtime.app. Implements ComponentProvider
MemoryServiceProvider
@FunctionalInterface public interface MemoryServiceProvider extends ComponentProvider<MemoryService>定义记忆服务提供者契约的接口。位于 io.agentscope.runtime.app 包,实现 ComponentProvider<MemoryService>。核心成员包括 get。
An interface in io.agentscope.runtime.app that defines the contract for components that deploys, schedules and serves agents. Declared in io.agentscope.runtime.app. Implements ComponentProvider
SandboxServiceProvider
@FunctionalInterface public interface SandboxServiceProvider extends ComponentProvider<SandboxService>定义沙箱服务提供者契约的接口。位于 io.agentscope.runtime.app 包,实现 ComponentProvider<SandboxService>。核心成员包括 get。
An interface in io.agentscope.runtime.app that defines the contract for components that deploys, schedules and serves agents. Declared in io.agentscope.runtime.app. Implements ComponentProvider
AgentHandlerProvider
@FunctionalInterface public interface AgentHandlerProvider定义智能体处理器提供者契约的接口。位于 io.agentscope.runtime.app 包。核心成员包括 get。
An interface in io.agentscope.runtime.app that defines the contract for components that deploys, schedules and serves agents. Declared in io.agentscope.runtime.app.
ServiceComponentManager
public static class ServiceComponentManager服务 Component 管理器,承载智能体的部署、调度与服务化运行。位于 io.agentscope.runtime.app 包。核心成员包括 getStateService、setStateService、getSessionHistoryService、setSessionHistoryService、getMemoryService、setMemoryService。
A class in io.agentscope.runtime.app that deploys, schedules and serves agents. Declared in io.agentscope.runtime.app.