mirror of
https://github.com/agentscope-ai/ReMe.git
synced 2026-11-29 00:38:33 +00:00
* fix(proactive): simplify round files and restore failed summaries * fix(proactive): validate document-relative Markdown links * feat(proactive_agent): implement v2 daily record workflow with single-file decision - Add ProactiveAgentStepV2 class to support single daily note decision and reminder - Introduce RoundOutputs for v2 round file tracking, and keep RoundArtifacts for v1 summary backup - Refactor AgentOutbox to support both v1 standalone reminder files and v2 daily reminder records - Add proactive_record utilities to parse and validate v2 daily record frontmatter and metadata - Enhance proactive_agent to prepare, read, and manage artifacts for both v1 and v2 flows - Add configuration profile proactive_v2 to enable new workflow with backward compatibility - Update proactive.yaml and reactive proactive_agent_step configuration comment for easy switching - Provide extensive schema validation for v2 reminders ensuring priority and message consistency - Document v2 workflow and usage in English and Chinese runtime docs - Add unit tests for v2 step verifying single file output and proper decision handling * refactor(agent/runtime): replace ReminderRef with string keys and simplify reminder handling - Remove ReminderRef model and switch to using workspace-relative string keys for reminders - Simplify AgentOutbox to read, write, and manage reminders keyed by strings - Change file locking and version checking to protect concurrent edits on daily record files - Replace legacy and v2 reminder file handling with unified ReminderFiles storage - Adjust ChatNotifications to operate with the new key scheme and update pending/read sets - Refactor RoundOutputs to RoundRecord for safer round record tracking and rollback - Remove unused ProactiveRunResult and related references from imports and exports - Update InboxWakeRequest, AgentReminder, and related models for consistent ID and path validation - Adjust proactive agent runtime and local runtime to check reminder versions before commit - Correct language and docs to describe reminders as daily records instead of separate files - Clean up roles of inbox and outbox for reminder ownership, delivery, and acknowledgments * fix(proactive): serialize round commits and align desktop reminders * refactor(proactive): unify task triggers in Proactive Runtime * fix(proactive): bound reminder payloads and simplify receipts * refactor(studio): share workbench and simplify proactive delivery * fix(studio): update and centralize build dependencies * fix(proactive): guard draft repair and verify Studio deployments * chore(docs): update source-map-js * feat(release): support publishing selected artifacts from a tag * chore(studio): remove the public playground * refactor: simplify reminders and release workflows * fix: preserve proactive records and align release provenance * test(proactive): remove brittle prompt and preset assertions * fix(proactive): register reminders after input acknowledgement * feat(notebook): list projects across todos and ideas * feat(studio): connect mobile apps to configurable ReMe services * fix(proactive): reserve registered reminder paths * fix(studio): request Android local network access * fix(proactive): reserve reminder paths referenced by receipts
173 lines
6.6 KiB
Python
173 lines
6.6 KiB
Python
"""Current Agent conversations independent of native wrapper or desktop implementation."""
|
|
|
|
from contextlib import aclosing
|
|
|
|
from ....constants import CHAT_AGENT_NAME
|
|
from .base import BaseAgentStep
|
|
from .chat import BaseChatAgentStep
|
|
from ....utils.files.path_lock import get_path_lock
|
|
from ....core.registry import R
|
|
from ....enumeration import ChunkEnum
|
|
from ....schema import StreamChunk
|
|
from ....utils.agent_transcript import TranscriptProjector
|
|
from ....schema.agent_view import (
|
|
AskAgentRequest,
|
|
AgentRequest,
|
|
AgentInboxRequest,
|
|
ListTaskRemindersRequest,
|
|
AgentReminderRequest,
|
|
TaskDocumentRequest,
|
|
)
|
|
|
|
|
|
class _AgentViewStep(BaseAgentStep):
|
|
"""Validate identities and permissions before reading runtime resources."""
|
|
|
|
def request(self, schema=AgentRequest):
|
|
"""Validate public inputs before authorizing the workspace."""
|
|
request = schema.model_validate(self.parameters())
|
|
self.require_paths(self.workspace_path)
|
|
return request
|
|
|
|
|
|
@R.register("agent_list_step")
|
|
class AgentListStep(_AgentViewStep):
|
|
"""List Remy and retained task identities without creating sessions."""
|
|
|
|
async def execute(self):
|
|
if self.parameters():
|
|
raise ValueError("list_agents accepts no arguments")
|
|
self.require_paths(self.workspace_path)
|
|
self.context.response.answer = await self.proactive_runtime.list_views()
|
|
return self.context.response
|
|
|
|
|
|
@R.register("agent_session_step")
|
|
class AgentSessionStep(_AgentViewStep):
|
|
"""Read Chat history or the latest task turn without changing the formal session."""
|
|
|
|
async def execute(self):
|
|
request = self.request()
|
|
self.context.response.answer = await self.proactive_runtime.read_agent(request.agent_name)
|
|
return self.context.response
|
|
|
|
|
|
@R.register("task_document_step")
|
|
class TaskDocumentStep(_AgentViewStep):
|
|
"""Reuse contained file operations for a named task's original description."""
|
|
|
|
async def execute(self):
|
|
request = TaskDocumentRequest.model_validate(self.parameters())
|
|
runtime = self.proactive_runtime
|
|
self.require_paths(runtime.agents.directory)
|
|
agent = await runtime.definition(request.agent_name)
|
|
target = runtime.agents.task_path(agent)
|
|
self.require_paths(target)
|
|
path = target.relative_to(self.workspace_path).as_posix()
|
|
if request.action == "read":
|
|
async with await get_path_lock(target):
|
|
await self.dispatch_steps(["load_step"], path=path)
|
|
else:
|
|
await self.dispatch_steps(
|
|
["save_step"],
|
|
path=path,
|
|
content=request.content,
|
|
expected_mtime=request.expected_mtime,
|
|
)
|
|
response = self.context.response
|
|
if response.success:
|
|
response.answer = {
|
|
"path": path,
|
|
"mtime": response.metadata["mtime"],
|
|
**({"content": response.answer} if request.action == "read" else {}),
|
|
}
|
|
return response
|
|
|
|
|
|
@R.register("watch_agent_session_step")
|
|
class WatchAgentSessionStep(_AgentViewStep):
|
|
"""Relay Chat history changes or atomic latest-task-turn snapshots with sidebar status."""
|
|
|
|
async def execute(self):
|
|
request = self.request()
|
|
async with aclosing(self.proactive_runtime.watch_agent(request.agent_name)) as events:
|
|
async for event in events:
|
|
await self.context.add_stream_chunk(StreamChunk(chunk_type=ChunkEnum.DATA, chunk=event))
|
|
return self.context.response
|
|
|
|
|
|
@R.register("ask_agent_step")
|
|
class AskAgentStep(_AgentViewStep, BaseChatAgentStep):
|
|
"""Continue Chat or ask a read-only fork of the latest task session."""
|
|
|
|
async def execute(self):
|
|
request = self.request(AskAgentRequest)
|
|
if not request.query.strip():
|
|
raise ValueError("query must not be blank")
|
|
projector = TranscriptProjector()
|
|
|
|
async def publish(chunk):
|
|
projector.update(chunk)
|
|
if projector.error:
|
|
self.context.stream_error = projector.error
|
|
# Main Chat content has one authority: the session subscription.
|
|
if request.agent_name == CHAT_AGENT_NAME and chunk.chunk_type not in {
|
|
ChunkEnum.REPLY_START,
|
|
ChunkEnum.REPLY_END,
|
|
ChunkEnum.ERROR,
|
|
}:
|
|
return
|
|
await self.context.add_stream_chunk(
|
|
StreamChunk(chunk_type=ChunkEnum.DATA, chunk=projector.message().model_dump(mode="json")),
|
|
)
|
|
|
|
if request.agent_name == CHAT_AGENT_NAME:
|
|
return await self.chat(request.query, on_chunk=publish)
|
|
reply = await self.query_reply(request.agent_name, request.query, on_chunk=publish)
|
|
self.context.response.success = reply["status"] == "completed" and self.context.stream_error is None
|
|
self.context.response.answer = reply["result"]
|
|
self.context.response.metadata.update(reply, agent_name=request.agent_name)
|
|
return self.context.response
|
|
|
|
|
|
@R.register("agent_new_session_step")
|
|
class AgentNewSessionStep(_AgentViewStep, BaseChatAgentStep):
|
|
"""Start a fresh main Chat session while retaining earlier history."""
|
|
|
|
async def execute(self):
|
|
if self.parameters():
|
|
raise ValueError("create_chat_session accepts no arguments")
|
|
self.require_paths(self.workspace_path)
|
|
await self.new_session()
|
|
self.context.response.answer = await self.proactive_runtime.read_agent(CHAT_AGENT_NAME)
|
|
return self.context.response
|
|
|
|
|
|
@R.register("list_task_reminders_step")
|
|
class ListTaskRemindersStep(_AgentViewStep):
|
|
"""Page a task Agent's committed reminders."""
|
|
|
|
async def execute(self):
|
|
request = self.request(ListTaskRemindersRequest)
|
|
self.context.response.answer = await self.proactive_runtime.outbox.list(**request.model_dump())
|
|
return self.context.response
|
|
|
|
|
|
@R.register("agent_reminder_step")
|
|
class AgentReminderStep(_AgentViewStep):
|
|
"""Read a task reminder or the sources of a Chat message."""
|
|
|
|
async def execute(self):
|
|
request = self.request(AgentReminderRequest)
|
|
self.context.response.answer = await self.proactive_runtime.outbox.read(**request.model_dump())
|
|
return self.context.response
|
|
|
|
|
|
@R.register("agent_inbox_step")
|
|
class AgentInboxStep(_AgentViewStep):
|
|
"""Read any Agent's inputs without claiming or acknowledging them."""
|
|
|
|
async def execute(self):
|
|
request = self.request(AgentInboxRequest)
|
|
self.context.response.answer = await self.proactive_runtime.list_inputs(**request.model_dump())
|
|
return self.context.response
|