计划执行与检查节点
executing-plans
按既定实施计划完成工作,保持过程检查和反馈。
agents-and-llm-orchestration【效率与协作】Build txtai LLM, RAG, and Agent workflows with backend selection, tools, templates, teams, and troubleshooting guidance.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Use this sub-skill when the task is to connect txtai generation, retrieval, and agentic tool use. It covers LLM, RAG, and Agent construction, YAML configuration, tool definitions, prompt templates, agent teams, backend selection, and optional dependency troubleshooting.
For low-level embeddings store creation and query tuning, route to embeddings-search. For deterministic pipeline/workflow task chains, route to pipelines-and-workflows. For serving agents/RAG over API, OpenAI-compatible endpoints, or hosted app deployment, route to api-and-deployment.
| User goal | Use |
|---|---|
| Generate text directly | LLM(path=None, method=None, **kwargs) |
| Answer with retrieved context | RAG(similarity, path, template=..., context=..., output=...) |
| Let a model choose tools over multiple steps | Agent(model=..., tools=[...], max_steps=...) |
| Build multi-agent research/delegation | Agents as tool targets inside another Agent |
| Define via YAML/Application | top-level llm:, rag:, and agent: sections |
| Validate RAG config safely | python scripts/rag_config_template.py --write-template rag_template.py |
from txtai import Agent, Embeddings, LLM, RAG
print(LLM)
print(RAG)
print(Agent)
If constructing Agent(...) raises ImportError: smolagents is not available - install "agent" extra to enable, install an agent-capable environment such as pip install "txtai[agent]". If LLM backends fail, see backend-and-tooling.
from txtai import LLM
llm = LLM("ibm-granite/granite-4.0-350m")
answer = llm("Summarize retrieval augmented generation", maxlength=256)
LLM accepts a model path, optional method, and backend keyword arguments. It supports strings, lists of strings, chat-message dictionaries with role and content, streaming via stream=True, stop strings, defaultrole, and stripthink cleanup. Use method="transformers", method="llama.cpp", method="litellm", or a custom generation class path when inference cannot be inferred from the model path.
from txtai import Embeddings, RAG
embeddings = Embeddings(content=True)
embeddings.index([
("install", "txtai supports semantic search, RAG, agents, workflows and APIs"),
("agent", "txtai agents use tools such as Python functions, embeddings stores and web search"),
])
template = """
Answer using only the context.
Question: {question}
Context: {context}
"""
rag = RAG(
embeddings,
"ibm-granite/granite-4.0-350m",
template=template,
system="You answer from retrieved context.",
context=3,
output="flatten",
)
result = rag("What can txtai agents use?", maxlength=256)
RAG joins a similarity source with a generator or question-answering pipeline. The similarity source can be an Embeddings instance, a Similarity pipeline, a callable batch searcher, or an Application-provided embeddings index. Build and persist retrieval stores with embeddings-search before focusing on prompt generation here.
from datetime import datetime
from txtai import Agent
def today() -> str:
"""
Gets the current date.
Returns:
current date in ISO format
"""
return datetime.today().isoformat()
agent = Agent(
model="Qwen/Qwen3-4B-Instruct-2507",
tools=[today, "websearch"],
max_steps=5,
)
answer = agent("What is today's date and why might it matter for a news search?", maxlength=2048)
Use agents for multi-step questions where tool choice matters. Prefer plain RAG or deterministic workflows for simple, repeatable flows.
tools; type hints and Google-style docstrings improve generated tool schemas.{"name": "lookup", "description": "...", "inputs": {...}, "target": callable}.{"name": "kb", "description": "Searches the knowledge base", "path": "index-path"} or {"target": embeddings}; results are lists of dicts with id, text, and score when content is available.bash, defaults, edit, glob, grep, python, read, todowrite, websearch, webview, and write.http://localhost:8000/mcp load a Model Context Protocol tool collection..md load a skill.md-style tool with frontmatter name and description.Agents can be tool targets for a supervisor agent.
from txtai import Agent, LLM
llm = LLM("Qwen/Qwen3-4B-Instruct-2507")
websearcher = Agent(model=llm, tools=["websearch"], max_steps=3)
supervisor = Agent(
model=llm,
tools=[{
"name": "websearcher",
"description": "Searches the web and returns concise findings",
"target": websearcher,
}],
max_steps=6,
)
Share a single LLM instance when team members should use the same backend configuration. Keep each agent tool description narrow so the supervisor can choose correctly.
llm:
path: Qwen/Qwen3-4B-Instruct-2507
agent:
researcher:
max_steps: 5
tools:
- websearch
- name: today
description: Gets the current date
target: package.module.today
rag:
path: ibm-granite/granite-4.0-350m
template: |
Answer using only the context.
Question: {question}
Context: {context}
output: flatten
context: 3
Application(config) resolves configured pipelines first, then agents, then embeddings. A configured rag: pipeline can receive the Application embeddings index when its similarity is omitted. In agent: sections, target values are resolved as configured pipelines, workflows, or importable callables.
output | Shape |
|---|---|
default | (name, answer) tuples, or dicts with answer for dict/string inputs |
flatten | answer strings only |
reference | (name, answer, reference) tuples or dicts with references |
RAG input can be a string, a list of strings, tuples shaped like (name, query, question, snippet), or dict rows with name, query, question, and snippet. Use output="flatten" for simple chat answers and output="reference" when the caller needs source ids from retrieved context.
LLM, RAG, and Agent in the target environment.{question} and {context}.Agent(model=..., tools=[], max_steps=1) or by importing smolagents directly.