-
Notifications
You must be signed in to change notification settings - Fork 5
Feature:Add Scheduled tasks #73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mengnankkkk
wants to merge
23
commits into
main
Choose a base branch
from
feature/add_task
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
ee73106
init
mengnankkkk d7a554f
feat: add scheduled agent task management
mengnankkkk ded2159
fix
mengnankkkk 45a9664
fix
mengnankkkk 3d78c5e
fix:remove something
mengnankkkk 91439d0
fix: remove
mengnankkkk 55baa99
fix: remove
mengnankkkk 6e6aa6a
Merge branch 'main' into feature/add_task
mengnankkkk b284c2e
Update AgentService.java
mengnankkkk fd5062f
fix: task can not run
mengnankkkk d373e7d
fix
mengnankkkk 957de1b
fix: remove
mengnankkkk 108d96d
fix: fix CR remove
mengnankkkk 8d2f645
refactor: streamline agent context and scheduled task service
mengnankkkk 7b7b3cd
Update application.properties
mengnankkkk bd4da3d
Merge branch 'main' into feature/add_task
mengnankkkk 9796742
Merge branch 'main' into feature/add_task
mengnankkkk b4a0d4e
refactor(schedule): split database scheduled task execution flow
mengnankkkk 38cf744
fix: remove prompt
mengnankkkk c708e4a
fix: use builder
mengnankkkk 16ecc73
fix: refactor task in cron
mengnankkkk dfd5a0d
fix: ci
mengnankkkk 455f8bc
refactor(schedule): centralize schedule config in @ConfigurationPrope…
lzq986 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...t-backend/src/main/java/io/github/malonetalk/config/ScheduledAgentScheduleProperties.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /* | ||
| * Copyright (C) 2026 github.com/MaloneTalk | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as | ||
| * published by the Free Software Foundation, either version 3 of the | ||
| * License, or any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| * limitations under the License. | ||
| */ | ||
| package io.github.malonetalk.config; | ||
|
|
||
| import static io.github.malonetalk.common.Constants.SCHEDULE_PROPERTIES_PREFIX; | ||
|
|
||
| import jakarta.validation.Valid; | ||
| import jakarta.validation.constraints.NotNull; | ||
| import jakarta.validation.constraints.Positive; | ||
| import java.time.Duration; | ||
| import lombok.Data; | ||
| import org.springframework.boot.context.properties.ConfigurationProperties; | ||
| import org.springframework.stereotype.Component; | ||
| import org.springframework.validation.annotation.Validated; | ||
|
|
||
| @Validated | ||
| @Component | ||
| @ConfigurationProperties(prefix = SCHEDULE_PROPERTIES_PREFIX) | ||
| @Data | ||
| public class ScheduledAgentScheduleProperties { | ||
|
|
||
| @Positive private int batchSize; | ||
|
|
||
| private long dispatchDelayMs; | ||
|
|
||
| @NotNull private Duration lockDuration; | ||
|
|
||
| @Valid @NotNull private Executor executor = new Executor(); | ||
|
|
||
| @Data | ||
| public static class Executor { | ||
|
|
||
| @Positive private int corePoolSize; | ||
|
|
||
| @Positive private int maxPoolSize; | ||
|
|
||
| @Positive private int queueCapacity; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
...t-backend/src/main/java/io/github/malonetalk/controller/ScheduledAgentTaskController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| /* | ||
| * Copyright (C) 2026 github.com/MaloneTalk | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as | ||
| * published by the Free Software Foundation, either version 3 of the | ||
| * License, or any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| * limitations under the License. | ||
| */ | ||
| package io.github.malonetalk.controller; | ||
|
|
||
| import io.github.malonetalk.common.Result; | ||
| import io.github.malonetalk.dto.ScheduledAgentTaskRequest; | ||
| import io.github.malonetalk.dto.ScheduledAgentTaskResponse; | ||
| import io.github.malonetalk.service.ScheduledAgentTaskService; | ||
| import jakarta.validation.Valid; | ||
| import jakarta.validation.constraints.NotNull; | ||
| import jakarta.validation.constraints.Positive; | ||
| import java.util.List; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.validation.annotation.Validated; | ||
| import org.springframework.web.bind.annotation.DeleteMapping; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PatchMapping; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.PutMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @Validated | ||
| @RestController | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/api/scheduled-agent-tasks") | ||
| public class ScheduledAgentTaskController { | ||
|
|
||
| private final ScheduledAgentTaskService taskService; | ||
|
|
||
| @PostMapping | ||
| public Result<Void> create(@Valid @RequestBody ScheduledAgentTaskRequest request) { | ||
| taskService.create(request); | ||
| return Result.success(); | ||
| } | ||
|
|
||
| @PutMapping("/{id}") | ||
| public Result<Void> update( | ||
| @PathVariable @Positive(message = "id must be positive.") Integer id, | ||
| @Valid @RequestBody ScheduledAgentTaskRequest request) { | ||
| taskService.update(id, request); | ||
| return Result.success(); | ||
| } | ||
|
|
||
| @DeleteMapping("/{id}") | ||
| public Result<Void> delete( | ||
| @PathVariable @Positive(message = "id must be positive.") Integer id) { | ||
| taskService.delete(id); | ||
| return Result.success(); | ||
| } | ||
|
|
||
| @GetMapping | ||
| public Result<List<ScheduledAgentTaskResponse>> listAll() { | ||
| return Result.success(taskService.listAll()); | ||
| } | ||
|
|
||
| @PatchMapping("/{id}/enabled") | ||
| public Result<Void> setEnabled( | ||
| @PathVariable @Positive(message = "id must be positive.") Integer id, | ||
| @Valid @RequestBody EnabledRequest request) { | ||
| taskService.setEnabled(id, request.enabled()); | ||
| return Result.success(); | ||
| } | ||
|
|
||
| @PostMapping("/{id}/run") | ||
| public Result<Boolean> runNow( | ||
| @PathVariable @Positive(message = "id must be positive.") Integer id) { | ||
| return Result.success(taskService.runNow(id)); | ||
| } | ||
|
|
||
| private record EnabledRequest(@NotNull(message = "enabled cannot be null.") Boolean enabled) {} | ||
| } |
29 changes: 29 additions & 0 deletions
29
data-agent-backend/src/main/java/io/github/malonetalk/dto/ScheduledAgentTaskRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /* | ||
| * Copyright (C) 2026 github.com/MaloneTalk | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as | ||
| * published by the Free Software Foundation, either version 3 of the | ||
| * License, or any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| * limitations under the License. | ||
| */ | ||
| package io.github.malonetalk.dto; | ||
|
|
||
| import io.github.malonetalk.enums.ScheduledAgentScheduleType; | ||
| import jakarta.validation.constraints.NotBlank; | ||
| import jakarta.validation.constraints.NotNull; | ||
|
|
||
| public record ScheduledAgentTaskRequest( | ||
| @NotBlank(message = "name cannot be blank.") String name, | ||
| @NotBlank(message = "prompt cannot be blank.") String prompt, | ||
| @NotNull(message = "scheduleType cannot be null.") ScheduledAgentScheduleType scheduleType, | ||
| @NotBlank(message = "scheduleExpr cannot be blank.") String scheduleExpr, | ||
| Boolean enabled) {} |
51 changes: 51 additions & 0 deletions
51
data-agent-backend/src/main/java/io/github/malonetalk/dto/ScheduledAgentTaskResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| /* | ||
| * Copyright (C) 2026 github.com/MaloneTalk | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as | ||
| * published by the Free Software Foundation, either version 3 of the | ||
| * License, or any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| * limitations under the License. | ||
| */ | ||
| package io.github.malonetalk.dto; | ||
|
|
||
| import io.github.malonetalk.entity.ScheduledAgentTask; | ||
| import java.time.LocalDateTime; | ||
| import lombok.Builder; | ||
|
|
||
| @Builder | ||
| public record ScheduledAgentTaskResponse( | ||
| Integer id, | ||
| String name, | ||
| String prompt, | ||
| String scheduleType, | ||
| String scheduleExpr, | ||
| Boolean enabled, | ||
| Boolean running, | ||
| LocalDateTime nextRunAt, | ||
| String lastStatus, | ||
| String lastError) { | ||
|
|
||
| public static ScheduledAgentTaskResponse from(ScheduledAgentTask task) { | ||
| return ScheduledAgentTaskResponse.builder() | ||
| .id(task.getId()) | ||
| .name(task.getName()) | ||
| .prompt(task.getPrompt()) | ||
| .scheduleType(task.getScheduleType()) | ||
| .scheduleExpr(task.getScheduleExpr()) | ||
| .enabled(task.getEnabled()) | ||
| .running(task.getRunning()) | ||
| .nextRunAt(task.getNextRunAt()) | ||
| .lastStatus(task.getLastStatus()) | ||
| .lastError(task.getLastError()) | ||
| .build(); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ToolCallContext定位是 “向工具传递业务上下文”, 详细看文档 “https://java.agentscope.io/v1/zh/docs/quickstart/agent.html#id4”
所以不要把 userInput、datasourceId 这种不向 工具传递业务上下文的放在这个对象。
userid需要保留在这个工具,因为后面鉴权的时候工具需要依赖它。