sage-libs API¶
Algorithm libraries: agents, RAG, tools, workflow optimization, and I/O utilities.
Layer: L3 (Core Libraries)
Overview¶
sage-libs provides reusable algorithm libraries and tools:
- Agents: Intelligent agent framework with planning and action
- RAG: Retrieval-Augmented Generation components
- Tools: Utility tools (search, image processing, web scraping)
- I/O: Data sources and sinks
- Context: Context management for agents and RAG
- Workflow: Workflow optimization framework
- Unlearning: Machine unlearning algorithms
Modules¶
Agents¶
::: sage.libs.agentic.agents options: show_root_heading: true members: - runtime - planning - action - profile
RAG (Retrieval-Augmented Generation)¶
Generator¶
::: sage.libs.rag.generator options: show_root_heading: true members: - OpenAIGenerator - VLLMGenerator
Retriever¶
::: sage.libs.rag.retriever options: show_root_heading: true members: - ChromaRetriever - MilvusRetriever
Promptor¶
::: sage.libs.rag.promptor options: show_root_heading: true members: - QAPromptor - ChatPromptor
I/O Utilities¶
Sources¶
::: sage.libs.io.source options: show_root_heading: true members: - FileSource - SocketSource - JSONFileSource - CSVFileSource - KafkaSource
Sinks¶
::: sage.libs.io.sink options: show_root_heading: true members: - TerminalSink - FileSink - PrintSink
Tools¶
::: sage.libs.tools options: show_root_heading: true members: - SearcherTool - ImageCaptioner - ArxivPaperSearcher
Workflow Optimization¶
::: sage.libs.workflow options: show_root_heading: true members: - WorkflowGraph - BaseOptimizer - WorkflowEvaluator
Quick Examples¶
RAG Pipeline¶
from sage.libs.rag.promptor import QAPromptor
from sage.libs.rag.retriever import ChromaRetriever
from sage.libs.rag.generator import OpenAIGenerator
# Build RAG pipeline
promptor = QAPromptor()
retriever = ChromaRetriever(collection_name="docs")
generator = OpenAIGenerator(model="gpt-4")
# Use in SAGE pipeline
stream = (env
.from_source(questions)
.map(promptor)
.map(retriever)
.map(generator)
.sink(output)
)
Agent Framework¶
from sage.libs.agentic.agents.profile.profile import BaseProfile
from sage.libs.agentic.agents.runtime.agent import AgentRuntime
from sage.libs.agentic.agents.planning.llm_planner import LLMPlanner
from sage.libs.agentic.agents.action.mcp_registry import MCPRegistry
profile = BaseProfile(name="assistant", role="research helper")
registry = MCPRegistry()
registry.register(search_tool)
registry.register(calculator_tool)
planner = LLMPlanner(generator=my_generator)
runtime = AgentRuntime(profile=profile, planner=planner, tools=registry)
result = runtime.execute({"query": "计算 2+2 并检索 AI 新闻"})
I/O Sources and Sinks¶
from sage.libs.io import FileSource, TerminalSink
# Create pipeline with I/O
stream = (env
.from_source(FileSource, {"file_path": "data.txt"})
.map(process_function)
.sink(TerminalSink, {})
)
Component Guides¶
RAG¶
Agents¶
- Agents Guide
- Agent Components - 查看导航栏 Libs AI 组件库 > Agents 章节
Tools¶
- Tools Introduction
- Individual Tool Docs - 查看导航栏 Libs AI 组件库 > Tools 章节
Design Decisions¶
See Also¶
- Libraries Guide
- RAG Examples - 查看导航栏 Libs AI 组件库 > RAG > 示例章节
- Agent Examples - 查看导航栏 Libs AI 组件库 > Agents > 示例章节