Close Menu
    Facebook X (Twitter) Instagram
    Articles Stock
    • Home
    • Technology
    • AI
    • Pages
      • About ArticlesStock — AI & Technology Journalist
      • Contact us
      • Disclaimer For Articles Stock
      • Privacy Policy
      • Terms and Conditions
    Facebook X (Twitter) Instagram
    Articles Stock
    AI

    Construct a Hybrid-Reminiscence Autonomous Agent with Modular Structure and Instrument Dispatch Utilizing OpenAI

    Naveed AhmadBy Naveed Ahmad13/05/2026Updated:13/05/2026No Comments4 Mins Read
    blog11 14


    class MemoryStoreTool(Instrument):
       identify = "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 = "common") -> str:
           chunk_id = self._mem.retailer(textual content, {"class": class})
           return f"Saved as {chunk_id}."
    
    
       def schema(self) -> Dict:
           return {
               "kind": "perform",
               "perform": {
                   "identify": self.identify,
                   "description": self.description,
                   "parameters": {
                       "kind": "object",
                       "properties": {
                           "textual content":     {"kind": "string", "description": "The actual fact to recollect."},
                           "class": {"kind": "string", "description": "Class tag, e.g. 'user_pref', 'activity', 'truth'."},
                       },
                       "required": ["text"],
                   },
               },
           }
    
    
    
    
    class MemorySearchTool(Instrument):
       identify = "memory_search"
       description = "Search long-term reminiscence for info 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": {
                   "identify": self.identify,
                   "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):
       identify = "calculator"
       description = "Consider a secure 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:
               outcome = eval(expression, {"__builtins__": {}}, allowed)
               return str(outcome)
           besides Exception as exc:
               return f"Error: {exc}"
    
    
       def schema(self) -> Dict:
           return {
               "kind": "perform",
               "perform": {
                   "identify": self.identify,
                   "description": self.description,
                   "parameters": {
                       "kind": "object",
                       "properties": {
                           "expression": {"kind": "string", "description": "Math expression to judge."},
                       },
                       "required": ["expression"],
                   },
               },
           }
    
    
    
    
    class WebSnippetTool(Instrument):
       identify = "web_search"
       description = "Search the net for present info 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 search 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 software — combine an actual search API right here.)"
    
    
       def schema(self) -> Dict:
           return {
               "kind": "perform",
               "perform": {
                   "identify": self.identify,
                   "description": self.description,
                   "parameters": {
                       "kind": "object",
                       "properties": {
                           "question": {"kind": "string", "description": "Search question."},
                       },
                       "required": ["query"],
                   },
               },
           }
    
    
    
    
    @dataclass
    class AgentPersona:
       identify: str
       position: str
       traits: Listing[str]
       forbidden_phrases: Listing[str] = area(default_factory=listing)
       objectives: Listing[str] = area(default_factory=listing)
    
    
       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.objectives:
               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(
       identify="Aria",
       position="a exact, useful analysis assistant with a hybrid reminiscence system",
       traits=["Methodical", "Curious", "Transparent about uncertainty", "Concise"],
       objectives=[
           "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.")



    Source link

    Naveed Ahmad

    Naveed Ahmad is a technology journalist and AI writer at ArticlesStock, covering artificial intelligence, machine learning, and emerging tech policy. Read his latest articles.

    Related Posts

    Meet the Unhappy Wives of AI

    13/05/2026

    Google unveils Googlebook, a brand new line of AI-native laptops

    13/05/2026

    Google DeepMind Introduces an AI-Enabled Mouse Pointer Powered by Gemini That Captures Visible and Semantic Context Across the Cursor

    13/05/2026
    Leave A Reply Cancel Reply

    Categories
    • AI
    Recent Comments
      Facebook X (Twitter) Instagram Pinterest
      © 2026 ThemeSphere. Designed by ThemeSphere.

      Type above and press Enter to search. Press Esc to cancel.