Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.
Python agent-contextagent-memoryagent-pluginsagentic-ragcontext-databasedsh-pluginknowledge-basememorymemory-managementself-evolvingvector-database
Step 1: Add a resource
Install requests in your Python environment (python -m pip install requests). Replace the local file path and use an unused complete target URI; the page supplies the service URL and API key.
import json
from pathlib import Path
import requests
url = "{{OPENVIKING_BASE_URL}}"
api_key = "{{OPENVIKING_API_KEY}}"
file_path = Path("[TODO]your-file-path") # e.g. test.txt
resource_to = "[TODO]your-resource-path" # e.g. viking://resources/test.txt
reason = "[TODO]your-reason" # e.g. External API documentation
# 1. Initialize request headers.
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer " + api_key,
}
def post_json(path: str, payload: dict, timeout: float):
response = requests.post(f"{url}{path}", headers=headers, json=payload, timeout=timeout)
response.raise_for_status()
return response.json()
# 2. Upload the local file to a temporary resource.
with file_path.open("rb") as file:
result = requests.post(
f"{url}/api/v1/resources/temp_upload",
headers={
"Authorization": "Bearer " + api_key,
},
files={"file": (file_path.name, file, "application/octet-stream")},
timeout=120.0,
)
result.raise_for_status()
result = result.json()
print(json.dumps(result, ensure_ascii=False, indent=2))
temp_file_id = result["result"]["temp_file_id"]
# 3. Create a resource from the temporary file.
result = post_json(
"/api/v1/resources",
{
"temp_file_id": temp_file_id,
"source_name": file_path.name,
"to": resource_to,
"reason": reason,
},
120.0,
)
print(json.dumps(result, ensure_ascii=False, indent=2))
Step 2: Add memory
Reuse the imports, connection settings, and post_json helper from Step 1. Add a message to a new session and submit memory extraction:
text = "[TODO]your-message-text" # e.g. I am a developer
# Create a session.
session = post_json("/api/v1/sessions", {}, 360.0)
session_id = session["result"]["session_id"]
# Add a message.
post_json(
f"/api/v1/sessions/{session_id}/messages",
{
"role": "user",
"parts": [{"type": "text", "text": text}],
},
360.0,
)
# Commit the session.
result = post_json(
f"/api/v1/sessions/{session_id}/commit",
{"telemetry": False},
360.0,
)
print(json.dumps(result, ensure_ascii=False, indent=2))
Resource import and session commit may return before processing finishes. If result["result"] contains a task_id, query GET /api/v1/tasks/{task_id} with the same authorization header until it is completed, failed, or cancelled. Handle failures before reading or searching the result. A no-op commit may return no task.