## AI Coding 101 Note: - Introduction - Agenda --- ### AI Agent - Autonomy - Goal-Oriented - Perception - Decision-Making - Action Execution - Memory and Learning Note: - Autonomy: Ability to operate independently without constant human intervention. They can make decisions and take actions based on their understanding of the environment and goals. - Goal-Oriented: Designed to achieve specific objectives or tasks. They can break down complex problems into smaller, manageable steps. - Perception: Can interpret and understand information from their environment, often through various inputs like text, code, or sensor data. - Decision-making: They use algorithms, machine learning, or rule-based systems to analyze information and choose appropriate actions from available options. - Action Execution: Capable of performing actions in their environment, such as writing code, executing commands, or interacting with APIs. - Memory and Learning: A key differentiator is their ability to remember past interactions and learn from experience, allowing them to refine their strategies and improve performance over time. ---- ### Without AI Agent Refactor similar code 1. Identify similar code 2. Abstract based on commonalities, extract into a function 3. Write tests to cover the new function 4. Run tests to ensure refactoring is correct, until all tests pass ---- ### With AI Agent Refactor similar code 1. Tell AI "@/xxx/xxx has a lot of similar code, refactor them" 2. AI scans for similar code 3. AI abstracts based on similar code 4. AI adds tests 5. AI runs tests to ensure refactoring is correct, until all tests pass --- ### MCP ( Model Context Protocol ) - Standardized Interface: LLMs <-> External Tools or Services - Extensibility - Contextual Awareness - Examples: - GitHub MCP Server - Slack MCP Server - Filesystem MCP Server Note: - Standardized Interface: AI's HTTP - Extensibility: Allows AI models to interact with external systems, APIs, and data sources, enabling them to perform a wider range of tasks. - Contextual Awareness: Enables tools to provide relevant context back to the AI model, improving the model's understanding and decision-making. ---- ![image](https://hackmd.io/_uploads/By0IjOXSee.png) ---- ### Recommend MCP ### Context7 - Provides up-to-date documentation for many mainstream libraries, preventing LLMs from relying oudated on training data and thus reducing hallucinations. ---- #### Context7 Example ```shell > Is there any func can convert map keys to a slice in lo lib? use context7 ``` ![image](https://hackmd.io/_uploads/ByGVrCyrxl.png) --- ### How to Write Good Prompts - Be Clear and Specific ```shell Bad: Fix the code. Good: Fix the bug in the calculateTotal function that causes it to return incorrect results. ``` - Provide Context ```shell Good: @/interval/utils.go Refactor the calculateTotal function to use goroutine. ``` - Break Down Tasks - Give Examples - Iterate Note: Be Clear and Specific: Clearly state what you want Roo Code to do. Avoid ambiguity. Provide Context: Use Context Mentions to refer to specific files, folders, or problems. Break Down Tasks: Divide complex tasks into smaller, well-defined steps. Give Examples: If you have a specific coding style or pattern in mind, provide examples. Iterate: Don't be afraid to refine your prompt if the initial results aren't what you expect. --- ### Instruction - Pre-defined system-level guidelines - Tells AI its overall role, style, and limitations - Remains effective throughout all conversations ---- #### Instruction Example - Gemini CLI -> GEMINI.md - Claude Code -> CLAUDE.md - Cursor -> .cursor/rules ```markdown You are a professional Go programmer assistant - Always provide clear code comments - Prioritize code readability and performance - Confirm understanding of requirements before answering ``` --- ### Privacy - Asking for permissions - Cursor Privacy Mode - Ignore file (`.cursorignore`, `.rooignore`) - Default ignore `.gitignore` - Choose Model carefully - Free Model - Model Policy - Local LLM (Ollama) --- ### Use Cases - Write unit tests - Write documents - Explain code base - Refactroing - Routine work - Creating GitHub PR, send it to slack channel and tag someone (Github, Slack MCP) ---- ### PR Creator ```md # Personal commands ## PR Creator: when message format is "/pr [$TITLE] [$MENTION] [$CHANNEL]", create a GitHub pull request, and send a Slack message, following these requirements: 1. Branch is current branch 2. Remote branch is master 3. Push Repository: attempt to push to the remote repository if not already pushed 4. All content in English 5. Creating a PR - {PR details} 6. Sending a Slack message - {message content} ``` <!-- .slide: style="font-size: 28px;" --> --- ![image](https://hackmd.io/_uploads/SyNHHibBeg.png) https://roocode.com/ - VS Code Plugin - Open-Source and Model-Agnostic - Multiple specialized modes - Fully customizable ---- #### Modes ![image](https://hackmd.io/_uploads/SJbJ2CJHeg.png) ---- #### Providers ![image](https://hackmd.io/_uploads/rkc4yyxrgg.png) ---- #### Examples ![image](https://hackmd.io/_uploads/H1dTQJgrle.png) ---- #### Examples ![image](https://hackmd.io/_uploads/Skl4QJxBex.png) --- ### Tips - Notifications (bell sound) - English saves more tokens than Chinese - You might not need an AI Agent - Search and replace - Jetbrains refactoring features - Security concerns - Writing prompts is harder than developing yourself Note: 2. LLMs are trained in English, and Chinese consumes more tokens due to word segmentation. If you have token usage requirements, consider using English. --- ### Don't Panic - Tools are largely similar - Update speed is very fast --- The End
{"title":"AI Coding 101","description":"Note:","slideOptions":"{\"theme\":\"dracula\"}","contributors":"[{\"id\":\"c5781c81-b53d-4a93-aa3b-a9c491009e81\",\"add\":8634,\"del\":2788,\"latestUpdatedAt\":1760799578612}]"}
    334 views