# Commit Historian Agent (`josef.prochazka/commit-historian-agent`) Actor

Simple tool to help analyze Github repository commits. It checkouts the repository and get all relevant commit messages. It uses OpenAI to answer questions asked by the user. This is done through PydanticAI framework.

- **URL**: https://apify.com/josef.prochazka/commit-historian-agent.md
- **Developed by:** [Josef Procházka](https://apify.com/josef.prochazka) (community)
- **Categories:** AI, Agents, Open source
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per event

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/platform/actors/running/actors-in-store#pay-per-event

## What's an Apify Actor?

Actors are a software tools running on the Apify platform, for all kinds of web data extraction and automation use cases.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

In JavaScript/TypeScript projects, use official [JavaScript/TypeScript client](https://docs.apify.com/api/client/js.md):

```bash
npm install apify-client
```

In Python projects, use official [Python client library](https://docs.apify.com/api/client/python.md):

```bash
pip install apify-client
```

In shell scripts, use [Apify CLI](https://docs.apify.com/cli/docs.md):

````bash
# MacOS / Linux
curl -fsSL https://apify.com/install-cli.sh | bash
# Windows
irm https://apify.com/install-cli.ps1 | iex
```bash

In AI frameworks, you might use the [Apify MCP server](https://docs.apify.com/platform/integrations/mcp.md).

If your project is in a different language, use the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).


# README

### Commit Historian Agent

Simple tool to help analyze Github repository commits.  It checkouts the repository and gets all relevant commit messages. It uses [OpenAI](https://openai.com/) to answer questions asked by the user. This is done through [PydanticAI](https://ai.pydantic.dev/) framework.

### How to run it

You can pick this actor from [Apify store](https://apify.com/josef.prochazka/commit-historian-agent) and run it on the Apify platform.

Enter repository name and your question and start the Actor.
Optionally you can choose a specific branch if your question is not related to the default branch of the repository.

If you do not input your own OpenAI API key then the actor will use our own API key, which will cause additional costs for running the actor.
You can pass your own OpenAI API key to significantly reduce the actor run costs.

### Example

**Inputs**:
> prompt: Show several most complicated changes done last month.

> repository: apify/crawlee-python

**Result**:
>Here are some of the most complicated changes from last month in the `apify/crawlee-python` repository:
>
>1. **Status Code Handling Update**: This refactor involved removing parameters and methods related to HTTP error status codes in HTTP clients, moving logic to a different class, and updating tests to ensure proper handling of session blocking status codes and error codes that require retries or retires. This was a significant change due to the impact on multiple components such as `Session`, `SessionPool`, `PlaywrightCrawler`, and `HttpCrawler` [details here](https://github.com/apify/crawlee-python/commit/6b5947125e63abdfff481b0669398fc9a7293e55).
>
>2. **Session Cookie Management**: The approach to handling cookies in a session was changed from using a plain dictionary to a more sophisticated `SessionCookies` class incorporating `CookieJar`. This supports basic cookie parameters and multiple domains, requiring extensive updates to tests and support for multi-domain scenarios [details here](https://github.com/apify/crawlee-python/commit/6523b3ade0eed53b0363ddce250c557024339b5e).
>
>3. **Fingerprint Integration**: Integration of the `browserforge` package to enable fingerprint and header generation in `PlaywrightCrawler` was implemented. This added significant functionality to enhance the crawling process by using generated fingerprints [details here](https://github.com/apify/crawlee-python/commit/2b156b4ba688f9111195422e6058dff30eb1f782).
>
>These complex changes involved substantial modifications to multiple parts of the codebase, including handling complex data structures, refactoring logic spread across different modules, and careful testing to ensure stability.


### How does it work

This actor defines one main [AI agent](https://ai.pydantic.dev/api/agent/) that is responsible for processing the prompt and return desired output. It uses one [tool](https://ai.pydantic.dev/api/tools/#pydantic_ai.tools.AgentDepsT) that gets the commit summaries for the main agent.

The tool for getting the commit summaries is responsible for suggesting the relevant time scope of the prompt, getting the raw commit messages in the relevant time scope and prefilter the commits based on whether they seem relevant for the main prompt or not. It is using two different AI agents through what is described in PydanticAI documentation as [programatic agent hand-off](https://ai.pydantic.dev/multi-agent-applications/#programmatic-agent-hand-off):
* Agent responsible for suggesting time scope of the prompt.
* Agent responsible for deciding whether individual commit is relevant for the prompt.

# Actor input Schema

## `prompt` (type: `string`):

Define question or task for the agent.
## `repository` (type: `string`):

Github repository that will be used to get commits and answer the question.
## `branch` (type: `string`):

Github repository branch that will be used to get commits. If not specified then it will use default repo branch.
## `openAIApiKey` (type: `string`):

Your own OpenAI token. Optional, but you will be charged more if you want to use Apify's token.

## Actor input object example

```json
{
  "prompt": "Show several most complicated changes done last month.",
  "repository": "apify/crawlee-python"
}
````

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "prompt": "Show several most complicated changes done last month.",
    "repository": "apify/crawlee-python",
    "branch": ""
};

// Run the Actor and wait for it to finish
const run = await client.actor("josef.prochazka/commit-historian-agent").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "prompt": "Show several most complicated changes done last month.",
    "repository": "apify/crawlee-python",
    "branch": "",
}

# Run the Actor and wait for it to finish
run = client.actor("josef.prochazka/commit-historian-agent").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print("💾 Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "prompt": "Show several most complicated changes done last month.",
  "repository": "apify/crawlee-python",
  "branch": ""
}' |
apify call josef.prochazka/commit-historian-agent --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=josef.prochazka/commit-historian-agent",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "Commit Historian Agent",
        "description": "Simple tool to help analyze Github repository commits. It checkouts the repository and get all relevant commit messages. It uses OpenAI to answer questions asked by the user. This is done through PydanticAI framework.",
        "version": "0.0",
        "x-build-id": "5ps853GFbp98VFnmw"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/josef.prochazka~commit-historian-agent/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-josef.prochazka-commit-historian-agent",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        },
        "/acts/josef.prochazka~commit-historian-agent/runs": {
            "post": {
                "operationId": "runs-sync-josef.prochazka-commit-historian-agent",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor and returns information about the initiated run in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/runsResponseSchema"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/acts/josef.prochazka~commit-historian-agent/run-sync": {
            "post": {
                "operationId": "run-sync-josef.prochazka-commit-historian-agent",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "inputSchema": {
                "type": "object",
                "required": [
                    "repository",
                    "prompt"
                ],
                "properties": {
                    "prompt": {
                        "title": "Prompt for the AI agent",
                        "type": "string",
                        "description": "Define question or task for the agent."
                    },
                    "repository": {
                        "title": "Github repository to be analyzed",
                        "type": "string",
                        "description": "Github repository that will be used to get commits and answer the question."
                    },
                    "branch": {
                        "title": "Repository branch",
                        "type": "string",
                        "description": "Github repository branch that will be used to get commits. If not specified then it will use default repo branch."
                    },
                    "openAIApiKey": {
                        "title": "OpenAI token",
                        "type": "string",
                        "description": "Your own OpenAI token. Optional, but you will be charged more if you want to use Apify's token."
                    }
                }
            },
            "runsResponseSchema": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "string"
                            },
                            "actId": {
                                "type": "string"
                            },
                            "userId": {
                                "type": "string"
                            },
                            "startedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "finishedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "status": {
                                "type": "string",
                                "example": "READY"
                            },
                            "meta": {
                                "type": "object",
                                "properties": {
                                    "origin": {
                                        "type": "string",
                                        "example": "API"
                                    },
                                    "userAgent": {
                                        "type": "string"
                                    }
                                }
                            },
                            "stats": {
                                "type": "object",
                                "properties": {
                                    "inputBodyLen": {
                                        "type": "integer",
                                        "example": 2000
                                    },
                                    "rebootCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "restartCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "resurrectCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "computeUnits": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "options": {
                                "type": "object",
                                "properties": {
                                    "build": {
                                        "type": "string",
                                        "example": "latest"
                                    },
                                    "timeoutSecs": {
                                        "type": "integer",
                                        "example": 300
                                    },
                                    "memoryMbytes": {
                                        "type": "integer",
                                        "example": 1024
                                    },
                                    "diskMbytes": {
                                        "type": "integer",
                                        "example": 2048
                                    }
                                }
                            },
                            "buildId": {
                                "type": "string"
                            },
                            "defaultKeyValueStoreId": {
                                "type": "string"
                            },
                            "defaultDatasetId": {
                                "type": "string"
                            },
                            "defaultRequestQueueId": {
                                "type": "string"
                            },
                            "buildNumber": {
                                "type": "string",
                                "example": "1.0.0"
                            },
                            "containerUrl": {
                                "type": "string"
                            },
                            "usage": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "integer",
                                        "example": 1
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "usageTotalUsd": {
                                "type": "number",
                                "example": 0.00005
                            },
                            "usageUsd": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "number",
                                        "example": 0.00005
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
