Phase03/.claude/skills/conversation-state/SKILL.md
Stateless conversation management with database-backed history, message persistence, and scalable architecture. Use when handling chat state, loading history, or building stateless APIs.
npx skillsauth add jawad-chaudhary/hackathone-2-todo-spec-driven-development conversation-stateInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
async def load_conversation_history(
session: AsyncSession,
user_id: str,
conversation_id: int | None
) -> tuple[Conversation, list[dict]]:
"""Load or create conversation with message history."""
if conversation_id:
stmt = select(Conversation).where(
Conversation.id == conversation_id,
Conversation.user_id == user_id
)
result = await session.execute(stmt)
conversation = result.scalar_one_or_none()
if not conversation:
raise HTTPException(status_code=404, detail="Conversation not found")
else:
conversation = Conversation(user_id=user_id)
session.add(conversation)
await session.commit()
await session.refresh(conversation)
# Load messages
stmt = select(Message).where(
Message.conversation_id == conversation.id
).order_by(Message.created_at)
result = await session.execute(stmt)
db_messages = result.scalars().all()
messages = [{"role": msg.role, "content": msg.content} for msg in db_messages]
return conversation, messages
@app.post("/api/{user_id}/chat")
async def chat(
user_id: str,
request: ChatRequest,
session: AsyncSession = Depends(get_db_session),
current_user: str = Depends(verify_jwt)
):
# 1. Load history from DB
conversation, messages = await load_conversation_history(
session, user_id, request.conversation_id
)
# 2. Save user message
user_msg = Message(
user_id=user_id,
conversation_id=conversation.id,
role="user",
content=request.message
)
session.add(user_msg)
await session.commit()
# 3. Add to history array
messages.append({"role": "user", "content": request.message})
# 4. Run agent
response, tool_calls = await run_agent(messages)
# 5. Save assistant response
assistant_msg = Message(
user_id=user_id,
conversation_id=conversation.id,
role="assistant",
content=response
)
session.add(assistant_msg)
await session.commit()
# 6. Return (server holds NO state)
return ChatResponse(
conversation_id=conversation.id,
response=response,
tool_calls=tool_calls
)
development
Async testing with pytest, pytest-asyncio, httpx, fixtures, coverage reports, and test-first development. Use when writing tests, test fixtures, or measuring coverage.
tools
Build AI agents with OpenAI Agents SDK, tool registration, conversation history, and stateless execution. Use when creating AI agents, registering tools, or handling conversations.
development
Integrate OpenAI ChatKit in Next.js 15 App Router with domain allowlist, authentication, and API connections. Use when building chat interfaces or ChatKit integration.
tools
Create MCP server tools with Official Python MCP SDK for AI agents. Use when building MCP tools, registering tool schemas, or creating AI-accessible functions.