agentleFS
dbtinoy-dbtinoy-/lexigram-framework-skills/ai-subsystem-quickstart/SKILL.md

ai-subsystem-quickstart

Skill1 starsChanged 3 months agoMITView on GitHub

Use when setting up the AI subsystem — LLM clients, RAG pipelines, agents, memory, or MCP servers in the Lexigram framework

  • Reads credentials

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Not calling result.map() on LLM responses — forget Result unwrapping discipline

    line 137

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

AI Subsystem Quickstart

Overview

Lexigram's AI stack is modular: 15+ lexigram-ai-* packages wired through AIModule. All follow contract-first DI — inject *Protocol, swap backends via config. See docs/guides/ai-*.md for deep dives.

LLM Client

from lexigram.contracts.ai.llm import LLMClientProtocol
from lexigram.contracts.ai.llm import ChatMessage, Role

class MyService:
    def __init__(self, llm: LLMClientProtocol):
        self.llm = llm

    async def summarize(self, text: str) -> Result[str, AIError]:
        messages = [ChatMessage(role=Role.USER, content=text)]
        result = await self.llm.complete(messages)
        return result.map_sync(lambda r: r.content)

RAG Pipeline

from lexigram.contracts.ai.rag import RAGPipelineProtocol, RAGContext

class QAService:
    def __init__(self, rag: RAGPipelineProtocol):
        self.rag = rag

    async def answer(self, question: str) -> Result[str, AIError]:
        result = await self.rag.execute(RAGContext(query=question))
        return result.map_sync(lambda r: r.answer)

Agents

from lexigram.contracts.ai.agents import AgentExecutorProtocol, ToolProtocol

class SearchTool(ToolProtocol):
    @property
    def name(self) -> str:
        return "search"

    @property
    def description(self) -> str:
        return "Search the docs"

    @property
    def parameters_schema(self) -> dict:
        return {"type": "object", "properties": {"query": {"type": "string"}}}

    async def execute(self, **kwargs) -> str:
        return f"Results for: {kwargs.get('query', '')}"

executor = await container.resolve(AgentExecutorProtocol)
result = await executor.run(agent, "Find docs about caching")  # run(agent, message, ...)

Configuration

LLM settings live in the top-level ai_llm section (not under ai:). providers is an ordered list — cascade order, first = highest priority:

Hosted (OpenAI, Anthropic, …):

ai_llm:
  providers:
    - name: primary
      provider: openai
      model: gpt-4-turbo
      api_key: ${OPENAI_API_KEY}
      temperature: 0.7
      max_tokens: 2048
      thinking:                     # For reasoning models
        budget_tokens: 4096

Local — any OpenAI-compatible server (Ollama, LM Studio, vLLM, llama.cpp):

ai_llm:
  providers:
    - name: local
      provider: openai_compatible
      model: llama3.2
      api_base: http://localhost:11434/v1   # Ollama default; swap for LM Studio / vLLM
      api_key: ollama                       # Local servers usually ignore the value

Shared knobs go under defaults: (temperature, max_tokens).

Module Registration

from lexigram.ai import AIModule

async with Application.boot(modules=[
    AIModule.configure(ai_config),
]) as app:
    llm = await app.container.resolve(LLMClientProtocol)

Testing

@module(imports=[AIModule.stub()])  # No-op AI
class TestModule(Module): pass

Quick Reference

PackageProtocolPurpose
lexigram-ai-llmLLMClientProtocolMulti-provider LLM (OpenAI, Anthropic, Ollama...)
lexigram-ai-ragRAGPipelineProtocolDocument retrieval + synthesis
lexigram-ai-agentsAgentExecutorProtocolReAct, plan-and-execute agents with tools
lexigram-ai-memoryMemoryStoreProtocolWorking, episodic, semantic memory
lexigram-ai-mcp—MCP server/client for external tools
lexigram-ai-guardGuardPipelineProtocolInput/output safety guards
lexigram-ai-governance—Cost tracking, budgets, rate limits
lexigram-ai-promptPromptTemplateProtocolPrompt templates and management
lexigram-ai-skillsSkillProtocolSkill/tool registry and execution
lexigram-ai-sessionSessionManagerProtocolConversation session management

Common Mistakes

  • Importing across AI sub-packages — use contracts + DI, never lexigram-ai-agents → lexigram-ai-llm
  • Reasoning models: thinking is off unless a ThinkingConfig is supplied; set ThinkingConfig(suppress=True) to strip thinking tokens from responses
  • Not calling result.map() on LLM responses — forget Result unwrapping discipline
  • Missing LLM fallback providers — single-provider setup has no resilience
  • Using AIModule.stub() when testing — otherwise tests call real APIs

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.