acontext-chatbot-integration

Acontext Chatbot Integration

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "acontext-chatbot-integration" with this command: npx skills add mbt1909432/acontext-skills/mbt1909432-acontext-skills-acontext-chatbot-integration

Acontext Chatbot Integration

Integration patterns for building AI chatbots with Acontext SDK - session management, disk tools, sandbox execution, and artifact storage.

Architecture

Core Principle: One Session = One Conversation = One Disk (1:1:1)

┌─────────────────────────────────────────────────────┐ │ Your Chatbot │ ├─────────────────────────────────────────────────────┤ │ LLM Client │ Tool Router │ Session Manager │ └──────┬───────┴───────┬───────┴────────┬─────────────┘ │ │ │ ▼ ▼ ▼ ┌─────────────────────────────────────────────────────┤ │ Acontext SDK (Storage Layer) │ ├─────────────────────────────────────────────────────┤ │ sessions.* disks.* sandboxes.* │ │ - storeMessage - create - create │ │ - getMessages - artifacts.* - execCommand │ │ - getTokenCounts - upsert - kill │ │ - delete - get │ └─────────────────────────────────────────────────────┘

Do NOT use database for messages! All messages via sessions.storeMessage() and sessions.getMessages() .

Quick Start

import { AcontextClient, DISK_TOOLS, SANDBOX_TOOLS } from "@acontext/acontext";

// 1. Initialize const client = new AcontextClient({ apiKey: process.env.ACONTEXT_API_KEY });

// 2. Create session + disk (1:1 binding) const session = await client.sessions.create({ user: "user@example.com" }); const disk = await client.disks.create();

// 3. Store message (MUST include format option!) await client.sessions.storeMessage(session.id, { role: "user", content: "Hello!" }, { format: "openai" });

// 4. Load messages const messages = await client.sessions.getMessages(session.id, { format: "openai" });

Reference Documentation

Topic File When to Read

API Reference api-reference.md SDK methods, parameters, return types

Implementation implementation.md Full code examples, Next.js routes

Session Management session-management.md Lifecycle, 1:1 binding, list management

Context Compression context-compression.md Token monitoring, auto-compression

Disk Path Mapping disk-path-mapping.md disk:: protocol, URL expiration

Vision API vision-api.md Multimodal content, image processing

Streaming streaming.md SSE server and client implementation

Skill System skill-system.md Mount Acontext skills into sandboxes

Session Cleanup session-cleanup.md Delete sessions, batch cleanup

Error Handling error-handling.md API errors, retry strategies

Debugging debugging.md Logging format, common issues

Troubleshooting troubleshooting.md 404 errors, tool sequence errors

Tool Categories

Disk Tools (DISK_TOOLS )

Tool Purpose

write_file_disk

Create/overwrite files

read_file_disk

Read file contents

replace_string_disk

Find and replace

list_disk

List directory

grep_disk / glob_disk

Search files

download_file_disk

Get public URL

const ctx = DISK_TOOLS.format_context(client, diskId); const result = await DISK_TOOLS.execute_tool(ctx, "write_file_disk", { filename: "notes.txt", content: "Hello", file_path: "/" });

Sandbox Tools (SANDBOX_TOOLS )

Tool Purpose

bash_execution_sandbox

Execute commands

text_editor_sandbox

Create/edit files

export_file_sandbox

Export to disk with URL

const ctx = SANDBOX_TOOLS.format_context(client, sandboxId, diskId); await SANDBOX_TOOLS.execute_tool(ctx, "text_editor_sandbox", { command: "create", path: "script.py", file_text: "print('Hello')" });

Critical Patterns

Message Sequence for Tool Calls

OpenAI API requires strict ordering: User → Assistant(tool_calls) → Tool Response

// 1. User message await client.sessions.storeMessage(sessionId, { role: "user", content: "Draw" }, { format: "openai" });

// 2. Assistant with tool_calls (MUST save!) await client.sessions.storeMessage(sessionId, { role: "assistant", content: "", tool_calls: [{ id: "call_xxx", type: "function", function: {...} }] }, { format: "openai" });

// 3. Tool response (MUST match tool_call_id!) await client.sessions.storeMessage(sessionId, { role: "tool", tool_call_id: "call_xxx", content: JSON.stringify({ result: "success" }) }, { format: "openai" });

Common Error: 400 An assistant message with 'tool_calls' must be followed by tool messages

Sandbox: No Heredoc Support

// WRONG - will hang! command: "python - << 'EOF'\ncode\nEOF"

// CORRECT - create file first, then execute await SANDBOX_TOOLS.execute_tool(ctx, "text_editor_sandbox", { command: "create", path: "script.py", file_text: "..." }); await SANDBOX_TOOLS.execute_tool(ctx, "bash_execution_sandbox", { command: "python3 script.py" });

Sandbox: Reuse sandbox_id

// CORRECT: Same sandbox_id across tool calls let sandboxId: string | undefined; const ctx1 = SANDBOX_TOOLS.format_context(client, sandboxId, diskId); await SANDBOX_TOOLS.execute_tool(ctx1, "text_editor_sandbox", {...}); sandboxId = ctx1.sandbox_id; // Save for reuse!

const ctx2 = SANDBOX_TOOLS.format_context(client, sandboxId, diskId); await SANDBOX_TOOLS.execute_tool(ctx2, "bash_execution_sandbox", {...}); // Now can find the file created earlier!

disk:: Protocol

Use disk:: for permanent image references (S3 URLs expire in ~1 hour):

// Tool returns { diskPath: "disk::artifacts/chart.png" }

// Frontend transforms for rendering chart

See disk-path-mapping.md for implementation.

Tool Routing Pattern

const DISK_TOOL_NAMES = ["write_file_disk", "read_file_disk", "list_disk", ...]; const SANDBOX_TOOL_NAMES = ["bash_execution_sandbox", "text_editor_sandbox", ...];

async function executeToolCall(toolCall, context) { const { name } = toolCall.function; const args = JSON.parse(toolCall.function.arguments || "{}");

if (DISK_TOOL_NAMES.includes(name)) { const ctx = DISK_TOOLS.format_context(context.client, context.diskId); return DISK_TOOLS.execute_tool(ctx, name, args); }

if (SANDBOX_TOOL_NAMES.includes(name)) { const ctx = SANDBOX_TOOLS.format_context(context.client, context.sandboxId, context.diskId); return SANDBOX_TOOLS.execute_tool(ctx, name, args); }

throw new Error(Unknown tool: ${name}); }

// Register with LLM const tools = [ ...DISK_TOOLS.to_openai_tool_schema(), ...SANDBOX_TOOLS.to_openai_tool_schema(), ];

Integration Checklist

  • Setup: Install @acontext/acontext , configure ACONTEXT_API_KEY

  • Sessions: Create on new chat, store every message with { format: "openai" }

  • Session + Disk: 1:1 binding, each session gets its own disk

  • Message Sequence: Always save tool responses after tool_calls

  • disk::: Tools return diskPath, frontend rewrites to API URL

  • Compression: Monitor tokens, apply strategies when >80K

  • Cleanup: Delete both Session AND Disk when deleting conversation

Common Mistakes

// WRONG: Store messages in database await supabase.from('messages').insert({ content: "Hello" });

// CORRECT: Store messages in Acontext await client.sessions.storeMessage(sessionId, { role: "user", content: "Hello" }, { format: "openai" });

// WRONG: Multiple sessions sharing one disk const sharedDisk = await client.disks.create(); // Don't share this disk across sessions!

// CORRECT: Each session has its own disk const session = await client.sessions.create({ user }); const disk = await client.disks.create(); // Exclusive to this session

Scripts

Copy these files to your project:

File Purpose

scripts/types.ts

Core type definitions

scripts/config.ts

Environment configuration

scripts/acontext-client.ts

SDK wrapper utilities

scripts/disk-tools.ts

Disk tool schemas and execution

scripts/sandbox-tool.ts

Python sandbox execution

scripts/openai-client.ts

OpenAI client with tool routing

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Automation

clinic-visit-prep

帮助患者整理就诊前问题、既往记录、检查清单与时间线,不提供诊断。;use for healthcare, intake, prep workflows;do not use for 给诊断结论, 替代医生意见.

Archived SourceRecently Updated
Automation

changelog-curator

从变更记录、提交摘要或发布说明中整理对外 changelog,并区分用户价值与内部改动。;use for changelog, release-notes, docs workflows;do not use for 捏造未发布功能, 替代正式合规审批.

Archived SourceRecently Updated
Automation

klaviyo

Klaviyo API integration with managed OAuth. Access profiles, lists, segments, campaigns, flows, events, metrics, templates, catalogs, and webhooks. Use this skill when users want to manage email marketing, customer data, or integrate with Klaviyo workflows. For other third party apps, use the api-gateway skill (https://clawhub.ai/byungkyu/api-gateway).

Archived SourceRecently Updated
Automation

lifelog

生活记录自动化系统。自动识别消息中的日期(今天/昨天/前天/具体日期),使用 SubAgent 智能判断,记录到 Notion 对应日期,支持补录标记。 适用于:(1) 用户分享日常生活点滴时自动记录;(2) 定时自动汇总分析并填充情绪、事件、位置、人员字段

Archived SourceRecently Updated