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
In this repository17 other files it gives its agents.
- auth-and-securitySkill
- caching-patternsSkill
- cli-code-generationSkill
- cli-config-and-inspectSkill
- cli-database-operationsSkill
- cli-project-scaffoldingSkill
- configuration-managementSkill
- creating-providers-and-modulesSkill
- database-repository-patternSkill
- events-and-messagingSkill
- lexigram-uiSkill
- multimedia-generationSkill
- real-time-webSkill
- resilience-patternsSkill
- testing-with-lexigramSkill
- using-result-and-error-codesSkill
- web-controllers-and-routingSkill
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
- Very specific: line 137
Not calling result.map() on LLM responses — forget Result unwrapping discipline
≈ “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.
Files
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: 4096Local — 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 valueShared 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): passQuick Reference
| Package | Protocol | Purpose |
lexigram-ai-llm | LLMClientProtocol | Multi-provider LLM (OpenAI, Anthropic, Ollama...) |
lexigram-ai-rag | RAGPipelineProtocol | Document retrieval + synthesis |
lexigram-ai-agents | AgentExecutorProtocol | ReAct, plan-and-execute agents with tools |
lexigram-ai-memory | MemoryStoreProtocol | Working, episodic, semantic memory |
lexigram-ai-mcp | — | MCP server/client for external tools |
lexigram-ai-guard | GuardPipelineProtocol | Input/output safety guards |
lexigram-ai-governance | — | Cost tracking, budgets, rate limits |
lexigram-ai-prompt | PromptTemplateProtocol | Prompt templates and management |
lexigram-ai-skills | SkillProtocol | Skill/tool registry and execution |
lexigram-ai-session | SessionManagerProtocol | Conversation 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
ThinkingConfigis supplied; setThinkingConfig(suppress=True)to strip thinking tokens from responses - Not calling
result.map()on LLM responses — forget Result unwrapping discipline - Missing LLM
fallbackproviders — single-provider setup has no resilience - Using
AIModule.stub()when testing — otherwise tests call real APIs
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
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.

