> ## Documentation Index
> Fetch the complete documentation index at: https://docs.inworld.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Vibe Code

> Learn how to vibe code with Inworld Agent Runtime

## Vibe Coding Principles

Focused, concise and context-rich prompts are the key to effective vibe coding.

1. **Provide Essential Context** - Share product requirements, user journey, and constraints upfront

2. **Decompose Into Small Tasks** - Break your project into isolated, single-purpose tasks. Solve only one task per session

3. **Restart Sessions Often** - Start new chats for new features or when stuck. Use `/compact` (Claude Code) or `/compress` (Gemini CLI) to summarize before restarting

## Quick Setup

**Requirements**:

* Node.js v20 or higher: [Download here](https://nodejs.org/en/download)
* Your Inworld API key: [Sign up here](https://platform.inworld.ai/signup) or see [quickstart guide](/node/authentication#getting-an-api-key)

**Project Setup**:

1. **Clone the templates repository**
   ```bash theme={"system"}
   git clone https://github.com/inworld-ai/inworld-runtime-templates-node
   cd inworld-runtime-templates-node
   ```
2. **Open** your project in your development environment:
   * **AI IDEs**: Cursor, Windsurf, etc.
   * **IDEs with coding agents**: Visual Studio Code (with Zencoder, GitHub Copilot), JetBrains (with AI Assistant), etc.
   * **CLI tools**: Claude Code, Gemini CLI, etc.
3. **Create** a copy of the `.env-sample`, rename it to `.env`, and add your base64 API key
4. **Install** dependencies - In the root folder of your project, run this terminal command:

```bash theme={"system"}
yarn install
```

5. **Run** a simple example - Test your setup with this basic LLM example:

```bash theme={"system"}
cd templates/ts/cli
yarn basic-llm "Tell me a short joke"
```

6. **View** traces and logs - Visit the [Inworld Portal](https://platform.inworld.ai/) to monitor your graph executions, observe latency, and debug issues. Learn more about [logs](/portal/logs) and [traces](/portal/traces).

***

## Vibe Code with Inworld Agent Runtime

Follow these 4 steps for each new feature: Start fresh → Find template → Build incrementally → Troubleshoot as needed.

### Step 1: Set Context

Enter this prompt to ask the AI to familiarize itself with the codebase.

<Expandable title="Vibe Coding System Prompt">
  ```
  You are an agent to help build applications with Inworld Agent Runtime, an SDK for creating AI workflows using connected graphs of processing nodes.

  Before coding, examine the existing templates and examples in this codebase to understand implementation patterns, common node configurations, and data flow structures.

  Below is a summary of the Inworld Agent Runtime:

  **Graphs** assemble nodes, edges, and components into complete workflows. Think of them as executable processing pipelines.

  **Nodes** perform specific tasks within the graph:
  - **Built-in Nodes**: Ready-to-use AI nodes (LLM chat, TTS, STT, text manipulation, intent detection, knowledge retrieval)
  - **Custom Nodes**: Your own processing logic for specialized tasks

  **Components** Define a service configuration (like an LLM or TTS model) once and add it to the graph. 
  Multiple nodes can then reference this component by its ID, promoting DRY principles.

  **Edges** connect nodes and control data flow. Support parallel processing, conditional routing, and streaming.

  **Subgraphs** encapsulate a complex, multi-node workflow into a reusable subgraph. 
  Build it once, then add it to your main graph and use it as a single node.

  ## Data Flow Patterns
  **Fan-Out Pattern:** `A -> B` and `A -> C`. Achieved by adding two edges originating from the same source node `A`.
  **Fan-In Pattern:** `A -> C` and `B -> C`. Achieved by adding two edges that point to the same destination node `C`. The graph will wait for all inputs to be ready before executing node `C`.

  ## Graph Visualization
  Always represent structural changes with ASCII diagrams to ensure clarity:

  **When to show diagrams:**
  - Adding/removing nodes or edges
  - Changing data flow patterns
  - Introducing conditional routing

  **Format:**
  CURRENT:
  [Input] → [LLM Chat] → [Output]

  PROPOSED: 
  [Input] → [Intent Detection] → [LLM Chat] → [TTS] → [Output]
            +new node                        +new node

  ## Conditional Routing: Control graph flow based on data
  - **Simple Conditions:** Basic comparisons using expressions
  - **Custom Conditions:** Create a custom function as the condition 

  ## Best Practices
  - **Multi-node over single-node**: Build multi-node graphs for better UX instead of single-node solutions
  - **Reuse components**: Create components once, reference by ID across multiple nodes
  - **Use built-in nodes first**: Prefer built-in nodes before creating custom logic
  - **Check data type compatibility**: Ensure node outputs match the expected input types of downstream nodes
  ```
</Expandable>

***

### Step 2: Choose Template

Finding the best template to start from.

```
I want to build [describe your app and what it does].

User journey: [what users input → what they get back]

Please:
1. Find the closest template in this codebase
2. Outline the changes needed to make it into my app
3. Create a simple implementation plan

Keep the solution as simple as possible while meeting the user journey needs.
```

***

### Step 3: Build Incrementally

Start implementation with the recommended template.

```
Build the app incrementally using the recommended template.
- Begin with the identified template
- Implement one node modification per iteration
- Test and demonstrate each change before proceeding
- Request approval before adding complex features or custom nodes
```

***

### Step 4: Troubleshooting

When your AI agent gets stuck, try these troubleshooting options:

1. **Search templates for patterns:**

```
I'm stuck on [specific issue - e.g., "connecting TTS node to LLM output"]. 

Search the templates folder for:
- Similar node configurations or patterns
- Examples that handle [your specific data type/flow]
- Working implementations I can adapt

Show me the relevant code snippets and explain how to adapt them to my case.
```

2. **Revert to last checkpoint:** Use "Restore Checkpoint" in supported tools, or git reset/manual backups in others

3. **Restart the session:** Summarize progress first, then start fresh

```
Summarize: 
- What we've built so far (features, templates used, key configurations)
- Current blockers or challenges preventing progress
- Next immediate task to tackle
```

4. **Document successful solutions:** Save useful patterns as reusable rules. In Cursor, you can [create rules](https://docs.cursor.com/en/context/rules#generating-rules) by prompting the agent:

```
/Generate Cursor Rules

Document the fix we just implemented in this format:

**Problem:** [Describe the exact error or issue that was blocking progress]
**Solution:** [Explain the specific approach, pattern, or code change that resolved it]
**Context:** [Define when this rule applies - specific scenarios, node types, or conditions]
**Example:** [Include the actual code snippet or configuration that worked]
```
