Lesson Introduction

Welcome! In this lesson, we’ll enhance our Todo API agent to support all CRUD operations: Create, Read, Update, and Delete. These are the core actions behind any data-driven app, from simple to-do lists to complex systems. By the end, you’ll know how to implement and orchestrate these operations in a Python agent that communicates with a RESTful API.

Think of building a digital assistant for daily tasks. To be useful, it must add, show, update, and remove tasks. CRUD operations make this possible. Our goal is to make our Todo agent handle all these actions smoothly.

Note: In this lesson, we focus on implementing the client side of the Todo API agent — that is, the code that sends requests to an API to perform CRUD operations. The lesson does not cover the implementation of the API server that receives and responds to these requests.

Overview of CRUD Operations and Data Modeling

CRUD stands for Create, Read, Update, and Delete — the four basic ways to manage data.

  • Create: Add a new item (e.g., a new task).
  • Read: Retrieve items (e.g., list all tasks).
  • Update: Change an item (e.g., mark a task as done).
  • Delete: Remove an item (e.g., delete a finished task).

In web apps, these map to HTTP methods:

  • POST for Create
  • GET for Read
  • PUT for Update
  • DELETE for Delete

For example, adding a new task in a to-do app sends a POST request. Viewing tasks uses GET. Editing uses PUT, and deleting uses DELETE.

To manage tasks, we use data models. Our agent uses Pydantic models to define a task and the required arguments.

Here’s the task model:

Implementing CRUD in the TodoAPI Class: Read and Create

The TodoAPI class handles API communication. Each CRUD operation is a class method.

Read (GET):

The get_tasks method is the same as in the previous lesson—a quick revision:

  • Sends GET to fetch all tasks.
  • Converts the response to TodoItem objects.

Create (POST):

  • Sends POST with new task data.
  • Returns the created task.
Implementing CRUD in the TodoAPI Class: Update and Delete

Update (PUT):

  • Sends PUT to update a task by ID.

Delete (DELETE):

  • Sends DELETE to remove a task by ID.

Dispatching Actions:

The handle_request method selects the appropriate CRUD method:

Integrating CRUD with the Agent

Now, let’s connect these CRUD operations to our agent so it can process natural language commands.

We wrap the API logic in a FunctionTool:

  • name: Tool’s name.
  • description: What it does.
  • params_json_schema: Expected input.
  • on_invoke_tool: Function to call.

The agent is created with clear instructions:

This setup ensures the agent knows how to handle each request and can guide users, even with partial information.

Example Interactions

Let’s see this in action. You can interact with your agent using natural language.

List all tasks:

Create a new task:

Update a task:

Delete a task:

The agent translates your request into the correct CRUD operation and interacts with the API. This makes managing tasks as easy as typing or speaking commands.

Lesson Summary and Practice Introduction

You’ve learned how to enhance a Todo API agent to support all CRUD operations. We covered CRUD theory, data modeling with Pydantic, implementing each operation, and connecting everything to an agent that understands natural language.

Now, it’s your turn. In the next section, you’ll practice implementing and testing CRUD operations with the Todo API agent. This hands-on work will help you master these concepts and prepare you for more advanced agent development. Good luck!

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal