agentscope-ai / agentscope-ai/agentscope-runtime

[Feature] Add Hooks/Decorators for FastAPI Middleware in AgentApp

Open
#293 4 comments 0 reactions 1 assignee Claimed by @zhilingluo View on GitHub
enhancement
Dominant language
Python
Stars
863
Forks
168
PR merge metrics
No merged PRs in 30d

Description

## Problem Description

Currently, `agentscope_runtime.engine.AgentApp` leverages `FastAPIAppFactory.create_app` to instantiate a FastAPI application instance for serving agent-related endpoints. However, there is no built-in mechanism (e.g., hooks, decorators, or callback functions) to inject custom FastAPI middleware into the created app instance.

Developers who need to add middleware (e.g., logging, authentication, ~~CORS~~ customization, request/response interceptors) to the FastAPI app have to either:
Modify the internal implementation of FastAPIAppFactory (not maintainable), or
Recreate the app instance manually (defeats the purpose of AgentApp abstraction).

## Proposed Solution

to be discussed.

## Affected Component(s)
- [x] Engine
- [ ] Sandbox
- [ ] Common
- [ ] Tools
- [ ] Documentation
- [ ] Other: ___________

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.