Overview
As discussed in the introduction, developing AI applications is a pragmatic approach requiring to start simple and iterate towards complexity. Following this approach, this first version of our Code Assistant will be able to explain a given code file:- Agents: Agents act as a wrapper around the LLM (ex: Anthropic), providing a structured way to interact with it.
Setup
Follow the below steps to setup your project:1. Initialize your project
1. Initialize your project
2. Install the required dependencies
2. Install the required dependencies
3. Add TypeScript support
3. Add TypeScript support
4. Download the example code file
4. Download the example code file
Implementing our Code Assistant v1
Our first version of our Code Assistant takes the shape of a RAG workflow. A RAG workflow is a specific type of AI workflow that generally consist of two steps: retrieval (fetching relevant information) and generation (creating a response with a LLM). Our Code Assistant will have following two steps:- A retrieval step reads the content of a local file specified by the user.
- A generation step uses Anthropic to analyze the code and provide a detailed explanation of what it does.
The retrieval step: loading the code file
We earlier downloaded theexample.ts
file locally, let’s load it in our code by creating a index.ts
file:
The generation step using AgentKit’s Agent
As covered in the introduction, AgentKit’screateAgent()
is a wrapper around the LLM, providing a structured way to interact with it with 3 main properties:
name
: A unique identifier for the agent.system
: A description of the agent’s purpose.model
: The LLM to use.
claude-3-5-sonnet-latest
model by updating our index.ts
file:
main()
function to use our codeAssistant
Agent in the generation step:
- We load the
example.ts
file in memory. - We invoke our Code Assistant using the
codeAssistant.run()
method. - We retrieve the last message from the
output
array. - We log the content of the last message to the console.
Running our Code Assistant v1
First, go to your Anthropic dashboard and create a new API key. Then, run the following command to execute our Code Assistant:What we’ve learned so far
Let’s recap what we’ve learned so far:- A RAG workflow is a specific type of AI workflow that generally consist of two steps: retrieval (fetching relevant information) and generation (creating a response with a LLM).
- Note that most RAG workflows in production consist of more than two steps and combine multiple sources of information and generation steps. You can see an example in this blog post.
- AgentKit’s
createAgent()
is a wrapper around the LLM, providing a structured way to interact with a LLM model.- The use of a single Agent is often sufficient to power chatbots or extract structured data from a given text.
Next steps
Our Code Assistant v1 is a static AI workflow that only works with theexample.ts
file.
In the next version of our Code Assistant, we will make it dynamic by allowing the user to specify the file to analyze and also enable our Agent to perform more complete analysis.
Code Assistant v2: Complex code analysis
Our next Code Assistant version will rely on Agentic workflows to perform more
complex code analysis.