Skip to content

Conversation

@XiuShenAl
Copy link
Collaborator

@XiuShenAl XiuShenAl commented Jan 23, 2026

Description

This PR refactors the AgentApp class by migrating it from a factory-based FastAPI setup to a direct inheritance model. This completes the transition previously initiated under FastAgentApp.

Key Changes:

  1. Full Replacement: The legacy AgentApp has been removed. The new implementation (formerly FastAgentApp) is now the primary AgentApp.
  2. Execution Interruption Support: Added a mechanism to manually interrupt the agent's running process.
  3. State Management via Control Flow: Supported a pattern where users can manage agent state using standard try...finally blocks. Users can load the state at the beginning of the execution and ensure the current state is saved within the finally block when an interruption occurs.
  4. STS Token Support for Deployment: Supported temporary STS credentials in runtime-fc-deploy. This enables secure cloud deployments using temporary security tokens instead of static AccessKey.

Related Issue:
Fixes #402
Fixes #432

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Refactoring

Component(s) Affected

  • Engine
  • Sandbox
  • Tools
  • Common
  • Documentation
  • Tests
  • CI/CD

Checklist

  • Pre-commit hooks pass
  • Tests pass locally
  • Documentation updated (if needed)
  • Ready for review

Additional Notes

  • This PR now represents a complete replacement of the old AgentApp architecture.
  • Fixed Deployment: Resolved issues in the previous version regarding app deployment.
  • Ready for full review once CI passes.

@XiuShenAl XiuShenAl changed the title feat: extend AgentApp to FastAgentApp with FastAPI inheritance and in… feat: refactor AgentApp to inherit from FastAPI with interrupt support Jan 30, 2026
@XiuShenAl XiuShenAl marked this pull request as ready for review January 30, 2026 08:32
@XiuShenAl XiuShenAl requested a review from a team January 30, 2026 08:32
@XiuShenAl XiuShenAl force-pushed the feat/interruptible-fastapi-app branch from 9263a4d to 1dbc76b Compare January 30, 2026 11:16
@rayrayraykk rayrayraykk requested a review from Copilot February 2, 2026 03:15
@rayrayraykk
Copy link
Member

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request is a significant and well-executed refactoring of the AgentApp class. By making AgentApp inherit directly from FastAPI, the architecture is now much cleaner, more aligned with FastAPI best practices, and more extensible. The introduction of mixins for routing, tasks, and interrupts is a great design choice that improves modularity. The new interrupt support with configurable backends is a powerful feature. I've identified a couple of areas for improvement in the new streaming and error handling logic, but overall this is an excellent contribution.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR replaces the legacy factory-based AgentApp design with a FastAPI-inheriting AgentApp, introduces unified routing and task/interrupt infrastructure, and adds support for distributed/manual interruption of running agent sessions.

Changes:

  • Refactored AgentApp to inherit directly from FastAPI, wiring it to a Runner, new routing mixins (UnifiedRoutingMixin, CustomEndpointMixin, TaskEngineMixin), and updated deployment paths.
  • Introduced an interrupt subsystem (InterruptMixin plus Redis and local backends) to track task states and allow cross-process/manual interruption of streaming executions.
  • Deprecated the older Celery/FastAPIAppFactory path, updated LocalDeployManager to work with AgentApp instances directly, and removed now-obsolete tests around FastAPIAppFactory.

Reviewed changes

Copilot reviewed 14 out of 15 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
tests/unit/test_service_utils.py Removes unit tests that targeted the now-deprecated FastAPIAppFactory and its deployment modes, aligning the test suite with the new AgentApp-centric architecture.
src/agentscope_runtime/engine/deployers/utils/service_utils/routing/unified_routing_mixin.py Adds UnifiedRoutingMixin to centralize custom/task routing registration, task status routes, and discovery-oriented routing metadata, used by AgentApp for unified route management.
src/agentscope_runtime/engine/deployers/utils/service_utils/routing/task_engine_mixin.py Introduces TaskEngineMixin that encapsulates Celery/in-memory task execution, task registration, and status querying, decoupling task processing from the old CeleryMixin/factory pattern.
src/agentscope_runtime/engine/deployers/utils/service_utils/routing/custom_endpoint_mixin.py Provides CustomEndpointMixin to register custom synchronous and streaming endpoints with correct FastAPI signature handling and SSE normalization, used by UnifiedRoutingMixin/AgentApp.
src/agentscope_runtime/engine/deployers/utils/service_utils/interrupt/base_backend.py Defines the abstract BaseInterruptBackend, TaskState, and InterruptSignal enums that formalize the contract for distributed interrupt backends.
src/agentscope_runtime/engine/deployers/utils/service_utils/interrupt/redis_backend.py Implements RedisInterruptBackend using Redis pub/sub and key-value storage to persist task state and broadcast interrupt signals across processes.
src/agentscope_runtime/engine/deployers/utils/service_utils/interrupt/local_backend.py Adds LocalInterruptBackend, an in-memory backend suitable for single-process deployments, mirroring the Redis backend’s API for task state and signal handling.
src/agentscope_runtime/engine/deployers/utils/service_utils/interrupt/interrupt_mixin.py Introduces InterruptMixin with run_and_stream, stop_chat, and lifecycle wiring so AgentApp can wrap streaming generators with distributed interrupt and state tracking semantics.
src/agentscope_runtime/engine/deployers/utils/service_utils/interrupt/init.py Exposes the new interrupt types (TaskState, BaseInterruptBackend, RedisInterruptBackend, InterruptMixin, LocalInterruptBackend) as a public interrupt API surface.
src/agentscope_runtime/engine/deployers/utils/service_utils/fastapi_factory.py Marks FastAPIAppFactory as deprecated with guidance to construct AgentApp directly, reflecting the migration away from the factory-based app construction route.
src/agentscope_runtime/engine/deployers/local_deployer.py Adjusts local daemon-thread deployment to run an existing AgentApp instance directly under uvicorn, removing the dependency on FastAPIAppFactory.create_app while still supporting detached-process packaging.
src/agentscope_runtime/engine/app/celery_mixin.py Deprecates the legacy CeleryMixin in favor of the new TaskEngineMixin, signalling that task processing responsibilities have moved to the routing utils layer.
src/agentscope_runtime/engine/app/base_app.py Removes the obsolete BaseApp that previously combined CeleryMixin with a pseudo-FastAPI task routing API, as its responsibilities are now handled by AgentApp plus the new mixins.
src/agentscope_runtime/engine/app/agent_app.py Fully refactors AgentApp to inherit from FastAPI, integrate unified routing and interrupt support, override openapi to inject protocol schemas, manage lifecycle via FastAPI lifespan hooks, and provide run/deploy methods compatible with the new architecture.

@XiuShenAl XiuShenAl force-pushed the feat/interruptible-fastapi-app branch from 38123c9 to bcf8274 Compare February 2, 2026 07:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants