• bitcoinBitcoin(BTC)$67,928.00-0.04%
  • ethereumEthereum(ETH)$1,967.81-0.86%
  • tetherTether(USDT)$1.000.00%
  • binancecoinBNB(BNB)$621.45-1.17%
  • rippleXRP(XRP)$1.36-0.29%
  • usd-coinUSDC(USDC)$1.000.01%
  • solanaSolana(SOL)$83.51-1.33%
  • tronTRON(TRX)$0.2867751.07%
  • Figure HelocFigure Heloc(FIGR_HELOC)$1.02-0.01%
  • dogecoinDogecoin(DOGE)$0.090311-0.14%
  • whitebitWhiteBIT Coin(WBT)$54.28-0.33%
  • USDSUSDS(USDS)$1.000.01%
  • cardanoCardano(ADA)$0.255092-1.18%
  • bitcoin-cashBitcoin Cash(BCH)$451.860.14%
  • leo-tokenLEO Token(LEO)$9.03-0.26%
  • HyperliquidHyperliquid(HYPE)$30.50-0.56%
  • moneroMonero(XMR)$345.46-1.08%
  • chainlinkChainlink(LINK)$8.71-0.90%
  • Ethena USDeEthena USDe(USDE)$1.000.05%
  • CantonCanton(CC)$0.1527690.08%
  • stellarStellar(XLM)$0.151170-0.63%
  • USD1USD1(USD1)$1.00-0.01%
  • RainRain(RAIN)$0.009014-0.84%
  • daiDai(DAI)$1.000.03%
  • hedera-hashgraphHedera(HBAR)$0.095941-0.74%
  • paypal-usdPayPal USD(PYUSD)$1.000.00%
  • litecoinLitecoin(LTC)$53.51-1.05%
  • avalanche-2Avalanche(AVAX)$8.95-0.80%
  • suiSui(SUI)$0.90-0.64%
  • the-open-networkToncoin(TON)$1.33-0.78%
  • zcashZcash(ZEC)$196.36-6.65%
  • shiba-inuShiba Inu(SHIB)$0.000005-0.89%
  • crypto-com-chainCronos(CRO)$0.075014-0.03%
  • tether-goldTether Gold(XAUT)$5,137.79-0.08%
  • World Liberty FinancialWorld Liberty Financial(WLFI)$0.097043-1.80%
  • MemeCoreMemeCore(M)$1.51-0.60%
  • pax-goldPAX Gold(PAXG)$5,170.89-0.16%
  • polkadotPolkadot(DOT)$1.46-1.93%
  • uniswapUniswap(UNI)$3.76-1.65%
  • mantleMantle(MNT)$0.68-0.43%
  • okbOKB(OKB)$100.24-2.27%
  • Circle USYCCircle USYC(USYC)$1.120.00%
  • Pi NetworkPi Network(PI)$0.209355-8.40%
  • BlackRock USD Institutional Digital Liquidity FundBlackRock USD Institutional Digital Liquidity Fund(BUIDL)$1.000.00%
  • Falcon USDFalcon USD(USDF)$1.000.01%
  • BittensorBittensor(TAO)$177.87-1.42%
  • Global DollarGlobal Dollar(USDG)$1.000.00%
  • AsterAster(ASTER)$0.69-1.48%
  • SkySky(SKY)$0.0733134.51%
  • aaveAave(AAVE)$108.70-1.52%
TradePoint.io
  • Main
  • AI & Technology
  • Stock Charts
  • Market & News
  • Business
  • Finance Tips
  • Trade Tube
  • Blog
  • Shop
No Result
View All Result
TradePoint.io
No Result
View All Result

Building a Secure and Memory-Enabled Cipher Workflow for AI Agents with Dynamic LLM Selection and API Integration

August 12, 2025
in AI & Technology
Reading Time: 6 mins read
A A
Building a Secure and Memory-Enabled Cipher Workflow for AI Agents with Dynamic LLM Selection and API Integration
ShareShareShareShareShare

In this tutorial, we walk through building a compact but fully functional Cipher-based workflow. We start by securely capturing our Gemini API key in the Colab UI without exposing it in code. We then implement a dynamic LLM selection function that can automatically switch between OpenAI, Gemini, or Anthropic based on which API key is available. The setup phase ensures Node.js and the Cipher CLI are installed, after which we programmatically generate a cipher.yml configuration to enable a memory agent with long-term recall. We create helper functions to run Cipher commands directly from Python, store key project decisions as persistent memories, retrieve them on demand, and finally spin up Cipher in API mode for external integration. Check out the FULL CODES here.

import os, getpass
os.environ["GEMINI_API_KEY"] = getpass.getpass("Enter your Gemini API key: ").strip()


import subprocess, tempfile, pathlib, textwrap, time, requests, shlex


def choose_llm():
   if os.getenv("OPENAI_API_KEY"):
       return "openai", "gpt-4o-mini", "OPENAI_API_KEY"
   if os.getenv("GEMINI_API_KEY"):
       return "gemini", "gemini-2.5-flash", "GEMINI_API_KEY"
   if os.getenv("ANTHROPIC_API_KEY"):
       return "anthropic", "claude-3-5-haiku-20241022", "ANTHROPIC_API_KEY"
   raise RuntimeError("Set one API key before running.")

We start by securely entering our Gemini API key using getpass so it stays hidden in the Colab UI. We then define a choose_llm() function that checks our environment variables and automatically selects the appropriate LLM provider, model, and key based on what is available. Check out the FULL CODES here.

YOU MAY ALSO LIKE

Building Next-Gen Agentic AI: A Complete Framework for Cognitive Blueprint Driven Runtime Agents with Memory Tools and Validation

OpenAI is reportedly pushing back the launch of its ‘adult mode’ even further

def run(cmd, check=True, env=None):
   print("▸", cmd)
   p = subprocess.run(cmd, shell=True, text=True, capture_output=True, env=env)
   if p.stdout: print(p.stdout)
   if p.stderr: print(p.stderr)
   if check and p.returncode != 0:
       raise RuntimeError(f"Command failed: {cmd}")
   return p

We create a run() helper function that executes shell commands, prints both stdout and stderr for visibility, and raises an error if the command fails when check is enabled, making our workflow execution more transparent and reliable. Check out the FULL CODES here.

def ensure_node_and_cipher():
   run("sudo apt-get update -y && sudo apt-get install -y nodejs npm", check=False)
   run("npm install -g @byterover/cipher")

We define ensure_node_and_cipher() to install Node.js, npm, and the Cipher CLI globally, ensuring our environment has all the necessary dependencies before running any Cipher-related commands. Check out the FULL CODES here.

def write_cipher_yml(workdir, provider, model, key_env):
   cfg = """
llm:
 provider: {provider}
 model: {model}
 apiKey: ${key_env}
systemPrompt:
 enabled: true
 content: |
   You are an AI programming assistant with long-term memory of prior decisions.
embedding:
 disabled: true
mcpServers:
 filesystem:
   type: stdio
   command: npx
   args: ['-y','@modelcontextprotocol/server-filesystem','.']
""".format(provider=provider, model=model, key_env=key_env)


   (workdir / "memAgent").mkdir(parents=True, exist_ok=True)
   (workdir / "memAgent" / "cipher.yml").write_text(cfg.strip() + "n")

We implement write_cipher_yml() to generate a cipher.yml configuration file inside a memAgent folder, setting the chosen LLM provider, model, and API key, enabling a system prompt with long-term memory, and registering a filesystem MCP server for file operations. Check out the FULL CODES here.

def cipher_once(text, env=None, cwd=None):
   cmd = f'cipher {shlex.quote(text)}'
   p = subprocess.run(cmd, shell=True, text=True, capture_output=True, env=env, cwd=cwd)
   print("Cipher says:n", p.stdout or p.stderr)
   return p.stdout.strip() or p.stderr.strip()

We define cipher_once() to run a single Cipher CLI command with the provided text, capture and display its output, and return the response, allowing us to interact with Cipher programmatically from Python. Check out the FULL CODES here.

def start_api(env, cwd):
   proc = subprocess.Popen("cipher --mode api", shell=True, env=env, cwd=cwd,
                           stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
   for _ in range(30):
       try:
           r = requests.get("http://127.0.0.1:3000/health", timeout=2)
           if r.ok:
               print("API /health:", r.text)
               break
       except: pass
       time.sleep(1)
   return proc

We create start_api() to launch Cipher in API mode as a subprocess, then repeatedly poll its /health endpoint until it responds, ensuring the API server is ready before proceeding. Check out the FULL CODES here.

def main():
   provider, model, key_env = choose_llm()
   ensure_node_and_cipher()
   workdir = pathlib.Path(tempfile.mkdtemp(prefix="cipher_demo_"))
   write_cipher_yml(workdir, provider, model, key_env)
   env = os.environ.copy()


   cipher_once("Store decision: use pydantic for config validation; pytest fixtures for testing.", env, str(workdir))
   cipher_once("Remember: follow conventional commits; enforce black + isort in CI.", env, str(workdir))


   cipher_once("What did we standardize for config validation and Python formatting?", env, str(workdir))


   api_proc = start_api(env, str(workdir))
   time.sleep(3)
   api_proc.terminate()


if __name__ == "__main__":
   main()

In main(), we select the LLM provider, install dependencies, and create a temporary working directory with a cipher.yml configuration. We then store key project decisions in Cipher’s memory, query them back, and finally start the Cipher API server briefly before shutting it down, demonstrating both CLI and API-based interactions.

In conclusion, we have a working Cipher environment that securely manages API keys, selects the right LLM provider automatically, and configures a memory-enabled agent entirely through Python automation. Our implementation includes decision logging, memory retrieval, and a live API endpoint, all orchestrated in a Notebook/Colab-friendly workflow. This makes the setup reusable for other AI-assisted development pipelines, allowing us to store and query project knowledge programmatically while keeping the environment lightweight and easy to redeploy.


Check out the FULL CODES here. Feel free to check out our GitHub Page for Tutorials, Codes and Notebooks. Also, feel free to follow us on Twitter and don’t forget to join our 100k+ ML SubReddit and Subscribe to our Newsletter.


Asif Razzaq is the CEO of Marktechpost Media Inc.. As a visionary entrepreneur and engineer, Asif is committed to harnessing the potential of Artificial Intelligence for social good. His most recent endeavor is the launch of an Artificial Intelligence Media Platform, Marktechpost, which stands out for its in-depth coverage of machine learning and deep learning news that is both technically sound and easily understandable by a wide audience. The platform boasts of over 2 million monthly views, illustrating its popularity among audiences.

Credit: Source link

ShareTweetSendSharePin

Related Posts

Building Next-Gen Agentic AI: A Complete Framework for Cognitive Blueprint Driven Runtime Agents with Memory Tools and Validation
AI & Technology

Building Next-Gen Agentic AI: A Complete Framework for Cognitive Blueprint Driven Runtime Agents with Memory Tools and Validation

March 8, 2026
OpenAI is reportedly pushing back the launch of its ‘adult mode’ even further
AI & Technology

OpenAI is reportedly pushing back the launch of its ‘adult mode’ even further

March 7, 2026
NASA’s DART spacecraft changed a binary asteroid’s orbit around the sun, in a first for a human-made object
AI & Technology

NASA’s DART spacecraft changed a binary asteroid’s orbit around the sun, in a first for a human-made object

March 7, 2026
OpenAI’s head of robotics resigns following deal with the Department of Defense
AI & Technology

OpenAI’s head of robotics resigns following deal with the Department of Defense

March 7, 2026
Next Post
The Only Hypocritical Advice We Give On This Show

The Only Hypocritical Advice We Give On This Show

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Search

No Result
View All Result
Meta signs a multimillion dollar AI licensing deal with News Corp

Meta signs a multimillion dollar AI licensing deal with News Corp

March 3, 2026
Trump says he ‘might have forced Israel’s hand’ in striking Iran first

Trump says he ‘might have forced Israel’s hand’ in striking Iran first

March 7, 2026
Google ends its 30 percent app store fee and welcomes third-party app stores

Google ends its 30 percent app store fee and welcomes third-party app stores

March 4, 2026

About

Learn more

Our Services

Legal

Privacy Policy

Terms of Use

Bloggers

Learn more

Article Links

Contact

Advertise

Ask us anything

©2020- TradePoint.io - All rights reserved!

Tradepoint.io, being just a publishing and technology platform, is not a registered broker-dealer or investment adviser. So we do not provide investment advice. Rather, brokerage services are provided to clients of Tradepoint.io by independent SEC-registered broker-dealers and members of FINRA/SIPC. Every form of investing carries some risk and past performance is not a guarantee of future results. “Tradepoint.io“, “Instant Investing” and “My Trading Tools” are registered trademarks of Apperbuild, LLC.

This website is operated by Apperbuild, LLC. We have no link to any brokerage firm and we do not provide investment advice. Every information and resource we provide is solely for the education of our readers. © 2020 Apperbuild, LLC. All rights reserved.

No Result
View All Result
  • Main
  • AI & Technology
  • Stock Charts
  • Market & News
  • Business
  • Finance Tips
  • Trade Tube
  • Blog
  • Shop

© 2023 - TradePoint.io - All Rights Reserved!