Example: Planning with Our Assistant › Executing the Plan

Michael BrenndoerferJuly 23, 20253 min read
AI Agent HandbookAll chapters
Part 9 of 15Planning - Agents with a Plan
Chapter 26Example: Planning with Our Assistant › Executing the Plan
Reading section 4 of 9 · Executing the Plan · 3 minSection 4 of 9 · 3 min

Book contents

Section 4 of 9 · 3 min read

Example: Planning with Our Assistant › Executing the PlanOne section · Sections in this chapter4 / 9 ↓

Now our assistant moves through each step, using the tools and capabilities we've built in previous chapters.

Step 1-3: Finding a Meeting Time

In[2]:
Code
## Example (Claude Sonnet 4.5)
## Simulating calendar tool calls


def check_calendar(person, start_date, end_date):
    """Tool to check calendar availability"""
    # In reality, this would call Google Calendar API or similar
    if person == "Alice":
        return {
            "available_slots": [
                "2025-11-17 14:00-15:00",
                "2025-11-18 10:00-11:00",
                "2025-11-19 15:00-16:00",
            ]
        }
    else:  # User's calendar
        return {
            "available_slots": [
                "2025-11-17 14:00-15:00",
                "2025-11-18 10:00-11:00",
                "2025-11-20 09:00-10:00",
            ]
        }


## Agent executes steps 1-3
alice_availability = check_calendar("Alice", "2025-11-17", "2025-11-23")
user_availability = check_calendar("User", "2025-11-17", "2025-11-23")

## Find overlapping slots
alice_slots = set(alice_availability["available_slots"])
user_slots = set(user_availability["available_slots"])
common_slots = alice_slots.intersection(user_slots)

print(f"Available times for both: {list(common_slots)}")
## Output: ['2025-11-17 14:00-15:00', '2025-11-18 10:00-11:00']

The assistant has now completed the first three steps of its plan. It found two possible meeting times.

Step 4-5: Retrieving and Summarizing Q3 Work

Next, the assistant needs to gather information about Q3 marketing activities. This is where memory and retrieval come in.

In[4]:
Code
## Example (Claude Sonnet 4.5)
## Using the memory system from Chapter 6


def retrieve_project_notes(project_name, time_period):
    """Retrieve notes from long-term memory"""
    # This would query a vector database or document store
    return {
        "notes": [
            "Launched new social media campaign in July - 50K impressions",
            "Redesigned email templates - open rate increased 15%",
            "Partnered with 3 influencers for product reviews",
            "A/B tested landing pages - version B performed 22% better",
            "Ran webinar series - 500 attendees total",
        ],
        "documents": ["Q3_campaign_metrics.pdf", "social_media_report.xlsx"],
    }


## Agent executes step 4
q3_data = retrieve_project_notes("marketing", "Q3 2025")

## Agent executes step 5: summarize the findings
summary_prompt = f"""Summarize these Q3 marketing accomplishments in a brief, professional email format:

{q3_data["notes"]}

Keep it concise but highlight key metrics."""

response = client.messages.create(
    model="claude-sonnet-4-5",
    max_tokens=512,
    messages=[{"role": "user", "content": summary_prompt}],
)

summary = response.content[0].text
print(summary)

The assistant generates a summary:

Hi Alice,

Here's a quick overview of our Q3 marketing accomplishments:

- Social Media: Launched new campaign reaching 50K impressions
- Email Marketing: Redesigned templates with 15% improvement in open rates  
- Influencer Partnerships: Collaborated with 3 influencers for product reviews
- Website Optimization: A/B testing showed 22% better performance on new landing page
- Webinar Series: Hosted events with 500 total attendees

Looking forward to discussing Q4 plans!

Step 6: Sending the Summary

In[6]:
Code
## Example (Claude Sonnet 4.5)
def send_email(to, subject, body):
    """Tool to send email"""
    # Would use SendGrid, Gmail API, or similar
    print(f"Sending email to {to}")
    print(f"Subject: {subject}")
    print(f"Body: {body}")
    return {"status": "sent", "message_id": "msg_12345"}


## Agent executes step 6
email_result = send_email(
    to="alice@company.com",
    subject="Q3 Marketing Summary - Ahead of Our Q4 Planning Meeting",
    body=summary,
)

print(f"Email status: {email_result['status']}")

Step 7-8: Scheduling and Confirming

In[8]:
Code
## Example (Claude Sonnet 4.5)
def schedule_meeting(attendees, time_slot, subject, description):
    """Tool to create calendar event"""
    # Would use Google Calendar API or similar
    return {
        "event_id": "evt_67890",
        "status": "scheduled",
        "time": time_slot,
        "attendees": attendees,
    }


## Agent executes step 7
## Choose the first available slot
chosen_time = list(common_slots)[0]

meeting_result = schedule_meeting(
    attendees=["alice@company.com", "user@company.com"],
    time_slot=chosen_time,
    subject="Q4 Marketing Campaign Planning",
    description="Discuss Q4 marketing strategy and campaign plans",
)

## Agent executes step 8: Confirm with user
confirmation_message = f"""
Task completed! Here's what I did:

✓ Found available time: {chosen_time}
✓ Retrieved and summarized Q3 marketing accomplishments
✓ Sent summary to Alice at alice@company.com
✓ Scheduled meeting: "Q4 Marketing Campaign Planning"

The meeting is confirmed for {chosen_time}. Alice has received the Q3 summary in advance.
"""

print(confirmation_message)