










@@ -404,38 +404,186 @@ See [Get group/user IDs](#get-groupuser-ids) for lookup tips.
404404405405---
406406407+## Per-user agent isolation (Dynamic Agent Creation)
408+409+Enable `dynamicAgentCreation` to automatically create **isolated agent instances** for each DM user. Each user gets their own:
410+411+- Independent workspace directory
412+- Separate `USER.md` / `SOUL.md` / `MEMORY.md`
413+- Private conversation history
414+- Isolated skills and state
415+416+This is essential for public bots where you want each user to have their own private AI assistant experience.
417+418+<Note>
419+**Account limitation**: `dynamicAgentCreation` currently works with the **default Feishu account only**. Named/multi-account setups are not yet fully supported — dynamic bindings are created without `accountId`, so messages to named accounts may still route to `agent:main`. Track progress in [Issue #42837](https://github.com/openclaw/openclaw/issues/42837).
420+</Note>
421+422+### Quick setup
423+424+```json5
425+{
426+ channels: {
427+ feishu: {
428+ dmPolicy: "open",
429+ allowFrom: ["*"],
430+ dynamicAgentCreation: {
431+ enabled: true,
432+ workspaceTemplate: "~/.openclaw/workspace-{agentId}",
433+ agentDirTemplate: "~/.openclaw/agents/{agentId}/agent",
434+ },
435+ },
436+ },
437+ session: {
438+// Critical: makes each user's DM their "main session"
439+// Automatically loads USER.md / SOUL.md / MEMORY.md
440+// For stronger isolation, use "per-channel-peer" instead
441+ dmScope: "main",
442+ },
443+}
444+```
445+446+### How it works
447+448+When a new user sends their first DM:
449+450+1. The channel generates a unique `agentId` = `feishu-{user_open_id}`
451+2. Creates a new workspace at `workspaceTemplate` path
452+3. Registers the agent and creates a binding for this user
453+4. The workspace helper ensures bootstrap files (`AGENTS.md`, `SOUL.md`, `USER.md`, etc.) on first access
454+5. Routes all future messages from this user to their dedicated agent
455+456+### Configuration options
457+458+| Setting | Description | Default |
459+| -------------------------------------------------------- | ------------------------------------------ | ------------------------------------ |
460+| `channels.feishu.dynamicAgentCreation.enabled` | Enable automatic per-user agent creation | `false` |
461+| `channels.feishu.dynamicAgentCreation.workspaceTemplate` | Path template for dynamic agent workspaces | `~/.openclaw/workspace-{agentId}` |
462+| `channels.feishu.dynamicAgentCreation.agentDirTemplate` | Agent directory name template | `~/.openclaw/agents/{agentId}/agent` |
463+| `channels.feishu.dynamicAgentCreation.maxAgents` | Maximum number of dynamic agents to create | unlimited |
464+465+Template variables:
466+467+- `{agentId}` - the generated agent ID (e.g., `feishu-ou_xxxxxx`)
468+- `{userId}` - the sender's Feishu open_id (e.g., `ou_xxxxxx`)
469+470+### Session scope
471+472+`session.dmScope` controls how direct messages are mapped to agent sessions. This is a **global setting** that affects all channels.
473+474+| Value | Behavior | Best for |
475+| -------------------- | --------------------------------------------------------- | ------------------------------------------------------------------ |
476+| `"main"` | Each user's DM maps to their agent's main session | Single-user bots where you want `USER.md` / `SOUL.md` to auto-load |
477+| `"per-channel-peer"` | Each (channel + user) combination gets a separate session | Public multi-user bots needing stronger isolation |
478+479+**Tradeoff**: Using `"main"` enables automatic bootstrap file loading (`USER.md`, `SOUL.md`, `MEMORY.md`), but means all DMs across all channels share the same session key pattern. For public multi-user bots where isolation matters more than bootstrap auto-loading, consider `"per-channel-peer"` and manage bootstrap files manually.
480+481+<Note>
482+`"per-account-channel-peer"` is not recommended with `dynamicAgentCreation` because dynamic bindings are created without `accountId`. Use it only with manual bindings.
483+</Note>
484+485+```json5
486+{
487+ session: {
488+// For single-user personal bots: enables auto bootstrap loading
489+ dmScope: "main",
490+491+// For public multi-user bots: stronger isolation
492+// dmScope: "per-channel-peer",
493+ },
494+}
495+```
496+497+### Typical multi-user deployment
498+499+```json5
500+{
501+ channels: {
502+ feishu: {
503+ appId: "cli_xxx",
504+ appSecret: "xxx",
505+ dmPolicy: "open",
506+ allowFrom: ["*"],
507+ groupPolicy: "open",
508+ requireMention: true,
509+ dynamicAgentCreation: {
510+ enabled: true,
511+ workspaceTemplate: "~/.openclaw/workspace-{agentId}",
512+ agentDirTemplate: "~/.openclaw/agents/{agentId}/agent",
513+ },
514+ },
515+ },
516+ session: {
517+// Choose dmScope based on your isolation needs:
518+// "main" for bootstrap auto-loading, "per-channel-peer" for stronger isolation
519+ dmScope: "main",
520+ },
521+ bindings: [], // Empty - dynamic agents auto-bind
522+}
523+```
524+525+### Verification
526+527+Check gateway logs to confirm dynamic creation is working:
528+529+```
530+feishu: creating dynamic agent "feishu-ou_xxxxxx" for user ou_xxxxxx
531+workspace: /Users/you/.openclaw/workspace-feishu-ou_xxxxxx
532+feishu: dynamic agent created, new route: agent:feishu-ou_xxxxxx:main
533+```
534+535+List all created workspaces:
536+537+```bash
538+ls -la ~/.openclaw/workspace-*
539+```
540+541+### Notes
542+543+- **Workspace isolation**: Each user gets their own workspace directory and agent instance. Users cannot see each other's conversation history or files within the normal messaging flow.
544+- **Security boundary**: This is a messaging-context isolation mechanism, not a hostile co-tenant security boundary. The agent process and host environment are shared.
545+- **`bindings` should be empty**: Dynamic agents auto-register their own bindings
546+- **Upgrade path**: Existing manual bindings continue to work alongside dynamic agents
547+- **`session.dmScope` is global**: This affects all channels, not just Feishu
548+549+---
550+407551## Configuration reference
408552409553Full configuration: [Gateway configuration](/gateway/configuration)
410554411-| Setting | Description | Default |
412-| ------------------------------------------------- | -------------------------------------------------------------------------------- | ---------------- |
413-| `channels.feishu.enabled` | Enable/disable the channel | `true` |
414-| `channels.feishu.domain` | API domain (`feishu` or `lark`) | `feishu` |
415-| `channels.feishu.connectionMode` | Event transport (`websocket` or `webhook`) | `websocket` |
416-| `channels.feishu.defaultAccount` | Default account for outbound routing | `default` |
417-| `channels.feishu.verificationToken` | Required for webhook mode | - |
418-| `channels.feishu.encryptKey` | Required for webhook mode | - |
419-| `channels.feishu.webhookPath` | Webhook route path | `/feishu/events` |
420-| `channels.feishu.webhookHost` | Webhook bind host | `127.0.0.1` |
421-| `channels.feishu.webhookPort` | Webhook bind port | `3000` |
422-| `channels.feishu.accounts.<id>.appId` | App ID | - |
423-| `channels.feishu.accounts.<id>.appSecret` | App Secret | - |
424-| `channels.feishu.accounts.<id>.domain` | Per-account domain override | `feishu` |
425-| `channels.feishu.accounts.<id>.tts` | Per-account TTS override | `messages.tts` |
426-| `channels.feishu.dmPolicy` | DM policy | `allowlist` |
427-| `channels.feishu.allowFrom` | DM allowlist (open_id list) | [BotOwnerId] |
428-| `channels.feishu.groupPolicy` | Group policy | `allowlist` |
429-| `channels.feishu.groupAllowFrom` | Group allowlist | - |
430-| `channels.feishu.requireMention` | Require @mention in groups | `true` |
431-| `channels.feishu.groups.<chat_id>.requireMention` | Per-group @mention override; explicit IDs also admit the group in allowlist mode | inherited |
432-| `channels.feishu.groups.<chat_id>.enabled` | Enable/disable a specific group | `true` |
433-| `channels.feishu.textChunkLimit` | Message chunk size | `2000` |
434-| `channels.feishu.mediaMaxMb` | Media size limit | `30` |
435-| `channels.feishu.streaming` | Streaming card output | `true` |
436-| `channels.feishu.blockStreaming` | Completed-block reply streaming | `false` |
437-| `channels.feishu.typingIndicator` | Send typing reactions | `true` |
438-| `channels.feishu.resolveSenderNames` | Resolve sender display names | `true` |
555+| Setting | Description | Default |
556+| -------------------------------------------------------- | -------------------------------------------------------------------------------- | ------------------------------------ |
557+| `channels.feishu.enabled` | Enable/disable the channel | `true` |
558+| `channels.feishu.domain` | API domain (`feishu` or `lark`) | `feishu` |
559+| `channels.feishu.connectionMode` | Event transport (`websocket` or `webhook`) | `websocket` |
560+| `channels.feishu.defaultAccount` | Default account for outbound routing | `default` |
561+| `channels.feishu.verificationToken` | Required for webhook mode | - |
562+| `channels.feishu.encryptKey` | Required for webhook mode | - |
563+| `channels.feishu.webhookPath` | Webhook route path | `/feishu/events` |
564+| `channels.feishu.webhookHost` | Webhook bind host | `127.0.0.1` |
565+| `channels.feishu.webhookPort` | Webhook bind port | `3000` |
566+| `channels.feishu.accounts.<id>.appId` | App ID | - |
567+| `channels.feishu.accounts.<id>.appSecret` | App Secret | - |
568+| `channels.feishu.accounts.<id>.domain` | Per-account domain override | `feishu` |
569+| `channels.feishu.accounts.<id>.tts` | Per-account TTS override | `messages.tts` |
570+| `channels.feishu.dmPolicy` | DM policy | `allowlist` |
571+| `channels.feishu.allowFrom` | DM allowlist (open_id list) | [BotOwnerId] |
572+| `channels.feishu.groupPolicy` | Group policy | `allowlist` |
573+| `channels.feishu.groupAllowFrom` | Group allowlist | - |
574+| `channels.feishu.requireMention` | Require @mention in groups | `true` |
575+| `channels.feishu.groups.<chat_id>.requireMention` | Per-group @mention override; explicit IDs also admit the group in allowlist mode | inherited |
576+| `channels.feishu.groups.<chat_id>.enabled` | Enable/disable a specific group | `true` |
577+| `channels.feishu.dynamicAgentCreation.enabled` | Enable automatic per-user agent creation | `false` |
578+| `channels.feishu.dynamicAgentCreation.workspaceTemplate` | Path template for dynamic agent workspaces | `~/.openclaw/workspace-{agentId}` |
579+| `channels.feishu.dynamicAgentCreation.agentDirTemplate` | Agent directory name template | `~/.openclaw/agents/{agentId}/agent` |
580+| `channels.feishu.dynamicAgentCreation.maxAgents` | Maximum number of dynamic agents to create | unlimited |
581+| `channels.feishu.textChunkLimit` | Message chunk size | `2000` |
582+| `channels.feishu.mediaMaxMb` | Media size limit | `30` |
583+| `channels.feishu.streaming` | Streaming card output | `true` |
584+| `channels.feishu.blockStreaming` | Completed-block reply streaming | `false` |
585+| `channels.feishu.typingIndicator` | Send typing reactions | `true` |
586+| `channels.feishu.resolveSenderNames` | Resolve sender display names | `true` |
439587440588---
441589此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。