mirror of
https://github.com/agentscope-ai/ReMe.git
synced 2026-09-22 00:32:49 +00:00
- add neo4j dependency to project requirements - introduce NetworkXFileGraph to replace LocalFileGraph implementation - rename local_file_graph.py to networkx_file_graph.py with updated component registration as 'networkx' - remove pickle persistence logic from NetworkX backend, simplify initialization - update Neo4jFileGraph to return FileLink objects instead of (FileNode, FileLink) tuples from get_inlinks/get_outlinks methods - remove unused AsyncIterator import and adjust method signatures - add BareFileParser for handling binary/attachment files without content parsing - move wikilink resolution utilities to dedicated utility module - refactor memory I/O to use file graph's link resolution methods directly - remove link extraction utilities from schema module, consolidate in utils.wikilink_resolver
51 lines
1.6 KiB
Python
51 lines
1.6 KiB
Python
"""Helpers for serializing Step output onto `RuntimeContext.response`
|
|
and into `agentscope.tool.ToolResponse`.
|
|
|
|
Lives next to `runtime_context.py` because both are about the BaseStep
|
|
interface — the response side, specifically. Used by every Step that
|
|
returns a JSON-shaped payload (agent toolkit, lint toolkit, the three
|
|
memory services).
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
from datetime import date, datetime
|
|
from typing import Any
|
|
|
|
from agentscope.message import TextBlock
|
|
from agentscope.tool import ToolResponse
|
|
|
|
|
|
def _to_jsonable(value):
|
|
if isinstance(value, (datetime, date)):
|
|
return value.isoformat()
|
|
if isinstance(value, dict):
|
|
return {k: _to_jsonable(v) for k, v in value.items()}
|
|
if isinstance(value, (list, tuple, set)):
|
|
return [_to_jsonable(v) for v in value]
|
|
return value
|
|
|
|
|
|
def _set_answer(context, payload) -> None:
|
|
context.response.answer = json.dumps(_to_jsonable(payload), ensure_ascii=False, indent=2)
|
|
|
|
|
|
def _tool_response(
|
|
op: str,
|
|
ok: bool,
|
|
payload: Any,
|
|
audit: list[dict] | None = None,
|
|
) -> ToolResponse:
|
|
"""Wrap a tool-method result as `ToolResponse` and optionally
|
|
append an audit row. Shared by every BaseStep's tool-method
|
|
surface so each toolkit doesn't reinvent serialization."""
|
|
if audit is not None:
|
|
entry = {"op": op, "ok": ok}
|
|
if isinstance(payload, dict):
|
|
entry.update(payload)
|
|
else:
|
|
entry["result"] = payload
|
|
audit.append(entry)
|
|
text = json.dumps(_to_jsonable(payload), ensure_ascii=False, indent=2)
|
|
return ToolResponse(content=[TextBlock(type="text", text=text)])
|