xml-pipeline/xml_pipeline/tools/keyvalue.py
dullfig e653d63bc1 Rename agentserver to xml_pipeline, add console example
OSS restructuring for open-core model:
- Rename package from agentserver/ to xml_pipeline/
- Update all imports (44 Python files, 31 docs/configs)
- Update pyproject.toml for OSS distribution (v0.3.0)
- Move prompt_toolkit from core to optional [console] extra
- Remove auth/server/lsp from core optional deps (-> Nextra)

New console example in examples/console/:
- Self-contained demo with handlers and config
- Uses prompt_toolkit (optional, falls back to input())
- No password auth, no TUI, no LSP — just the basics
- Shows how to use xml-pipeline as a library

Import changes:
- from agentserver.* -> from xml_pipeline.*
- CLI entry points updated: xml_pipeline.cli:main

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-19 21:41:19 -08:00

78 lines
1.8 KiB
Python

"""
Key-value store tool - persistent agent state.
"""
from typing import Any, Optional
from .base import tool, ToolResult
# TODO: Implement backend (Redis, SQLite, or in-memory)
_store: dict = {} # Temporary in-memory store
@tool
async def key_value_get(
key: str,
namespace: Optional[str] = None,
) -> ToolResult:
"""
Get a value from the key-value store.
Args:
key: Key to retrieve
namespace: Namespace for isolation (default: agent name)
Returns:
Stored value, or null if not found
"""
# TODO: Implement with Redis/SQLite
ns_key = f"{namespace or 'default'}:{key}"
value = _store.get(ns_key)
return ToolResult(success=True, data=value)
@tool
async def key_value_set(
key: str,
value: Any,
namespace: Optional[str] = None,
ttl: Optional[int] = None,
) -> ToolResult:
"""
Set a value in the key-value store.
Args:
key: Key to store
value: Value to store (JSON-serializable)
namespace: Namespace for isolation (default: agent name)
ttl: Time-to-live in seconds (optional)
Returns:
success (bool)
"""
# TODO: Implement with Redis/SQLite, handle TTL
ns_key = f"{namespace or 'default'}:{key}"
_store[ns_key] = value
return ToolResult(success=True, data=True)
@tool
async def key_value_delete(
key: str,
namespace: Optional[str] = None,
) -> ToolResult:
"""
Delete a key from the key-value store.
Args:
key: Key to delete
namespace: Namespace for isolation
Returns:
deleted (bool)
"""
# TODO: Implement with Redis/SQLite
ns_key = f"{namespace or 'default'}:{key}"
deleted = ns_key in _store
_store.pop(ns_key, None)
return ToolResult(success=True, data=deleted)