Expand description
Knowledge sources, scopes, ingestion requests, and retrieval policies. Inputs for privately managed knowledge ingestion and retrieval policy.
These values carry caller-authored sources and scope choices, not retrieval internals or Database adapters. Nonempty ingestion atomically replaces the addressed source set. An empty request is a no-op after scope validation; it is not a deletion request. The receiving operation validates which scopes it owns and whether the selected backend supports managed knowledge.
Retrieval is private and happens during a prompt. KnowledgePolicy::only
narrows eligible owner scopes; it does not promise that a model will quote
every source or follow requested wording. Database scope is shared only when
callers deliberately supply the same Database domain. Agent and Workspace
shutdown preserve sources for reopen; Conversation close removes its owned
sources. Reopen must receive a compatible Database as well as control-plane
storage; missing or mismatched persisted knowledge is an error.
§Local ingestion and scope validation
This executes ingestion with embedded Lance StateStore and memory LanceDB Database, without inference or an Ollama server. These are separate products: the StateStore holds control-plane records; the Database holds source content. The request carries sources, never private retrieval context or an adapter.
use std::{num::NonZeroUsize, time::Duration};
use agents_kit::{AgentBackend, AgentBuilder, AgentStorage};
use agents_kit::config::{AgentConfig, CustomAgentConfig, CustomLoopLimits, CustomToolApproval};
use agents_kit::knowledge::{IngestKnowledgeRequest, KnowledgePolicy, KnowledgeScope, KnowledgeSource};
use agents_kit::{model::ModelSelector, tool::ToolSelection};
use providers_kit::{Provider, ProviderConfig,
config::{OllamaConfig, ProviderKind, TransportConfig}};
use storage_kit::{Database, StateStore,
database::config::{DatabaseConfig, LanceConfig},
state::config::{LanceStateStoreConfig, StateStoreConfig}};
let store = StateStore::connect(StateStoreConfig::Lance(LanceStateStoreConfig::memory())).await?;
let database = Database::connect(DatabaseConfig::lance(
LanceConfig::embedded_path("memory://"))).await?;
let custom = CustomAgentConfig::new(ModelSelector::new("exact-model")?,
ToolSelection::None, CustomLoopLimits::new(4, 0, 1)?, CustomToolApproval::Deny)?;
let config = AgentConfig::new(custom.into(), Duration::from_secs(10), NonZeroUsize::MIN)?;
let provider = Provider::from_config(ProviderConfig::new(
ProviderKind::Ollama(OllamaConfig::local()), TransportConfig::default()))?;
let agent = AgentBuilder::create(config, AgentStorage::new(store))
.with_provider(provider).with_knowledge_database(database).build().await?;
let outcome = async {
agent.ingest_knowledge(IngestKnowledgeRequest::new(vec![
KnowledgeSource::text("runbook", "Incident runbook", "Escalate service incidents.")?,
])?.with_scope(KnowledgeScope::Agent)).await?;
agent.ingest_knowledge(IngestKnowledgeRequest::new(vec![])?
.with_scope(KnowledgeScope::Agent)).await?; // retains the runbook
let invalid = agent.ingest_knowledge(IngestKnowledgeRequest::new(vec![])?
.with_scope(KnowledgeScope::Conversation)).await.unwrap_err();
assert_eq!(invalid.kind(), agents_kit::error::ErrorKind::InvalidInput);
let request = agents_kit::prompt::PromptRequest::new("How are incidents escalated?")?
.with_knowledge_policy(KnowledgePolicy::only(vec![KnowledgeScope::Agent])?)?;
assert_eq!(request.knowledge_policy(),
Some(&KnowledgePolicy::Only(vec![KnowledgeScope::Agent])));
// Sending this request through a Conversation requires the configured model.
Ok::<(), Box<dyn std::error::Error>>(())
}.await;
let shutdown = agent.shutdown().await;
outcome?;
shutdown?;Structs§
- Ingest
Knowledge Request - Validated source set for one managed-knowledge ingestion operation.
Enums§
- Knowledge
Policy - Retrieval policy for managed knowledge.
- Knowledge
Scope - A portable ownership scope from which managed knowledge may be retrieved.
- Knowledge
Source - Caller-authored content for managed-knowledge ingestion.