@tinyclaw/core
The foundational package containing Tiny Claw’s agent runtime, conversation loop, database layer, and built-in LLM provider.Installation
Main Exports
Agent Loop
agentLoop()
The core conversational agent loop that handles messages, tool execution, and streaming responses.
The user’s input message
Unique identifier for the user (e.g.,
"web:owner", "discord:123456")Complete agent context including database, provider, tools, and configuration
Optional streaming callback for real-time updates
The agent’s final response after processing
- Multi-turn conversation with tool execution
- Prompt injection defense with boundary markers
- Owner authority enforcement (owner vs. friend permissions)
- Shield integration for security policy enforcement
- Adaptive memory integration for context retrieval
- Em-dash sanitization for clean output
- Background task result injection
- Automatic history compaction
Database
createDatabase(path: string): Database
Creates a SQLite-backed database for conversation history, memory, sub-agents, and more.
Absolute path to the SQLite database file
Database instance with methods for messages, memory, compactions, sub-agents, episodic memory, task metrics, and blackboard
saveMessage(userId, role, content)- Save a conversation messagegetHistory(userId, limit?)- Retrieve conversation historygetMessageCount(userId)- Count messages for a usergetMessageTimestamps(userId)- Get message timestamps (ascending)deleteMessagesBefore(userId, beforeTimestamp)- Delete old messagesdeleteMessagesForUser(userId)- Delete all messages for a user
saveMemory(userId, key, value)- Store a memory entrygetMemory(userId)- Retrieve all memories as a key-value object
saveCompaction(userId, summary, replacedBefore)- Save a compaction summarygetLatestCompaction(userId)- Get the most recent compaction
saveSubAgent(record)- Create a new sub-agentgetSubAgent(id)- Retrieve a sub-agent by IDgetActiveSubAgents(userId)- Get active/suspended sub-agentsgetAllSubAgents(userId, includeDeleted?)- Get all sub-agentsupdateSubAgent(id, updates)- Update sub-agent fieldsdeleteExpiredSubAgents(beforeTimestamp)- Clean up soft-deleted sub-agentsarchiveStaleSuspended(inactiveBefore)- Archive inactive suspended sub-agents
saveEpisodicEvent(record)- Store an episodic memory eventgetEpisodicEvent(id)- Retrieve a single eventgetEpisodicEvents(userId, limit?)- Get recent episodic eventsupdateEpisodicEvent(id, updates)- Update importance/access countdeleteEpisodicEvents(ids)- Delete events by IDsearchEpisodicFTS(query, userId, limit?)- Full-text search (FTS5)decayEpisodicImportance(userId, olderThanDays, decayFactor)- Apply temporal decaypruneEpisodicEvents(userId, maxImportance, maxAccessCount, olderThanMs)- Prune low-value events
saveTaskMetric(record)- Log task execution metricsgetTaskMetrics(taskType, tier, limit?)- Retrieve metrics for analysis
saveBlackboardEntry(entry)- Post a problem or proposalgetBlackboardEntry(id)- Retrieve an entrygetBlackboardProposals(problemId)- Get proposals for a problemgetActiveProblems(userId)- Get open problemsresolveBlackboardProblem(problemId, synthesis)- Mark problem as resolvedcleanupBlackboard(olderThanMs)- Clean up old resolved entries
LLM Provider
createOllamaProvider(config: OllamaConfig): Provider
Creates the built-in Ollama Cloud provider.
Explicit API key (optional, defaults to secrets manager lookup)
Secrets manager for API key resolution
Model tag to use (default: from
DEFAULT_MODEL)Base URL for Ollama API (default:
"https://ollama.com")Provider instance with
chat() and isAvailable() methodschat(messages, tools?)- Send messages and receive a responseisAvailable()- Check if the provider is reachable and authenticated
Model Constants
Default model tag:
"kimi-k2.5:cloud"Default provider name:
"ollama"Default Ollama API base URL:
"https://ollama.com"Map of built-in model tags to display names
Array of all built-in model tags
Owner Authority
Cryptographic utilities for owner authentication (TOTP, backup codes, session tokens).generateTotpSecret()- Generate a base32 TOTP secretgenerateTotpCode(secret)- Generate a 6-digit TOTP codeverifyTotpCode(secret, code)- Verify a TOTP code (30s window)createTotpUri(secret, label)- Create otpauth:// URI for QR codesgenerateSessionToken()- Generate a secure session tokengenerateBackupCodes(count)- Generate backup codesgenerateRecoveryToken()- Generate a recovery tokensha256(text)- SHA-256 hash utility
Update Checker
checkForUpdate(currentVersion)- Check npm for updatesbuildUpdateContext(updateInfo?)- Build system prompt contextdetectRuntime()- Detect runtime environment (npm/bun/docker/binary)isNewerVersion(current, latest)- Compare semver versions
Onboarding Messages
Types
See @tinyclaw/types for all type definitions used by@tinyclaw/core.
Related Packages
- @tinyclaw/types - TypeScript type definitions
- @tinyclaw/config - Configuration management
- @tinyclaw/memory - Adaptive memory engine
- @tinyclaw/delegation - Sub-agent delegation
- @tinyclaw/compactor - Conversation compaction
- @tinyclaw/shield - Runtime security enforcement