Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
c7e7023
Refactor logging setup and enhance tool descriptions in AIAgent class…
daveebbelaar Sep 29, 2025
476e91d
Update README to reflect repository origin and clarify tutorial source.
daveebbelaar Sep 29, 2025
7534c4e
Update README to improve link formatting for repository origin.
daveebbelaar Sep 29, 2025
e214e89
Update .gitignore to exclude workspace files, clean up imports in run…
daveebbelaar Sep 30, 2025
989528f
Update AI model version in AIAgent class across multiple scripts and …
daveebbelaar Sep 30, 2025
bd8a842
Remove logging setup from multiple runbook scripts to streamline code…
daveebbelaar Sep 30, 2025
4904fb5
Update system prompt in AIAgent class to specify avoidance of asteris…
daveebbelaar Sep 30, 2025
ba1a916
update env var to OPENAI_API_KEY
krs-github16 Oct 28, 2025
46e7aef
migrate agent class to OpenAI API and update tool schema
krs-github16 Oct 28, 2025
e6e8cd2
update tool definitions for OpenAI function calling
krs-github16 Oct 28, 2025
a99123b
update tool execution for OpenAI migration
krs-github16 Oct 28, 2025
487337c
migrate chat method to OpenAI responses API
krs-github16 Oct 28, 2025
0f80072
migrate interactive CLI to OpenAI API
krs-github16 Oct 28, 2025
81d930d
migrate final tutorial to OpenAI API
krs-github16 Oct 28, 2025
e0239dd
enhance logging in interactive CLI
krs-github16 Oct 28, 2025
1857b74
complete OpenAI migration with model selection
krs-github16 Oct 28, 2025
7798021
docs: update README for OpenAI migration
krs-github16 Oct 28, 2025
1c66122
Merge pull request #4 from krs-github16/using-openai-responses-api
daveebbelaar Oct 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
demo
agent.log
bug_report.md
*.code-workspace
40 changes: 34 additions & 6 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

Build a complete AI agent in 218 lines of Python. No frameworks, no complexity. Just clean code that shows exactly how agents work.

This tutorial demonstrates a working agent that can read, write, and edit files through natural conversation with Claude. Everything runs from a single Python file using `uv`'s inline dependencies: no virtual environments, no pip installs, no dependency conflicts.
This tutorial demonstrates a working agent that can read, write, and edit files through natural conversation with OpenAI's GPT models using responses api. Everything runs from a single Python file using `uv`'s inline dependencies: no virtual environments, no pip installs, no dependency conflicts.

You'll understand how AI agents parse responses, execute tools, and maintain conversation context. The mechanics laid bare, without abstractions.

## Credits

This code is based on the tutorial by Thorsten Ball in ["How to Build an Agent"](https://ampcode.com/how-to-build-an-agent) from ampcode.com. Thank you, Thorsten. Brilliant guide.
This repository is forked from Francis Beeson's implementation: [Single-File AI Agent Tutorial](https://github.com/leobeeson/single-file-ai-agent-tutorial)

The code is based on the tutorial by Thorsten Ball in ["How to Build an Agent"](https://ampcode.com/how-to-build-an-agent) from ampcode.com. Thank you, Thorsten. Brilliant guide.

## Features

Expand All @@ -26,7 +28,20 @@ This code is based on the tutorial by Thorsten Ball in ["How to Build an Agent"]

- `uv` package manager (see installation instructions below)
- Python 3.12 or higher (though `uv` will [handle this automatically](https://docs.astral.sh/uv/concepts/python-versions/))
- Anthropic API key (you can get one from [Anthropic's Console](https://console.anthropic.com/settings/keys))
- OpenAI API key (you can get one from [OpenAI's Platform](https://platform.openai.com/api-keys))

## Model Selection

The agent supports both reasoning and non-reasoning OpenAI models:

**Reasoning Models** (recommended for complex tasks):
- `gpt-5-mini`, `gpt-5`, `gpt-5-nano`
- `o1-preview`, `o1-mini`, `o3-mini`, `o4-mini`, `o3`, `o4`

**Non-reasoning Models** (faster, more cost-effective):
- `gpt-4o-mini`, `gpt-4o`, `gpt-4.1-mini`, `gpt-4.1`, `gpt-4.1-nano`

The agent automatically detects the model type and adjusts API parameters accordingly.

## Installing uv

Expand Down Expand Up @@ -56,16 +71,29 @@ uv --version

## Running the Agent

1. Export your Anthropic API key:
1. Export your OpenAI API key:

```bash
export ANTHROPIC_API_KEY="your-api-key-here"
export OPENAI_API_KEY="your-api-key-here"
```

2. Run the agent:

```bash
uv run --python python3.12 main.py
uv run main.py
```

### Model Selection

You can specify which model to use with the `--model` argument:

```bash
# Use a reasoning model (default: gpt-4o-mini)
uv run main.py --model gpt-5-mini

# Use a non-reasoning model
uv run main.py --model gpt-4o-mini

```

The agent leverages uv's inline dependencies handling from the script headers, so no manual dependency installation is needed.
Expand Down
Loading