process_user_input
Processes user choices to generate personalized narrative responses and story paths in interactive reincarnation storytelling.
Instructions
Process user input and generate narrative response with options
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| user_id | Yes | ||
| user_input | Yes |
Implementation Reference
- main.py:295-338 (handler)The handler function decorated with @mcp.tool() that implements the core logic for processing user input during story progression. It generates narrative prompts and option prompts based on the current story state.@mcp.tool() def process_user_input(user_id: str, user_input: str) -> str: """Process user input and generate narrative response with options""" state = get_user_state(user_id) if not state["story_started"]: return "Please start the story first by typing 'Arise'." if not state["current_path"]: return "Please choose a reincarnation path first." # Generate narrative based on user input narrative_prompt = str(generate_narrative_prompt( user_input=user_input, path=state["current_path"], step=state["story_step"], previous_context=state["current_context"] )) # Update context for next iteration state["current_context"] = f"Step {state['story_step']}: {user_input[:100]}..." state["story_step"] += 1 state["choices_made"].append(user_input) # Generate options for next step options_prompt = str(generate_options_prompt( current_narrative=f"User's action: {user_input}. Context: {state['current_context']}", path=state["current_path"], step=state["story_step"], previous_choices=state["choices_made"][-3:] # Last 3 choices )) return f""" NARRATIVE GENERATION PROMPT: {narrative_prompt} After the narrative is generated, use this prompt to create three options: OPTIONS GENERATION PROMPT: {options_prompt} The AI will now generate the next part of your story based on your input: "{user_input}" """