-
Notifications
You must be signed in to change notification settings - Fork 21
Open
Labels
enhancementNew feature or requestNew feature or request
Milestone
Description
Description
Currently, deploying an AgentScope agent with AgentApp does not support cusrom endpoints and middleware, also, the lifecycle hook is also missing.
To improve developer experience, we propose enhancing the AgentApp class to support:
- Declarative endpoint registration (e.g., for
/chat,/process) - Middleware pipeline (for logging, auth, tracing, rate limiting, etc.)
- Application lifecycle hooks:
before_start(): run DB migrations, warm up models, connect to Redisafter_finish(): gracefully shutdown executors, flush metrics, close connections
This will allow users to define a production-ready agent service in just a few lines.
Proposed API
AgentApp app = new AgentApp(agent);
// Register middleware (executed on every request)
app.use(new LoggingMiddleware());
app.use(new TracingMiddleware());
// Register custom endpoints
app.post("/custom-action", MyCustomHandler);
// Lifecycle hooks
app.beforeStart(() -> {
System.out.println("Warming up");
});
app.afterFinish(() -> {
System.out.println("Shutting down...");
});Or via builder pattern:
new AgentApp(agent)
.middleware(new AuthMiddleware())
.onBeforeStart(initVectorStore())
.onAfterFinish(closeObservability())
.post("/custom-action", MyCustomHandler);Benefits
- Reduce boilerplate for serving agents over HTTP
- Standardize observability, auth, and error handling via middleware
- Enable pre/post startup logic (critical for sandbox, RAG index, etc.)
- Match Python runtime’s
AgentAppergonomics
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request