Close Menu
NCIJ Network NCIJ Network
    What's Hot

    Yes, There Is Some Global Action on Phasing Out Fossil Fuels

    October 24, 2026

    70,000 police forces deployed in France for tense day of protests – POLITICO

    October 24, 2026

    Between quick wins and big dreams lies Burnham’s biggest test, starting with the Budget

    October 24, 2026
    Facebook X (Twitter) Instagram
    Trending
    • Yes, There Is Some Global Action on Phasing Out Fossil Fuels
    • 70,000 police forces deployed in France for tense day of protests – POLITICO
    • Between quick wins and big dreams lies Burnham’s biggest test, starting with the Budget
    • No unions, low taxes: why some of Britain’s top chefs are opening outposts in Gulf states | Restaurants
    • Stateful Agentic Engineering Copilots with Letta: Core Memory, Shared State, Semantic Retrieval, Custom Tools, Streaming, and Portable Agent Workflows
    • Quest Diagnostics confirms data breach exposed patient records
    • People are taking an unapproved weight-loss drug. AI found something surprising
    • Death of iconic elephant in Sri Lanka pushes authorities to fast-track protection efforts
    • About
      • Our Team
      • Editorial Policy
      • Editorial Independence
      • International Support
    • Trust & Standards
      • AI Usage Policy
      • Conflict of Interest Policy
      • Corrections Policy
      • Ethics Policy
      • Fact-Checking Policy
      • Source Protection
    • Get Involved
      • Guide for Sources
      • Support Independent Journalism
    • Legal
      • Cookie Policy
      • Privacy Policy
      • Terms of Use
    Facebook X (Twitter) Instagram
    NCIJ Network NCIJ Network
    Saturday, October 24
    • Home
    • World
    • Ai
    • Business
    • Politics
    • Health
    • Crypto
    • Science
    • Technology
    • Cybersecurity
    • Defense & Security
    • Economy
    • Energy
    • Europe
    • More
      • Fact Check
      • Investigations
      • Opinion & Analysis
      • Environment
    NCIJ Network NCIJ Network
    Home»Artificial Intelligence

    Stateful Agentic Engineering Copilots with Letta: Core Memory, Shared State, Semantic Retrieval, Custom Tools, Streaming, and Portable Agent Workflows

    NCIJ NETWNCIJ NETWORKBy NCIJ NETWNCIJ NETWORKOctober 24, 2026 Artificial Intelligence No Comments3 Mins Read
    Share
    Facebook Twitter LinkedIn Pinterest Email

    import subprocess, sys
    subprocess.run([sys.executable, "-m", "pip", "install", "-q", "-U", "letta-client"], check=True)
    import os, json, time, textwrap
    from getpass import getpass
    from letta_client import Letta
    def flex(*attempts, label=""):
       err = None
       for fn in attempts:
           try:
               return fn()
           except Exception as e:
               err = e
       raise RuntimeError(f"All call variants failed for {label or 'call'}: {err}") from err
    API_KEY  = os.environ.get("LETTA_API_KEY") or getpass("Letta API key (platform.letta.com/api-keys): ")
    BASE_URL = os.environ.get("LETTA_BASE_URL", "").strip()
    client = flex(
       lambda: Letta(base_url=BASE_URL, api_key=API_KEY) if BASE_URL else Letta(api_key=API_KEY),
       lambda: Letta(base_url=BASE_URL, token=API_KEY)   if BASE_URL else Letta(token=API_KEY),
       label="client init",
    )
    def hr(title):
       print("n" + "=" * 92 + f"n  {title}n" + "=" * 92)
    def as_text(content):
       if isinstance(content, str):
           return content
       if isinstance(content, list):
           return "".join(getattr(p, "text", "") or "" for p in content)
       return str(content or "")
    def show(response, hide_reasoning=False):
       for m in getattr(response, "messages", response) or []:
           kind = getattr(m, "message_type", None) or getattr(m, "type", "?")
           if kind == "reasoning_message" and not hide_reasoning:
               print("🧠 reasoning :", textwrap.shorten(getattr(m, "reasoning", "") or "", 220))
           elif kind == "tool_call_message":
               tc = getattr(m, "tool_call", None)
               print("🔧 tool call :", getattr(tc, "name", "?"), textwrap.shorten(str(getattr(tc, "arguments", "")), 200))
           elif kind == "tool_return_message":
               print("↩️  tool ret  :", textwrap.shorten(str(getattr(m, "tool_return", "")), 260))
           elif kind == "assistant_message":
               print("🤖 assistant :", as_text(getattr(m, "content", "")))
           elif kind == "approval_request_message":
               print("⏸️  approval  : agent is waiting for you to approve a tool call")
       u = getattr(response, "usage", None)
       if u:
           print(f"   ↳ steps={getattr(u, 'step_count', '?')} tokens={getattr(u, 'total_tokens', '?')}")
    def chat(agent_id, text, max_steps=12, quiet=False):
       r = flex(
           lambda: client.agents.messages.create(agent_id=agent_id, input=text, max_steps=max_steps),
           lambda: client.agents.messages.create(agent_id=agent_id, input=text),
           lambda: client.agents.messages.create(agent_id=agent_id,
                                                 messages=[{"role": "user", "content": text}]),
           label="messages.create",
       )
       if not quiet:
           print(f"n👤 user      : {text}")
           show(r)
       return r
    PREFERRED = ["openai/gpt-4.1", "openai/gpt-4o-mini", "anthropic/claude-sonnet-4-20250514"]
    try:
       handles = [getattr(m, "handle", None) for m in client.models.list()]
       MODEL = next((h for h in PREFERRED if h in handles), None) or handles[0]
    except Exception:
       MODEL = PREFERRED[0]
    print(f"✅ connected · model handle = {MODEL}")
    hr("1. Create a stateful agent with custom memory blocks")
    def make_agent(**kw):
       return flex(
           lambda: client.agents.create(model=MODEL, embedding="openai/text-embedding-3-small", **kw),
           lambda: client.agents.create(model=MODEL, **kw),
           label="agents.create",
       )
    copilot = make_agent(
       name=f"copilot-{int(time.time())}",
       description="Engineering copilot with inspectable long-term memory",
       tags=["tutorial", "copilot"],
       memory_blocks=[
           {"label": "persona",
            "value": "I am Mnemo, an engineering copilot. I am terse, concrete, and I never "
                     "invent facts — if I don't know something I say so and then go look it up.",
            "limit": 3000},
           {"label": "human",
            "description": "Durable facts about the engineer I work with: name, role, stack, "
                           "preferences, working style. Update this whenever I learn something stable.",
            "value": "Unknown so far.",
            "limit": 3000},
           {"label": "project_state",
            "description": "Live state of the project we are shipping: milestones, blockers, "
                           "decisions and their rationale. Keep it dense and current; delete stale lines.",
            "value": "(empty)",
            "limit": 5000},
           {"label": "lessons",
            "description": "Hard-won lessons and mistakes to never repeat. Append-only, one line each.",
            "value": "(empty)",
            "limit": 2000},
       ],
    )
    print("agent id:", copilot.id)
    def get_block(agent_id, label):
       return flex(
           lambda: client.agents.blocks.retrieve(agent_id=agent_id, block_label=label),
           lambda: client.agents.blocks.retrieve(agent_id, label),
           label="agents.blocks.retrieve",
       )
    def set_block(agent_id, label, value):
       return flex(
           lambda: client.agents.blocks.update(agent_id=agent_id, block_label=label, value=value),
           lambda: client.agents.blocks.modify(agent_id=agent_id, block_label=label, value=value),
           lambda: client.agents.blocks.update(agent_id, label, value=value),
           label="agents.blocks.update",
       )
    def dump_memory(agent_id, title="core memory"):
       blocks = flex(lambda: client.agents.blocks.list(agent_id=agent_id),
                     lambda: client.agents.blocks.list(agent_id), label="agents.blocks.list")
       print(f"n──── {title} ────")
       for b in blocks:
           ro = " [read-only]" if getattr(b, "read_only", False) else ""
           print(f"▸ {b.label}{ro} ({len(b.value or '')}/{getattr(b, 'limit', '?')} chars)")
           print(textwrap.indent(textwrap.fill(b.value or "", 100), "    "))
       return blocks
    dump_memory(copilot.id, "core memory at birth")
    
    agent agentic Copilots core custom Engineering Letta memory portable Retrieval Semantic shared state Stateful Streaming Tools Workflows
    NCIJ NETWNCIJ NETWORK
    • Website

    Keep Reading

    NVIDIA Releases Nemotron 3.5 Bolt E4B 4GB: An Open Small Language Model for Local Voice Agents, Game Characters and Robots

    Kyutai CADRE: Video Autoencoders That Cut World Model Lag Below 230 ms

    Moonshot AI Releases Kimi K3.1 Pro: A 2.8T Total/104B Active Params (MoE) Model with 1M Context

    You.com Launches Inference Router: 12 Open-Weight Models With 99.9% Uptime SLA

    You gave your AI agent access, but who is giving it orders?

    TinyFish Breaks Down Agentic Search Architecture for Production AI Agents

    Add A Comment
    Leave A Reply Cancel Reply

    Editors Picks

    Yes, There Is Some Global Action on Phasing Out Fossil Fuels

    October 24, 2026

    70,000 police forces deployed in France for tense day of protests – POLITICO

    October 24, 2026

    Between quick wins and big dreams lies Burnham’s biggest test, starting with the Budget

    October 24, 2026

    No unions, low taxes: why some of Britain’s top chefs are opening outposts in Gulf states | Restaurants

    October 24, 2026
    Latest Posts

    ‘This is hell’: British widow ‘sick’ with worry over threat of being removed from Sweden | Sweden

    August 14, 2026

    Prichard Colon dies from boxing injury that resulted in 221-day coma | Boxing News

    August 14, 2026

    Weather forecasts once gave Britons something safe to chat about. Not any more | Andy Beckett

    August 14, 2026

    Subscribe to News

    Get the latest sports news from NewsSite about world, sports and politics.

    NCIJ Network is an independent digital news platform delivering trusted investigative journalism, European and global news, in-depth analysis, and fact-based reporting with accuracy, transparency, and integrity.

    Facebook X (Twitter) Instagram Pinterest YouTube

    Yes, There Is Some Global Action on Phasing Out Fossil Fuels

    October 24, 2026

    70,000 police forces deployed in France for tense day of protests – POLITICO

    October 24, 2026

    Between quick wins and big dreams lies Burnham’s biggest test, starting with the Budget

    October 24, 2026

    Subscribe to Updates

    Get the latest creative news from FooBar about art, design and business.

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