Skip to content

Implement persistent background agent execution with scheduling and event-driven triggers#1

Merged
Bharani010 merged 5 commits into
mainfrom
copilot/fix-159679943-1088593371-3342cd36-2970-40ff-b403-eefd82d95579
Nov 3, 2025
Merged

Implement persistent background agent execution with scheduling and event-driven triggers#1
Bharani010 merged 5 commits into
mainfrom
copilot/fix-159679943-1088593371-3342cd36-2970-40ff-b403-eefd82d95579

Conversation

Copy link
Copy Markdown

Copilot AI commented Nov 3, 2025

Enables agents to run autonomously without UI dependency, supporting scheduled execution (cron/interval/date), webhook triggers, and event-driven workflows.

Implementation

Database Layer

  • BackgroundAgent model: stores agent config, trigger settings, status (ACTIVE/PAUSED/STOPPED/ERROR)
  • BackgroundAgentExecution model: tracks execution history with results and errors
  • Support for 5 trigger types: CRON, INTERVAL, DATE, WEBHOOK, EVENT
  • Migration creates tables with proper indexes and foreign keys

Service Layer

  • BackgroundAgentService: APScheduler-based service managing agent lifecycle
  • Auto-loads ACTIVE agents on startup
  • Methods: start_agent(), stop_agent(), pause_agent(), resume_agent(), trigger_agent()
  • Async execution via execute_flow_background() using existing FlowRunner
  • Execution history tracking with status and error capture

API Endpoints

13 new endpoints under /api/v1/background_agents/:

  • CRUD: POST /, GET /, GET /{id}, PATCH /{id}, DELETE /{id}
  • Lifecycle: POST /{id}/start, POST /{id}/stop, POST /{id}/pause, POST /{id}/resume
  • Operations: POST /{id}/trigger, GET /{id}/status, GET /{id}/executions
  • User-scoped authorization, flow_id filtering support

Usage Example

# Create hourly data sync agent
agent = {
    "name": "Hourly Data Sync",
    "flow_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
    "trigger_type": "INTERVAL",
    "trigger_config": {"hours": 1},
    "input_config": {"input_value": "Sync data"}
}

response = requests.post(
    "http://localhost:7860/api/v1/background_agents/",
    json=agent,
    headers={"Authorization": f"Bearer {token}"}
)

# Start the agent
agent_id = response.json()["id"]
requests.post(f"http://localhost:7860/api/v1/background_agents/{agent_id}/start")

Dependencies

  • Added APScheduler>=3.10.4,<4.0.0 for scheduling infrastructure

Testing

  • 21 service layer unit tests covering all operations and trigger types
  • 17 API integration tests including auth/authz, CRUD, and lifecycle operations
  • CodeQL security scan: 0 alerts

Documentation

  • API Reference: endpoint specifications, request/response schemas, error handling
  • User Guide: getting started, use cases, configuration reference, troubleshooting
Original prompt

Feature Request
Enhance Langflow Agents to support persistent background execution, ensuring they remain active even when the UI is closed or user is offline. Agents should operate as dedicated background processes/services, enabling scheduled, event-driven, and autonomous workflows.

Enhancement Details
Implement a background runner for agents that can be initiated independently of the UI session.
Support scheduling capabilities (cron-like, time-based triggers).
Allow agents to respond to external events, webhooks, or API calls while running background tasks.
Provide controls for monitoring, starting, stopping, or restarting agent processes from the Langflow UI or API.
Ensure robust logging and error reporting for background agent activities.
Compatibility considerations: make background agent mode configurable per agent, with system resource checks and cross-platform support.
Motivation
This enhancement enables always-on and event-driven automation, supporting use cases such as:

Workflow orchestration (multi-step, autonomous tasks)
Continuous monitoring and alerting
Integration with third-party services or schedules
Reduces dependency on manual UI actions for agent activity
Your Contribution
I can assist with:

Use case validation: identifying scenarios that benefit from background agents
Testing: verifying background execution reliability on different platforms
Documentation: contributing guides and design suggestions for implementation
Collaboration: discussing system compatibility, API interface, and operational requirements
Next Steps
Gather feedback on specific background agent use cases and technical constraints
Prototype background agent runner and scheduling functionality
Document workflow and API integration options
Collaborate with community to ensure robust and user-friendly implementation


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 4 commits November 3, 2025 07:45
…and database migration

Co-authored-by: Bharani010 <159679943+Bharani010@users.noreply.github.com>
Co-authored-by: Bharani010 <159679943+Bharani010@users.noreply.github.com>
Co-authored-by: Bharani010 <159679943+Bharani010@users.noreply.github.com>
Co-authored-by: Bharani010 <159679943+Bharani010@users.noreply.github.com>
Copilot AI changed the title Feature Request Enhance Langflow Agents to support persistent background execution, ensuring they remain active even when the UI is closed or user is offline. Agents should operate as dedicated background processes/services, enabling scheduled, event-d... Implement persistent background agent execution with scheduling and event-driven triggers Nov 3, 2025
Copilot AI requested a review from Bharani010 November 3, 2025 08:01
@Bharani010 Bharani010 marked this pull request as ready for review November 3, 2025 08:03
@Bharani010 Bharani010 merged commit c493885 into main Nov 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants