Sub-Config Organization Policies and KakaoTalk Chatbot Integration
Using Claude Control as a team required organization-level configuration. This post documents building a sub-config system to manage session permissions, available tools, and prompt policies at the org level, along with integrating KakaoTalk as an external access point.
Organization Policy Configuration
from pydantic import BaseModel
from typing import List, Dict, Optional
class MemberPolicy(BaseModel):
max_sessions: int = 3
allowed_tools: List[str] = ["*"]
blocked_tools: List[str] = []
max_tokens_per_day: int = 100000
autonomous_mode: bool = False
class OrgConfig(BaseModel):
org_id: str
org_name: str
default_policy: MemberPolicy = MemberPolicy()
member_policies: Dict[str, MemberPolicy] = {}
shared_prompts: List[str] = []
mcp_servers: List[str] = []
def get_policy(self, member_id: str) -> MemberPolicy:
return self.member_policies.get(member_id, self.default_policy)
Policy Enforcement Middleware
from fastapi import Request, HTTPException
class PolicyMiddleware:
def __init__(self, org_config: OrgConfig):
self.config = org_config
async def check_permission(self, member_id: str, action: str):
policy = self.config.get_policy(member_id)
if action == "create_session":
active = await self._count_active_sessions(member_id)
if active >= policy.max_sessions:
raise HTTPException(
status_code=429,
detail=f"세션 제한 초과: {active}/{policy.max_sessions}",
)
if action == "use_tool":
# 도구 사용 권한 체크
pass
if action == "autonomous_mode" and not policy.autonomous_mode:
raise HTTPException(
status_code=403,
detail="자율 실행 모드 권한이 없습니다",
)
KakaoTalk Chatbot Integration
The KakaoTalk chatbot provides external access to Claude Control. This required implementing a Skill API compatible with Kakao i OpenBuilder.
@app.post("/kakao/skill")
async def kakao_skill(request: Request):
body = await request.json()
user_id = body["userRequest"]["user"]["id"]
utterance = body["userRequest"]["utterance"]
# 사용자의 세션 찾기 또는 생성
session_id = await get_or_create_user_session(user_id)
# Claude에 프롬프트 전달
result = await session_manager.send_prompt(session_id, utterance)
# 카카오톡 응답 형식으로 변환
return {
"version": "2.0",
"template": {
"outputs": [
{
"simpleText": {
"text": result[:1000] # 카카오톡 글자 제한
}
}
]
}
}
KakaoTalk Response Optimization
KakaoTalk's 5-second response timeout and 1,000-character limit required dedicated optimizations.
async def process_with_timeout(session_id: str, prompt: str):
try:
result = await asyncio.wait_for(
session_manager.send_prompt(session_id, prompt),
timeout=4.5, # 카카오톡 5초 제한보다 여유
)
if len(result) > 1000:
result = result[:950] + "\n\n(결과가 길어 일부만 표시합니다)"
return result
except asyncio.TimeoutError:
return "처리 시간이 초과되었습니다. 잠시 후 다시 시도해주세요."
Retrospective
Adding organization policies and external integrations transformed Claude Control from a personal tool into a team tool. The KakaoTalk integration gave non-technical team members a way to interact with the AI agent without needing direct access to the underlying system.