Build a DeepSeek Agent in Pure Python
Key Takeaways
This video teaches building a DeepSeek AI agent using pure Python for flexible and extensible applications
Full Transcript
in this video I'm going to show you how to create a deep seek agent the agent is going to be an allpurpose agent created in pure python so no Lang chain no llama index just Python and deep seek hosted on gr Cloud now let me show you what this deep seek agent powered by groc clock can do here I have a pandas data frame with some sales data and I can take that data frame pass it to the agent and the agent will analyze the data and return a result within a couple of seconds I can also take the same data frame and ask the agent to predict sales using temperature and a weakened flag as a feature and the agent will return a trained machine learning model again within a couple of seconds and note that these are just two examples we can extend this in Endless Ways by passing different objects to the agent to build this agent the only thing we need to do is to connect to gr Cloud there a python library that makes it very easy to get started with the API and connect to any of the open source llms including deep seek now in order to build our python agent the first thing you need to understand is the type of respond you're going to be getting from Deep seek so the first thing I'm going to do is in the gro Cloud playground I'm going to ask deep seek to write a small python script and what you'll see is that the response you're getting from Deep seek includes a reasoning section that's encapsulated in think brackets and then we get the actual python code that's encapsulated in Python code fenses and when we build our agent we want to extract this code from the response from the code fences now let's get started building the agent we only need to pip install Grog and python. to build and use the actual agent but we're going to need pandas number Andy it learn for the examples I have my environment variables in a EnV file with the gro API key I'll import CIS and string IO for capturing python output Gro for accessing the gro API OS and EnV for handling environment variables and then re for processing regular expressions and then I'm going to load the environment variables using load. EnV the first thing we're going to need the agent is the ability to generate some python code from a query or question and a context that could be data or an object we'll create a function for that and within this function we'll instantiate the gro client using the API key located in the EnV file then we'll Define a system prompt telling the llm to generate python code that uses only provided variables prints results and includes any needed Imports and this will go into the chat completions endpoint alongside with the data context and the main question from the user finally we set the model equal to deeps R1 and then we have the function return a clean code response and here clean code response is a function that passes the output from the llm and we'll need to formulate that function next the clean code response output pass is pretty simple we take the output from Deep seek we remove the thinking sections and then we extract the code from the python code fences using regular expressions and now we can call the CR Cloud API and get a clean code response and this code can be executed the next function we need for our agent is the execute python function that executes the code generated by Deep seek the execute python function will take the generated code AS input and then execute that code in the context and we use the build-in EXA function to do that where we pass the code in a namespace here called local vars which is either equal to the context or an in dictionary finally we use system standard out to capture the output of the exact function now we can execute the past python code the last thing we need to do is to assemble the agent the agent is going to take as input a question or query some data which is the main context and a string variable called Data context which is a description of the data then we're going to take the question and the data context and generate a clean code solution using generate code after that we'll take the clean code solution along with the data pass it to execute Python and execute and then get the results and this allows us to get both the code solution and the result back from the agent now let's try to use this agent for two different tasks but with the same data one is to analyze a data frame and the other one is to train a machine learning model and make some predictions so first we're going to need some data for this I'm going to simulate a data frame with sales data the data frame contains date category store ID sales temperature and a weeken flag analyzing this pandas data frame is very simple we simply pass the data frame to the agent along with a context which is a description of the data frame and a question and we're going to ask the agent to analyze the sales patterns so calculate the total sales per category and show if weekends have higher average sales now running the agent with this data and this question only takes a couple of seconds and you see that you get a result back so this is not a problem for deep seek same thing for the machine learning example we're going to use the same data frame and we're going to ask the agent to train a model to predict sales using temperature and the weekend flag as features and then show feature importance and again as you see this is no problem for the Deep seek agent we get the requested analysis back so this agent was built with deep seek on gr Cloud you can modify this to use anym and by changing out the context that you're passing to the agent you take this in any other direction all right that's it for now thanks for watching
Original Description
In this video, we will build a DeepSeek AI agent using pure Python. The solution is flexible and can easily be extended to various applications.
The notebook with the code is available here:
https://www.rabbitmetrics.com/lets-build-a-deepseek-agent-in-pure-python/
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Related Reads
📰
📰
📰
📰
Optimizing Operational Efficiency in Russia: A Pragmatic Approach to Automation and AI
Dev.to AI
How AI agents are replacing $10k/month jobs — and how you can profit from it
Dev.to AI
Unlocking Automation: Boost Efficiency with Browser Agents
Dev.to AI
Control before, proof after: an accountability primitive for AI agents
Dev.to · Greg
🎓
Tutor Explanation
DeepCamp AI