Sitemap
Press enter or click to view image in full size

Anthropic Agent Workflow Prototype

13 min readOct 27, 2025

--

When I started looking at AI Agents there was focus on a more code heavy approach, take for instance ReAct (Reason & Act) AI Agents.

The AI Agents typically relied on one Language Model which acted as the backbone of the AI Agent.

Not long ago, the term “AI Agent” was overtaken in popularity by the term “Agentic Workflows”. A number of companies launched GUI Agent workflow builders.

The most recent and talked about being the OpenAI Agentic Builder.

The new paradigm seems to be that of finding a balance in leveraging code and the model’s inherent capabilities…and the most recent capability to leverage is reasoning.

NVIDIA has also been backing this growing trend of agentic workflows where the orchestrating AI Agent (the “conductors” that plan, route tasks, and synthesise outputs) are indeed leaning toward being more lightweight and less code-intensive to implement.

These Agentic Workflows are easy to build in general, especially when presented via a GUI builder, that is no-code and handles tasks like versioning, collaboration and more.

Press enter or click to view image in full size
The code below is a full working version of the Python code that orchestrates two of Anthropic’s models to ingest four PDF’s cover Apple financial reports. And via a lightweight Agentic Workflow, create a text and graphic report as seen above.

The Agentic workflow I cover in this post can be considered from two perspectives…

The first, the Python routine can be used as a utility, where you can edit it and run as required for more personal use.

Secondly, the code can be turned into a conversational GUI, where the user is prompted vir their query, and give the opportunity to upload PDF’s. In which case there will need to be a level of disambiguation to clarify user intent.

You will see In that Claude cookbook example, the orchestrator (Claude 3 Opus) does handle some heavier lifting — like generating detailed prompts and even Matplotlib code for visualisation .

But it’s not bogged down in custom scripting or heavy tooling.

The real lightweight magic happens with the sub-agents (Haiku models), which are fast, cheap and specialised for grunt work like image-based PDF extraction.

The overall setup keeps things prompt-driven and modular. .

Orchestrators don’t need to be monolithic…they can be slim layers that delegate to specialised, lighter workers.

Press enter or click to view image in full size
This image shows how the user request is sent to Claude Opus, the more powerful and capable model and the four PDF documents are processed in parallel which optimises for time. The individual document processing is performed by the Claude Haiku model. Lastly, the Claude Opus model brings it all together and creates the final output.

PDF’s can be tricky to understand by models due to tables, charts etc.

Claude 3 Haiku is the lightweight sub-agent that does the targeted extraction work from the PDFs.

Using Claude’s multimodal vision capabilities.

You will see that the code converts each PDF page into high resolution PNG images.

Then encodes them as base64 strings. I’m not an expert on this, but there are a number of ways to convert PDFs into something easily digestible by the model.

For instance, some of the OpenAI demo framework code for web browsing converts the web UI into an image for the model to interpret and act on.

Press enter or click to view image in full size

A more detailed workflow below, what also like about this approach, is that there is whole host of cookbooks available from different model providers like OpenAI, Cohere, Anthropic and also frameworks like LlamaIndex & LangChain.

This example code can easily be adapted for specific use-cases. It is also a way of gleaning ways of doing things and what could serve as the best approach to solve a challenge.

I think for any enterprise implementation, it will make sense to start with smaller prototypes and automation routines and from there expand into something bigger.

Only start using a framework when it makes sense and the situation demands it.

Press enter or click to view image in full size
A more detailed view of the sequence of events.

The code you can copy and paste cell by cell into a Colab notebook and run…

%pip install anthropic IPython PyMuPDF matplotlib

You will need an Anthropic API key…I started saving my API keys in the Colab Secrets tab. It is a convenient way of re-using API keys and not accidentally post keys online.

# Import the required libraries
import fitz
import base64
from PIL import Image
import io
from concurrent.futures import ThreadPoolExecutor
from anthropic import Anthropic
import requests
import os
from google.colab import userdata

# Set up the Claude API client
ANTHROPIC_API_KEY = userdata.get('ANTHROPIC_API_KEY')
client = Anthropic(api_key=ANTHROPIC_API_KEY)
MODEL_NAME = "claude-haiku-4-5"

The urls for the PDFs are defined…with the question…

# List of Apple's earnings release PDF URLs
pdf_urls = [
"https://www.apple.com/newsroom/pdfs/fy2023-q4/FY23_Q4_Consolidated_Financial_Statements.pdf",
"https://www.apple.com/newsroom/pdfs/fy2023-q3/FY23_Q3_Consolidated_Financial_Statements.pdf",
"https://www.apple.com/newsroom/pdfs/FY23_Q2_Consolidated_Financial_Statements.pdf",
"https://www.apple.com/newsroom/pdfs/FY23_Q1_Consolidated_Financial_Statements.pdf"
]

# User's question
QUESTION = "How did Apple's net sales change quarter to quarter in the 2023 financial year and what were the key contributors to the changes?"

The routine to download the PDFs and convert the documents to base64-encoded PNG images.

# Function to download a PDF file from a URL and save it to a specified folder
def download_pdf(url, folder):
response = requests.get(url)
if response.status_code == 200:
file_name = os.path.join(folder, url.split("/")[-1])
with open(file_name, "wb") as file:
file.write(response.content)
return file_name
else:
print(f"Failed to download PDF from {url}")
return None

# Define the function to convert a PDF to a list of base64-encoded PNG images
def pdf_to_base64_pngs(pdf_path, quality=75, max_size=(1024, 1024)):
# Open the PDF file
doc = fitz.open(pdf_path)

base64_encoded_pngs = []

# Iterate through each page of the PDF
for page_num in range(doc.page_count):
# Load the page
page = doc.load_page(page_num)

# Render the page as a PNG image
pix = page.get_pixmap(matrix=fitz.Matrix(300/72, 300/72))

# Convert the pixmap to a PIL Image
image = Image.frombytes("RGB", [pix.width, pix.height], pix.samples)

# Resize the image if it exceeds the maximum size
if image.size[0] > max_size[0] or image.size[1] > max_size[1]:
image.thumbnail(max_size, Image.Resampling.LANCZOS)

# Convert the PIL Image to base64-encoded PNG
image_data = io.BytesIO()
image.save(image_data, format='PNG', optimize=True, quality=quality)
image_data.seek(0)
base64_encoded = base64.b64encode(image_data.getvalue()).decode('utf-8')
base64_encoded_pngs.append(base64_encoded)

# Close the PDF document
doc.close()

return base64_encoded_pngs

# Folder to save the downloaded PDFs
folder = "../images/using_sub_agents"


# Create the directory if it doesn't exist
os.makedirs(folder)

# Download the PDFs concurrently
with ThreadPoolExecutor() as executor:
pdf_paths = list(executor.map(download_pdf, pdf_urls, [folder] * len(pdf_urls)))

# Remove any None values (failed downloads) from pdf_paths
pdf_paths = [path for path in pdf_paths if path is not None]

The smaller model prompt…

def generate_haiku_prompt(question):
messages = [
{
"role": "user",
"content": [
{"type": "text", "text": f"Based on the following question, please generate a specific prompt for an LLM sub-agent to extract relevant information from an earning's report PDF. Each sub-agent only has access to a single quarter's earnings report. Output only the prompt and nothing else.\n\nQuestion: {question}"}
]
}
]

response = client.messages.create(
model="claude-opus-4-1",
max_tokens=2048,
messages=messages
)

return response.content[0].text

haiku_prompt = generate_haiku_prompt(QUESTION)
print(haiku_prompt)

And the output…

Extract the following information from this earnings report:

1. Total net sales revenue for this quarter (in dollars)
2. Total net sales revenue for the previous quarter if mentioned (in dollars)
3. Quarter-over-quarter net sales percentage change if provided
4. Breakdown of net sales by product category (iPhone, Mac, iPad, Wearables/Home/Accessories, Services, etc.) for this quarter
5. Breakdown of net sales by geographic segment (Americas, Europe, Greater China, Japan, Rest of Asia Pacific) for this quarter
6. Any mentioned drivers or reasons for increases in net sales (new product launches, strong demand for specific products, seasonal factors, etc.)
7. Any mentioned drivers or reasons for decreases in net sales (supply constraints, foreign exchange impact, weak demand, competitive pressures, etc.)
8. The specific quarter and year this report covers (e.g., Q1 2023, Q2 2023)

Provide the extracted information in a structured format with clear labels for each data point.

Now the PDFs are processed concurrently with the Haiku sub-agent models …

def extract_info(pdf_path, haiku_prompt):
base64_encoded_pngs = pdf_to_base64_pngs(pdf_path)

messages = [
{
"role": "user",
"content": [
*[{"type": "image", "source": {"type": "base64", "media_type": "image/png", "data": base64_encoded_png}} for base64_encoded_png in base64_encoded_pngs],
{"type": "text", "text": haiku_prompt}
]
}
]

response = client.messages.create(
model="claude-haiku-4-5",
max_tokens=2048,
messages=messages
)

return response.content[0].text, pdf_path

def process_pdf(pdf_path):
return extract_info(pdf_path, haiku_prompt)

# Process the PDFs concurrently with Haiku sub-agent models
with ThreadPoolExecutor() as executor:
extracted_info_list = list(executor.map(process_pdf, pdf_paths))

extracted_info = ""
# Display the extracted information from each model call
for info in extracted_info_list:
extracted_info += "<info quarter=\"" + info[1].split("/")[-1].split("_")[1] + "\">" + info[0] + "</info>\n"
print(extracted_info)

The output below…

<info quarter="Q4"># Apple Inc. Earnings Report - Q4 2023 (Three Months Ended September 30, 2023)

## 1. Total Net Sales Revenue for This Quarter
**$89,498 million** (or $89.5 billion)

## 2. Total Net Sales Revenue for Previous Quarter
**$90,146 million** (or $90.1 billion)
- This represents Q4 2022 (Three Months Ended September 24, 2022)

## 3. Quarter-over-Quarter Net Sales Percentage Change
**-0.72%** (a decrease of $648 million)
- Q4 2023 vs Q4 2022: $89,498M vs $90,146M

## 4. Breakdown of Net Sales by Product Category (Q4 2023)

| Category | Amount ($ millions) | % of Total |
|----------|-------------------|-----------|
| iPhone | $43,805 | 48.9% |
| Services | $22,314 | 24.9% |
| Mac | $7,614 | 8.5% |
| iPad | $6,443 | 7.2% |
| Wearables, Home and Accessories | $9,322 | 10.4% |
| **Total Net Sales** | **$89,498** | **100%** |

## 5. Breakdown of Net Sales by Geographic Segment (Q4 2023)

| Region | Amount ($ millions) | % of Total |
|--------|-------------------|-----------|
| Americas | $40,115 | 44.8% |
| Europe | $22,463 | 25.1% |
| Greater China | $15,084 | 16.9% |
| Japan | $5,505 | 6.2% |
| Rest of Asia Pacific | $6,331 | 7.1% |
| **Total Net Sales** | **$89,498** | **100%** |

## 6. Drivers for Increases in Net Sales
**No specific drivers mentioned in this report.** The financial statements are condensed consolidated statements without management commentary explaining the drivers of performance changes.

## 7. Drivers for Decreases in Net Sales
**No specific drivers mentioned in this report.** The financial statements are condensed consolidated statements without management commentary explaining reasons for the 0.72% year-over-year decline.

## 8. Reporting Period
**Q4 Fiscal Year 2023**
- **Period:** Three Months Ended September 30, 2023
- **Compared to:** Three Months Ended September 24, 2022 (Q4 2022)
- **Full Fiscal Year 2023:** Twelve Months Ended September 30, 2023

---

## Additional Context - Full Year FY 2023
For reference, the full fiscal year (12 months ended September 30, 2023) showed:
- **Total Net Sales:** $383,285 million (vs $394,328 million in FY 2022)
- **Year-over-Year Change:** -2.8% decline
- **Net Income:** $96,995 million (vs $99,803 million in FY 2022)</info>
<info quarter="Q3"># Apple Inc. Earnings Report - Key Financial Data

## 1. Total Net Sales Revenue for This Quarter
**$81,797 million** (Three months ended July 1, 2023)

## 2. Total Net Sales Revenue for Previous Quarter
**$82,959 million** (Three months ended June 25, 2022)

## 3. Quarter-over-Quarter Net Sales Percentage Change
**-1.4%** decline
- Calculation: ($81,797 - $82,959) / $82,959 = -1.4%

## 4. Breakdown of Net Sales by Product Category (Q3 2023)

| Category | Amount ($ millions) | % of Total |
|----------|-------------------|-----------|
| iPhone | $39,669 | 48.5% |
| Services | $21,213 | 25.9% |
| Wearables, Home and Accessories | $8,284 | 10.1% |
| iPad | $5,791 | 7.1% |
| Mac | $6,840 | 8.4% |
| **Total** | **$81,797** | **100%** |

## 5. Breakdown of Net Sales by Geographic Segment (Q3 2023)

| Region | Amount ($ millions) | % of Total |
|--------|-------------------|-----------|
| Americas | $35,383 | 43.3% |
| Europe | $20,205 | 24.7% |
| Greater China | $15,758 | 19.3% |
| Japan | $4,821 | 5.9% |
| Rest of Asia Pacific | $5,630 | 6.9% |
| **Total** | **$81,797** | **100%** |

## 6. Drivers for Increases in Net Sales
**Not explicitly mentioned in the financial statements provided.** The documents contain financial data only without management commentary or operational discussion.

## 7. Drivers for Decreases in Net Sales
**Not explicitly mentioned in the financial statements provided.** The documents contain financial data only without management commentary or operational discussion.

## 8. Reporting Period
**Q3 2023** - Three months ended **July 1, 2023**

---

### Additional Context:
- **Nine-Month Year-to-Date (July 1, 2023)**: $293,787 million (down 3.4% from $304,182 million in same period 2022)
- **Gross Margin (Q3 2023)**: 44.5%
- **Operating Income (Q3 2023)**: $22,998 million
- **Net Income (Q3 2023)**: $19,881 million
- **Diluted EPS (Q3 2023)**: $1.26</info>
<info quarter="Q2"># Apple Inc. Earnings Report Extract

## 1. Total Net Sales Revenue for This Quarter
**$94,836 million** (Q2 2023 - Three Months Ended April 1, 2023)

## 2. Total Net Sales Revenue for Previous Quarter
**$97,278 million** (Q1 2023 - Three Months Ended March 26, 2022)

## 3. Quarter-over-Quarter Net Sales Percentage Change
**-2.5%** (decline from $97,278M to $94,836M)

## 4. Breakdown of Net Sales by Product Category (Q2 2023)

| Category | Amount (millions) | % of Total |
|----------|------------------|-----------|
| iPhone | $51,334 | 54.1% |
| Services | $20,907 | 22.0% |
| Wearables, Home and Accessories | $8,757 | 9.2% |
| iPad | $6,670 | 7.0% |
| Mac | $7,168 | 7.6% |
| **Total Net Sales** | **$94,836** | **100%** |

## 5. Breakdown of Net Sales by Geographic Segment (Q2 2023)

| Region | Amount (millions) | % of Total |
|--------|------------------|-----------|
| Americas | $37,784 | 39.8% |
| Europe | $23,945 | 25.2% |
| Greater China | $17,812 | 18.8% |
| Japan | $7,176 | 7.6% |
| Rest of Asia Pacific | $8,119 | 8.6% |
| **Total Net Sales** | **$94,836** | **100%** |

## 6. Drivers of Increases in Net Sales
**Not explicitly mentioned** in the financial statements provided. The report shows only financial data without commentary on specific drivers.

## 7. Drivers of Decreases in Net Sales
**Not explicitly mentioned** in the financial statements provided. The report shows only financial data without commentary on specific reasons for the quarter-over-quarter decline.

## 8. Quarter and Year Covered
**Q2 Fiscal Year 2023** (Three Months Ended April 1, 2023)

---

**Note:** This extract is based solely on the condensed consolidated financial statements provided. Detailed management commentary regarding business drivers would typically be found in earnings call transcripts or investor letters not included in these financial statements.</info>
<info quarter="Q1"># Apple Inc. Earnings Report Extract

## 1. Total Net Sales Revenue for This Quarter
**$117,154 million** (or $117.154 billion)

## 2. Total Net Sales Revenue for Previous Quarter
**$123,945 million** (or $123.945 billion)
- This is from Q1 FY2022 (Quarter ended December 25, 2021)

## 3. Quarter-over-Quarter Net Sales Percentage Change
**-5.5%** decrease
- Calculation: ($117,154 - $123,945) / $123,945 = -5.5%

## 4. Breakdown of Net Sales by Product Category (This Quarter)

| Category | Revenue ($ millions) |
|----------|---------------------|
| iPhone | $65,775 |
| Mac | $7,735 |
| iPad | $9,396 |
| Wearables, Home and Accessories | $13,482 |
| Services | $20,766 |
| **Total** | **$117,154** |

## 5. Breakdown of Net Sales by Geographic Segment (This Quarter)

| Region | Revenue ($ millions) |
|--------|---------------------|
| Americas | $49,278 |
| Europe | $27,681 |
| Greater China | $23,905 |
| Japan | $6,755 |
| Rest of Asia Pacific | $9,535 |
| **Total** | **$117,154** |

## 6. Drivers of Net Sales Increases
**No specific drivers are explicitly mentioned in the provided statements.** The report presents financial data without narrative commentary on factors driving performance.

## 7. Drivers of Net Sales Decreases
**No specific drivers are explicitly mentioned in the provided statements.** The report presents financial data without narrative commentary on factors affecting decreases.

## 8. Specific Quarter and Year Covered

**Quarter:** Q1 FY2023 (First Quarter of Fiscal Year 2023)

**Period:** Three months ended **December 31, 2022**

---

### Additional Key Metrics:

| Metric | Value |
|--------|-------|
| Gross Margin | $50,332 million (42.9% margin) |
| Operating Income | $36,016 million |
| Net Income | $29,998 million |
| Basic EPS | $1.89 |
| Diluted EPS | $1.88 |</info>
# Prepare the messages for the powerful model
messages = [
{
"role": "user",
"content": [
{"type": "text", "text": f"Based on the following extracted information from Apple's earnings releases, please provide a response to the question: {QUESTION}\n\nAlso, please generate Python code using the matplotlib library to accompany your response. Enclose the code within <code> tags.\n\nExtracted Information:\n{extracted_info}"}
]
}
]

# Generate the matplotlib code using the powerful model
response = client.messages.create(
model="claude-opus-4-1",
max_tokens=4096,
messages=messages
)

generated_response = response.content[0].text
print("Generated Response:")
print(generated_response)
# Extract the matplotlib code from the response
# Function to extract the code and non-code parts from the response
def extract_code_and_response(response):
start_tag = "<code>"
end_tag = "</code>"
start_index = response.find(start_tag)
end_index = response.find(end_tag)
if start_index != -1 and end_index != -1:
code = response[start_index + len(start_tag):end_index].strip()
non_code_response = response[:start_index].strip()
return code, non_code_response
else:
return None, response.strip()

matplotlib_code, non_code_response = extract_code_and_response(generated_response)

print(non_code_response)
if matplotlib_code:

# Execute the extracted matplotlib code
exec(matplotlib_code)
else:
print("No matplotlib code found in the response.")
Based on the extracted information from Apple's earnings releases, here's an analysis of how Apple's net sales changed quarter to quarter in fiscal year 2023:

## Quarter-to-Quarter Net Sales Changes in FY 2023

Apple experienced a challenging fiscal year 2023 with declining net sales across most quarters:

1. **Q1 2023 (Dec 31, 2022)**: $117.154 billion - Started the fiscal year with the highest quarterly revenue
2. **Q2 2023 (Apr 1, 2023)**: $94.836 billion - Significant drop of 19.0% from Q1
3. **Q3 2023 (Jul 1, 2023)**: $81.797 billion - Further decline of 13.7% from Q2
4. **Q4 2023 (Sep 30, 2023)**: $89.498 billion - Partial recovery with 9.4% increase from Q3

## Key Contributors to Changes

### Product Category Performance:
- **iPhone** remained the dominant revenue driver, contributing 48-54% of total sales across all quarters
- **Services** was the second-largest category, maintaining steady contribution at 22-26% of sales
- The seasonal pattern shows iPhone sales peaked in Q1 ($65.8B) during the holiday season, then declined through Q3 ($39.7B) before recovering in Q4 ($43.8B)

### Geographic Distribution:
- **Americas** consistently led regional sales (39-44% of total)
- **Europe** maintained the second position (24-25% of total)
- **Greater China** showed volatility, ranging from 16.9% to 20.4% of total sales

### Seasonal Patterns:
The data clearly shows Apple's typical seasonal cycle with Q1 (holiday quarter) generating the highest revenue, followed by sequential declines through Q3 (summer quarter), and then a partial recovery in Q4 with new product launches.
Press enter or click to view image in full size
Press enter or click to view image in full size

Chief Evangelist @ Kore.ai | I’m passionate about exploring the intersection of AI and language. Language Models, AI Agents, Agentic Apps, Dev Frameworks & Data-Driven Tools shaping tomorrow.

Press enter or click to view image in full size

--

--

Cobus Greyling
Cobus Greyling

Written by Cobus Greyling

I’m passionate about exploring the intersection of AI & language. www.cobusgreyling.com

No responses yet