class MemoryStoreTool(Instrument):
title = "memory_store"
description = "Save an essential truth or piece of knowledge to long-term reminiscence."
def __init__(self, reminiscence: MemoryBackend):
self._mem = reminiscence
def run(self, textual content: str, class: str = "normal") -> str:
chunk_id = self._mem.retailer(textual content, {"class": class})
return f"Saved as {chunk_id}."
def schema(self) -> Dict:
return {
"kind": "perform",
"perform": {
"title": self.title,
"description": self.description,
"parameters": {
"kind": "object",
"properties": {
"textual content": {"kind": "string", "description": "The very fact to recollect."},
"class": {"kind": "string", "description": "Class tag, e.g. 'user_pref', 'activity', 'truth'."},
},
"required": ["text"],
},
},
}
class MemorySearchTool(Instrument):
title = "memory_search"
description = "Search long-term reminiscence for data related to a question."
def __init__(self, reminiscence: MemoryBackend):
self._mem = reminiscence
def run(self, question: str, top_k: int = 3) -> str:
outcomes = self._mem.search(question, top_k=top_k)
if not outcomes:
return "No related recollections discovered."
traces = [f"[{r['id']}] (rating={r['rrf_score']}) {r['text']}" for r in outcomes]
return "Related recollections:n" + "n".be a part of(traces)
def schema(self) -> Dict:
return {
"kind": "perform",
"perform": {
"title": self.title,
"description": self.description,
"parameters": {
"kind": "object",
"properties": {
"question": {"kind": "string", "description": "What to search for."},
"top_k": {"kind": "integer", "description": "Max outcomes (default 3)."},
},
"required": ["query"],
},
},
}
class CalculatorTool(Instrument):
title = "calculator"
description = "Consider a protected mathematical expression, e.g. '2 ** 10 + sqrt(144)'."
def run(self, expression: str) -> str:
allowed = {okay: getattr(math, okay) for okay in dir(math) if not okay.startswith("_")}
allowed.replace({"abs": abs, "spherical": spherical})
strive:
consequence = eval(expression, {"__builtins__": {}}, allowed)
return str(consequence)
besides Exception as exc:
return f"Error: {exc}"
def schema(self) -> Dict:
return {
"kind": "perform",
"perform": {
"title": self.title,
"description": self.description,
"parameters": {
"kind": "object",
"properties": {
"expression": {"kind": "string", "description": "Math expression to judge."},
},
"required": ["expression"],
},
},
}
class WebSnippetTool(Instrument):
title = "web_search"
description = "Search the net for present data on a subject (simulated)."
_KB = {
"openai": "OpenAI is an AI security firm that develops the GPT household of fashions.",
"rag": "Retrieval-Augmented Era (RAG) combines a retrieval system with an LLM to floor solutions in exterior paperwork.",
"bm25": "BM25 (Finest Match 25) is a probabilistic key phrase rating perform utilized in engines like google.",
}
def run(self, question: str) -> str:
q = question.decrease()
for kw, snippet in self._KB.objects():
if kw in q:
return f"Net snippet for '{question}': {snippet}"
return f"No snippet discovered for '{question}'. (Mock instrument — combine an actual search API right here.)"
def schema(self) -> Dict:
return {
"kind": "perform",
"perform": {
"title": self.title,
"description": self.description,
"parameters": {
"kind": "object",
"properties": {
"question": {"kind": "string", "description": "Search question."},
},
"required": ["query"],
},
},
}
@dataclass
class AgentPersona:
title: str
position: str
traits: Checklist[str]
forbidden_phrases: Checklist[str] = subject(default_factory=record)
targets: Checklist[str] = subject(default_factory=record)
def compile_system_prompt(self, extra_context: str = "") -> str:
traces = [
f"You are {self.name}, {self.role}.",
"",
"## Core Traits",
*[f"- {t}" for t in self.traits],
]
if self.targets:
traces += ["", "## Goals", *[f"- {g}" for g in self.goals]]
if self.forbidden_phrases:
traces += ["", "## Forbidden Phrases (never say these)", *[f"- "{p}"" for p in self.forbidden_phrases]]
if extra_context:
traces += ["", "## Live Context", extra_context]
traces += [
"",
"## Behaviour",
"- Always reason step-by-step before answering.",
"- Use available tools proactively; never guess when you can look up.",
"- After using memory_search, quote the retrieved ID in your answer.",
"- Keep answers concise unless depth is explicitly requested.",
]
return "n".be a part of(traces)
ARIA = AgentPersona(
title="Aria",
position="a exact, useful analysis assistant with a hybrid reminiscence system",
traits=["Methodical", "Curious", "Transparent about uncertainty", "Concise"],
targets=[
"Remember and connect information across conversations",
"Use tools whenever they can improve accuracy",
],
forbidden_phrases=["I cannot", "As an AI language model"],
)
print("✅ Instruments and AgentPersona prepared.")
Construct a Hybrid-Reminiscence Autonomous Agent with Modular Structure and Instrument Dispatch Utilizing OpenAI
RELATED ARTICLES
