Skip to content

Instantly share code, notes, and snippets.

@grahama1970
grahama1970 / 00_README.md
Last active February 27, 2025 16:17
Method Validator: An AI agent's tool for autonomous Python package analysis. Discovers and validates existing methods, preventing redundant code creation. Features smart filtering, detailed API analysis, exception handling intelligence, and machine-readable output. Perfect for AI-driven development.

✅ Method Validator - AI Agent's API Discovery Tool

A specialized tool designed for AI agents to autonomously analyze Python packages, discover existing methods, and validate APIs before implementing new solutions. This tool helps prevent redundant code creation by identifying existing functionality in non-standard packages.

Features

  • Smart Package Analysis: Automatically filters out standard library and common utility packages
  • Method Discovery: Quick scanning of available methods with categorization
  • Detailed Analysis: In-depth examination of method signatures, parameters, and return types
  • Exception Analysis: Identifies and prioritizes relevant error handling patterns
@grahama1970
grahama1970 / 00_README.md
Last active February 22, 2025 16:46
MCP Python & TypeScript SDKs fail to run persistently in Docker. mcp.run() exits immediately despite a defined lifespan, breaking deployments. No official examples work. If neither SDK functions in real-world use, MCP may not be production-ready.

README: MCP SDK Docker Deployment Issue

Problem Summary

MCP's Python and TypeScript SDKs fail to run persistently in Docker. Despite setting a lifespan in the Python SDK, mcp.run() exits immediately, shutting down the container. This issue affects all tested MCP projects, making real-world deployment impossible.

Reproducible Steps

  1. Create an MCP server using the Python SDK with a lifespan function to manage resources.
  2. Build and run the Docker container.
  3. The MCP server connects to ArangoDB, logs success, and then exits immediately.
  4. The same behavior is observed with the TypeScript SDK.
@grahama1970
grahama1970 / LPN_for_Tool_Execution_and_Config_Strategy.md
Last active February 21, 2025 16:07
LPN embeds tool configs in a latent space, optimizing execution order and parameters via RAG and search. It’s more accurate and consistent than LLM prompting but requires training. Ideal for multi-tool workflows, it reduces errors but is complex to set up. A toy script demonstrates this.

🚀 Latent Program Networks (LPN) for Tool Execution Strategies

This README explains how a Latent Program Networks (LPN)-inspired approach can generate tool execution strategies for multi-tool tasks in an agent workflow. This method offers advantages over relying solely on Large Language Models (LLMs) for tool strategy via prompting. A toy Python script demonstrates the concept in action.


🤖 What is LPN?

Latent Program Networks (LPNs), originally designed for abstract reasoning (e.g., the ARC benchmark), embed "rules" or "completions" into a searchable latent space. Here, we adapt LPNs to embed tool configurations and execution order, enabling smooth coordination of multiple tools (e.g., generate_summary and create_pie_chart) for tasks like summarization and data visualization.

@grahama1970
grahama1970 / 00_README.md
Last active February 20, 2025 18:26
This README outlines the limitations of the Cursor MCP Environment, highlighting constraints on package access and environment variables. Key issues include reliance on the Python standard library and the need to hardcode sensitive data. Workarounds involve adapting scripts accordingly. Open questions focus on potential configurations for improv…

Cursor MCP Environment Limitations

Discovered Constraints

  1. Package Access

    • Cannot access project's virtual environment
    • Limited to Python standard library
    • No ability to install additional packages
  2. Environment Variables

  • Cannot access project's .env files
@grahama1970
grahama1970 / agent_bubble.py
Last active February 26, 2025 18:31
Dynamic, safe, self-contained Python execution environment using bubblewrap & uv. Generates code/requirements on-the-fly, creates an isolated persistent venv, and lays the groundwork for an LLM-driven adaptive system that installs only needed packages.
#!/usr/bin/env python3
"""
Dynamic and Adaptive Python Environment in a Bubblewrap Sandbox
Overview:
This project demonstrates a minimal, safe, and self-contained Python execution
environment using bubblewrap (bwrap) and uv. The goal is to provide a lightweight
alternative to Docker for running agent code—in this case, dynamically generated
Python code along with its dependencies—within an isolated sandbox.
#!/usr/bin/env python3
"""
Dynamic and Adaptive Python Environment in a Bubblewrap Sandbox
Overview:
This project demonstrates a minimal, safe, and self-contained Python execution
environment using bubblewrap (bwrap) and uv. The goal is to provide a lightweight
alternative to Docker for running agent codein this case, dynamically generated
Python code along with its dependencieswithin an isolated sandbox.
@grahama1970
grahama1970 / unsloth_student_teacher_training.py
Last active February 17, 2025 01:53
Student-Teacher-GRPO-Proof-of-Concept
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Enhanced Unsloth GRPO with Student-Teacher Reward Mechanism
------------------------------------------------------------
This script extends Unsloth's GRPO by implementing a novel student-teacher reward
mechanism for improved reasoning chains.
Key Components:
1. Student Model (Unsloth GRPO):
@grahama1970
grahama1970 / errors_to_json.py
Created February 15, 2025 15:43
Snippet: Example of using the bulk insert command for Python-Arango
import re
import json
from loguru import logger
from pathlib import Path
from arango import ArangoClient
from arango.database import StandardDatabase
from typing import Dict, Any
from search_tool.arangodb.generate_schema_for_llm.utils.arango_utils import initialize_database
from search_tool.shared_utils.json_utils import save_json_to_file
@grahama1970
grahama1970 / arango_dump.sh
Last active February 13, 2025 20:29
Arango Dump and Restore bash scripts
#!/bin/bash
# arangodump_db.sh
# This script dumps an ArangoDB database from a Docker container with a low memory batch size.
#
# Usage: ./arangodump_db.sh
# Make sure arangodump is in your PATH.
# This script dumps an ArangoDB database from a Docker container with a low memory batch size.
# The dump path follows the structure: backups/<database_name>/<timestamp>/arangodump
#
# Usage: ./arangodump_db.sh
@grahama1970
grahama1970 / create_error_code_collection.py
Last active February 12, 2025 13:27
This script handles the creation and population of an ArangoDB collection containing error codes and messages. It downloads an error code dataset from a specified URL, parses it into JSON format, and stores it in a collection for easy reference and querying. The script is designed to be run as a standalone utility to initialize or update the err…
"""
This script handles the creation and population of an ArangoDB collection containing error codes and messages.
It downloads an error code dataset from a specified URL, parses it into JSON format, and stores it in a collection
for easy reference and querying. The script is designed to be run as a standalone utility to initialize or update
the error code collection in an ArangoDB database.
"""
import requests
import csv
from arango import ArangoClient