Skip to content
프로젝트

소개

Python 코드 약 100줄을 읽을 수 있다면 에이전트를 이해할 수 있습니다.

AI 및 머신러닝

이 수치를 측정하는 방법

What you can do

  • execute_bash: Run any bash command
  • read_file: Read file contents
  • write_file: Write content to files

측정된 스타 증가

in 24h
0
in 7 days
+5
in 15 days
+10
in 1 month
기록 수집 중

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

README.md

Original

nanoAgent

中文 | English

"The question is not what you look at, but what you see." — Henry David Thoreau

The simplest way to build an agent that can interact with your system.

A minimal implementation of an AI agent using OpenAI's function calling. The agent can execute bash commands, read files, and write files.

If you want to learn more (e.g. what MCP is, and how to fetch tools in a more modern way), see: https://github.com/sanbuphy/nanoMCP

install

pip install -r requirements.txt

Set your environment variables:

macOS/Linux:

export OPENAI_API_KEY='your-key-here'
export OPENAI_BASE_URL='https://api.openai.com/v1'  # optional
export OPENAI_MODEL='gpt-4o-mini'  # optional

Windows (PowerShell):

$env:OPENAI_API_KEY='your-key-here'
$env:OPENAI_BASE_URL='https://api.openai.com/v1'  # optional
$env:OPENAI_MODEL='gpt-4o-mini'  # optional

Windows (CMD):

set OPENAI_API_KEY=your-key-here
set OPENAI_BASE_URL=https://api.openai.com/v1
set OPENAI_MODEL=gpt-4o-mini

quick start

python agent.py "list all python files in current directory"
python agent.py "create a file called hello.txt with 'Hello World'"
python agent.py "read the contents of README.md"

how it works

The agent uses OpenAI's function calling to:

  1. Receive a task from the user
  2. Decide which tools to use (bash, read_file, write_file)
  3. Execute the tools
  4. Return results to the model
  5. Repeat until task is complete

That's it. ~100 lines of code.

# Define tools
tools = [{"type": "function", "function": {...}}]

# Agent loop
for _ in range(max_iterations):
    response = client.chat.completions.create(model=model, messages=messages, tools=tools)
    if not response.choices[0].message.tool_calls:
        return response.choices[0].message.content

    # Execute tool calls
    for tool_call in response.choices[0].message.tool_calls:
        result = available_functions[tool_call.function.name](**args)
        messages.append({"role": "tool", "content": result})

The core is just a loop: call model → execute tools → repeat.

Recent hardening keeps the loop running even when a tool call contains malformed JSON arguments or references an unknown tool; those cases are returned to the model as explicit tool errors instead of crashing the agent.

capabilities

  • execute_bash: Run any bash command
  • read_file: Read file contents
  • write_file: Write content to files

examples

# System operations
python agent.py "what's my current directory and what files are in it?"

# File operations
python agent.py "create a python script that prints hello world"

# Combined tasks
python agent.py "find all .py files and count total lines of code"

license

MIT

────────────────────────────────────────

⏺ Like a single seed that grows into a forest, one file becomes infinite possibilities.

관련 프로젝트 살펴보기

불러오는 중…