SDK Resource Management
Manage project resources and Team memory settings programmatically.
#SDK Resource Configuration
Use Agent or Swarm constructor declarations for assets needed by that scope. Use client.resources, client.skills, and client.memory to manage stored assets explicitly. These operations require an authenticated client and the server's permissions for the target scope. The snippets on this page assume MAIVN_API_KEY is set in the environment.
#Attach a skill
Constructor skills accepts Skill objects or dictionaries matching that model. A skill needs a name, description, and one to eight steps. Each step has a positive index and a non-empty action.
from maivn import Agent, Skill, SkillStep
summarization = Skill(
name="support-summary",
description="Summarize a support case with a decision and supporting evidence.",
steps=(SkillStep(index=1, action="State the decision and cite the case facts."),),
)
agent = Agent(name="support-agent")
agent.add_skill(summarization) # Registers remotely and attaches the returned ID.add_skill registers remotely and attaches the returned skill ID. Constructor skills=[...] only normalizes and stores the declarations in this SDK. It does not register or attach them automatically. Use add_skill or attach_skill when the skill must participate in an invocation. Use Skill for constructor skill entries.
Two related methods work on Agent and Swarm alike. add_skill_set(...) registers a SkillSet tree, or a path to a Markdown skill set, for that scope. Memory and Recall covers the format. use_skills(query, limit=16) opts the scope into automatic skill retrieval on later runs. The limit is at most 16.
#Attach a resource
Constructor resources accepts dictionaries. Supply a non-empty text_content or a readable file, plus name and mime_type. To bind the uploaded resource to this agent, set binding_type="agent". Use "swarm" for a swarm.
from maivn import Agent
agent = Agent(
name="support-agent",
resources=[{
"file": "support-policy.md",
"name": "Support policy",
"mime_type": "text/markdown",
"binding_type": "agent",
}],
)Registration runs before the first invocation and is cached on that scope instance. Constructor resources are uploaded as shared project knowledge that every customer of the agent can read. Without binding_type, this constructor path uploads without creating an agent/swarm binding. path, content_base64, and a resource ID alone are not supported content inputs for this path.
To replace a stored resource by ID or upload bytes directly, use the resource client instead. Do not expect changing a file after the scope's first invocation to trigger another upload.
#Manage stored resources
Every new record is either shared project knowledge or belongs to one customer. The server refuses an unclassified create with HTTP 422 and the code memory_classification_required. From a project-level client, mark deliberately authored knowledge with ResourceScopeRequest(shared=True). To store something for one customer, use the for_user facade described below.
from pathlib import Path
from maivn import Client, ResourceScopeRequest, ResourceUploadOptions
client = Client()
shared = ResourceScopeRequest(shared=True)
resource = client.resources.upload(
Path("support-policy.md").read_bytes(),
media_type="text/markdown",
name="Support policy",
options=ResourceUploadOptions(scope=shared),
)
client.resources.bind(
resource.resource_id, binding_type="agent", target_id="support-agent",
)
# Supply an existing ID when uploading a replacement version.
replacement = client.resources.upload(
Path("support-policy.md").read_bytes(),
media_type="text/markdown",
name="Support policy",
options=ResourceUploadOptions(resource_id=resource.resource_id, scope=shared),
)The server compares content hashes. Reusing bytes can reuse an existing resource, while replacement content can create a new version. ResourceRecord.deduplicated tells you which happened. The upload request still sends the bytes: deduplication is not a promise of zero network traffic. Empty content raises ValueError before any request.
In a project that keeps private data in its own custody, uploads are redacted before they are stored. ResourceUploadOptions(pii_whitelist=...) says what may stay visible, for example the dates and times on a scanned timesheet. It covers text documents as well as photographs and scanned PDFs. See Private Data.
#Resource models
A ResourceRecord carries:
- identity:
memory_id,resource_id,resource_thread_id,name,description,media_type,content_hash,size_bytes - placement:
scope(aMemoryScope),binding_type("portal","agent"or"swarm"),tags,metadata - lifecycle:
status("registered","superseded","deleted"or"error"),processing_status("pending","processing","processed","needs_ocr","ready","failed","quarantined"or"redaction_failed"),failure_reason,deduplicated,created_at,updated_at - extracted content:
markdownandstructure, when extraction has produced them
from maivn import ResourcePatch
records = client.resources.list(status="registered", processing_status="ready", limit=20)
updated = client.resources.patch(
resource.resource_id,
ResourcePatch(tags=("policy", "support"), sharing_scope="project"),
)
removed = client.resources.delete(resource.resource_id)
assert removed.successlist takes query, status (default "registered", with "all" to include the rest), processing_status (default "all") and limit (default 50), and returns a tuple of ResourceRecord.
delete is a soft deletion and works only on Portal-scoped resources. Call rebind first for a resource bound to an agent or swarm, which returns it to Portal scope. restore brings a deleted resource back to registered Portal scope. Uploading a deleted resource's identical bytes again also restores it: the record keeps its resource ID, returns to registered, and reports deduplicated=True, instead of the upload failing with HTTP 409. Each method has an async counterpart prefixed with a.
#Manage assets for one customer
client.resources.for_user(user_id), client.skills.for_user(user_id) and client.memory.for_user(user_id) return independent facades that act for a single customer. Run them from a trusted backend that derives user_id from its own authenticated session. Records created through a facade belong to that customer, and list calls see only that customer's records. The default sdk-user ID and blank IDs are rejected. for_user is also available on each nested client, such as client.memory.insights.
#Manage skills and memory
These methods also have async counterparts. First-class skill authoring uses Skill and SkillSet. Memory CRUD uses MemorySkillCreate, MemorySkillUpdate, MemoryInsightCreate, and MemoryInsightUpdate. They are different request models, so do not interchange them. Memory delete returns MemoryDeleteResponse, and promote takes target_scope="project" or "org". New skills, skill sets and memory records follow the same classification rule as resources: set scope=...(shared=True) on the request or use a for_user facade.
client.skills.delete(skill_id) (async adelete) deletes a first-class skill, one made with skills.create or Agent.add_skill. Pass its Skill.memory_id. It returns SkillDeleteResponse(success=True); an unknown ID raises MaivnHTTPError (404 unknown_skill). Skill sets that listed the skill keep its ID, and skill_sets.get skips it. client.memory.skills.delete(memory_id) is a separate store: it accepts only IDs from memory.skills.create or memory.skills.list, the learned-skill store, which also holds AI-generated skills. A run that saves memory can create learned skills unless you set MemoryConfig(persistence_mode='persist_none').
for receipt in client.memory.enrichments.list(session_id):
print(receipt)A response or extraction-start event does not prove persistence completed. Inspect the returned receipts when the application needs that outcome.
#Configure invocation memory
Use MemoryConfig to control retrieval and persistence. See the Session Config reference. Administrative asset operations and invocation memory policy are separate.
Your team's memory policy still applies to writes made through the SDK. Creating or promoting a skill or insight and uploading a resource are refused with HTTP 403 memory_persistence_disabled when the team's memory switch is off or its ceiling is No storage. The call raises MaivnHTTPError with status_code == 403 and code == 'memory_persistence_disabled'. HTTP 503 memory_policy_unavailable means the platform could not read the policy, so nothing was stored; listing skills and insights can return it too. Retry a 503. Do not retry a 403 until the policy changes. See Team memory policy.