ai
basic
Harness Engineering
spec-driven
- spec.md(specification) => plan.md => tasks.md
skill
- modular, file-based design pattern
- decoupling the instructions and tools from the core agent.
- a portable, self-contained directory containing a structured markdown file of instructions, alongside any necessary helper scripts or API triggers.
- allow lazy loading though skill descriptions
Function/tool Calling
- functions’ (blocks of reusable code) are the ‘tools’ agents use to carry out tasks.
Few-Shot && cot
- functions’ (blocks of reusable code) are the ‘tools’ agents use to carry out tasks.
Chain-of-Thoughts
- to think step by step
Tree of Thoughts
ReAct, reasoning action
thought: make plans
take actions
observation, observ the result that action returned
Short/long Term Memory
how llm generates answers?
- tokenizer, stands between user and llm to decode and encode tokens
- Tokenization: split user’s inputs into words called tokens
- one word can be a token, but it’s not always the case.
- helpful => help and ful. 程序员 => 程序 员
- Embedding, assign Each token to a unique list of numbers (a vector)
- Tokenization: split user’s inputs into words called tokens
- Contextualization
- Ambiguity (Polysemy), In human language, many words have multiple meanings.
- this step helps to realize exactly who “he,” “she,” or “it” refers to in a long paragraph.
- Calculating Probabilities
- assigns a probability score to every single token that could come next.
- Select from a list of probabilities
- How it picks determines how creative or factual the answer feels. controlled by settings like temperature, top_p, top_k, etc.
- Temperature, a low temperature means the top-scoring token
- Top-P / Top-K Sampling, only consider the top few most likely tokens to prevent nonsensical answers
- the loop
- predicts the first token of the answer => get the first token,adds it to your original prompt => get the second token => …
- Hallucinations
- LLMs are trained to predict the next word in a sequence based on probability, which can lead to “hallucinations”—convincing but false statements
- Lack of Real-World Knowledge
- Standard training often penalizes the model for being silent but rewards it for being fluent.
- tokenizer, stands between user and llm to decode and encode tokens
token
prompt types
- user prompt. input from user.
- system prompt. set by system.
what’s agent
- system
- Environment
- Sensors
- Actuators
- llm
- Perform Actions
- access to tools
- memory + knowledge
- system
Agent Type
Simple Reflex Agents, Follows hard-coded rules — no memory, no planningModel-Based Reflex Agents, Keeps an internal model of the world and updates it as things change- like tracks a stock’s price, and change then price when good or bads news happening
Goal-Based Agents, have a goal in mind and figures out how to reach it step by stepUtility-Based Agents, Doesn’t just find a solution — finds the best one by weighing tradeoffs.- `Learning Agents’, Gets better over time by learning from feedback.
- `Hierarchical Agents’, A high-level agent breaks work into subtasks and delegates to lower-level agents.
Multi-Agent Systems (MAS), Multiple independent agents working together (or competing).- Large workloads / Complex tasks can be divided into smaller tasks and assigned to different agents, allowing for parallel processing and faster completion
stituations
- Open-Ended Problems, need the LLM to figure out the path dynamically
- Multi-Step Processes, Tasks that require using tools across several turns, not just a single lookup or generation
- Improvement Over Time, like Learning Agents
design patterns
- msa, https://github.com/microsoft/ai-agents-for-beginners/tree/main/08-multi-agent
- Agent Communication. which agents are sharing info and how they are sharing info.
- how the agents are coordinating their actions to meet user’s preferences and constraints
- how the agents are making decisions and learning from their interactions with the user
- how to track agent activities and interactions. coulde be the form of logging and monitoring tools, visualization tools, and performance metrics
- Human in the loop. when to ask for human intervention
- msa, https://github.com/microsoft/ai-agents-for-beginners/tree/main/08-multi-agent
MCP-ModelContextProtocol
allows AI models to access and utilize external resources—such as databases, APIs, and local files—without the need for custom integrations for each data source.
it’s particularly beneficial in scenarios where AI models need to interact with multiple data sources or tools.
concepts
MCP host, an application that integrates ai modules, like cursorMCP client, It functions as a plugin within the host, providing a bridge between the host and the serverMCP server, an external server that offers dataToolsallow modules take actions through your serverResourcesprovide data to modules, not yet supported in Cursor- static resources are equal to upload file, but the file can be dynamic
Promptscreate a message template, or a message workflow
claude desktop failed to run mcp servers, but these servers are work great with cursor
- MCP Servers Don’t Work with NVM
- call
nodewith an absolute path - avoid use
npx. install packages globally, and then run them usingnodefrom their path
the official documents and some articles may not follow the updating of Sdk
debugger
npx @modelcontextprotocol/inspector- with claude: Open DevTools: Command-Option-Shift-i
The tokenization process splits text into smaller units called tokens, usually using a sub-word tokenization technique like Byte Pair Encoding (BPE) or WordPiece. but non-Latin text will be treated differently. Except the obvious characters, additional splits and encoding for sub-word components, punctuation, or any special tokens may exits and various according to the tokenization strategy
browsertools
useful for inspecting dom and adjusting style
Q: get the selected element. it’s child element has a padding thus is used to make a gap between two elements. the gap is need when the two elements are aligned.
get network logs and console logs
Q: getnetwork. log the requests with
pageSize:20set- this feature is not work as expected, it’s tend to miss logs. the repo are still many unresolved issues related to log retrieval
- sometimes, wiping logs or closing other F12 panels can help
RAG-RetrievalAugmentedGeneration
- why?
- Reducing Hallucinations
- RAG forces the model to look up a specific piece of evidence before answering.
- it can provide source links or citations, making the response auditable and trustworthy
- allowing the model to retrieve relevant information from an external knowledge base
- Reducing Hallucinations
- workflow: When a query (input) is received:
- Before-retrieval
- Routing
- rewriting
- expansion
- Retrieval
- After-retrieval
- Rerank, rerank the retrieved documents to improve the quality of the results
- summary
- fusion
- After-retrieval
- Before-retrieval
- embedding types
- Text Embeddings
- Multimodal Embeddings
Use LangChain and Ollama to go through the RAG workflow
https://js.langchain.com/docs/tutorials/rag
Indexing, a pipeline for ingesting data
- load, load document via document_loaders
- split, split doc into chunks via text splitters that support four strategies. long documents will be hard to fit into the context window of many models and can be struggle for modules to find information in very long inputs
- length
- text-structure, based on paragraphs, sentences, and words
- document-structure, based on an inherent structure, e.g. HTML, Markdown, or JSON
- semantic-meaning
- embed, Wrapper around a text embedding model for converting text to embeddings
- store, store splits into a VectorStore, allowed to add text and Document objects to the store, and query them using various similarity metrics.
- Can be in-memory or via third party
- allow to connect to an existing vector store
similaritySearch,similaritySearchWithScore
asRetriever, generate a Retriever, specifically aVectorStoreRetriever- Retrievers are Runnables, implement a standard set of methods (invoke and batch operations)
- similaritySearch vs Retriever
Retrieval, takes a user query at run time and retrieves the relevant data from the store via retrievers
- Query analysis
- can Re-write or expand to improve semantic or lexical searches
- can translate natural language queries into specialized query languages or filters, like sql, cypher
- Query analysis
generation, passes the relevant data and question to the model
- allow to load prompt template from prompt hub
task-master
- upon on Claude ai(required), Perplexity AI(optional)
- despite Claude ai, it still can manage tasks manually—creating, editing, and tracking them in tasks.json or via the Task Master CLI/MCP tools.
- Perplexity AI
- a search engine powered by models like Claude, GPT, and its own fine-tuning
- fact-based, best for research (cited answers)
- Always up-to-date
- Less conversational
- Claude
- more safety and polite.
- unlike open ai which relying on human feedback to fix bad behavior, Anthropic uses
Constitutional AIthat includes a set of human principles. - sometimes too verbose or cautions
- unlike open ai which relying on human feedback to fix bad behavior, Anthropic uses
- best for long document analysis, can handle over 100k tokens and optimized for huge inputs
- more safety and polite.
- Perplexity AI
- Init
- use
parse_prdto analyzePRDdocument, and create tasks - a foundational task structure will be created, and used for later tracing
- use
- update
- analyze what changed in the PRD and update / add / cancel tasks
- changes on code need manually implementations
- tips for better maintenance
- use
analyze-complexity, based uponPerplexity AI- to get to know task complexity level
- it’s better to break down complex tasks with
expand
- Periodically
validateandfixinvalid or circular dependencies.
- use