pygent 0.1.1__tar.gz → 0.1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pygent-0.1.1 → pygent-0.1.2}/PKG-INFO +4 -3
- pygent-0.1.2/README.md +81 -0
- {pygent-0.1.1 → pygent-0.1.2}/pygent/__init__.py +1 -1
- {pygent-0.1.1 → pygent-0.1.2}/pygent/agent.py +5 -2
- {pygent-0.1.1 → pygent-0.1.2}/pygent/cli.py +3 -3
- pygent-0.1.2/pygent/openai_compat.py +71 -0
- {pygent-0.1.1 → pygent-0.1.2}/pygent/runtime.py +3 -3
- {pygent-0.1.1 → pygent-0.1.2}/pygent/tools.py +1 -1
- {pygent-0.1.1 → pygent-0.1.2}/pygent.egg-info/PKG-INFO +4 -3
- {pygent-0.1.1 → pygent-0.1.2}/pygent.egg-info/SOURCES.txt +1 -0
- {pygent-0.1.1 → pygent-0.1.2}/pygent.egg-info/requires.txt +3 -1
- {pygent-0.1.1 → pygent-0.1.2}/pyproject.toml +9 -8
- pygent-0.1.1/README.md +0 -79
- {pygent-0.1.1 → pygent-0.1.2}/LICENSE +0 -0
- {pygent-0.1.1 → pygent-0.1.2}/pygent/py.typed +0 -0
- {pygent-0.1.1 → pygent-0.1.2}/pygent.egg-info/dependency_links.txt +0 -0
- {pygent-0.1.1 → pygent-0.1.2}/pygent.egg-info/entry_points.txt +0 -0
- {pygent-0.1.1 → pygent-0.1.2}/pygent.egg-info/top_level.txt +0 -0
- {pygent-0.1.1 → pygent-0.1.2}/setup.cfg +0 -0
- {pygent-0.1.1 → pygent-0.1.2}/tests/test_tools.py +0 -0
- {pygent-0.1.1 → pygent-0.1.2}/tests/test_version.py +0 -0
@@ -1,14 +1,15 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: pygent
|
3
|
-
Version: 0.1.
|
4
|
-
Summary: Pygent
|
3
|
+
Version: 0.1.2
|
4
|
+
Summary: Pygent is a minimalist coding assistant that runs commands in a Docker container when available and falls back to local execution. See https://marianochaves.github.io/pygent for documentation and https://github.com/marianochaves/pygent for the source code.
|
5
5
|
Author-email: Mariano Chaves <mchaves.software@gmail.com>
|
6
6
|
Project-URL: Documentation, https://marianochaves.github.io/pygent
|
7
7
|
Project-URL: Repository, https://github.com/marianochaves/pygent
|
8
8
|
Requires-Python: >=3.9
|
9
9
|
License-File: LICENSE
|
10
|
-
Requires-Dist: openai>=1.0.0
|
11
10
|
Requires-Dist: rich>=13.7.0
|
11
|
+
Provides-Extra: llm
|
12
|
+
Requires-Dist: openai>=1.0.0; extra == "llm"
|
12
13
|
Provides-Extra: test
|
13
14
|
Requires-Dist: pytest; extra == "test"
|
14
15
|
Provides-Extra: docs
|
pygent-0.1.2/README.md
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
# Pygent
|
2
|
+
|
3
|
+
Pygent is a coding assistant that executes each request inside an isolated Docker container whenever possible. If Docker is unavailable (for instance on some Windows setups) the commands are executed locally instead.
|
4
|
+
|
5
|
+
## Features
|
6
|
+
|
7
|
+
* Runs commands in ephemeral containers (default image `python:3.12-slim`).
|
8
|
+
* Integrates with OpenAI-compatible models to orchestrate each step.
|
9
|
+
* Persists the conversation history during the session.
|
10
|
+
* Provides a small Python API for use in other projects.
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Installing from source is recommended:
|
15
|
+
|
16
|
+
```bash
|
17
|
+
pip install -e .
|
18
|
+
```
|
19
|
+
|
20
|
+
Python ≥ 3.9 is required. The only runtime dependency is `rich`.
|
21
|
+
Install any OpenAI-compatible library such as `openai` or `litellm` separately to enable model access.
|
22
|
+
To run commands in Docker containers also install `pygent[docker]`.
|
23
|
+
|
24
|
+
## Configuration
|
25
|
+
|
26
|
+
Behaviour can be adjusted via environment variables:
|
27
|
+
|
28
|
+
* `OPENAI_API_KEY` – key used to access the OpenAI API.
|
29
|
+
* `PYGENT_MODEL` – model name used for requests (default `gpt-4o-mini-preview`).
|
30
|
+
* `PYGENT_IMAGE` – Docker image to create the container (default `python:3.12-slim`).
|
31
|
+
* `PYGENT_USE_DOCKER` – set to `0` to disable Docker and run locally.
|
32
|
+
|
33
|
+
## CLI usage
|
34
|
+
|
35
|
+
After installing run:
|
36
|
+
|
37
|
+
```bash
|
38
|
+
pygent
|
39
|
+
```
|
40
|
+
|
41
|
+
Use `--docker` to run commands inside a container (requires
|
42
|
+
`pygent[docker]`). Use `--no-docker` or set `PYGENT_USE_DOCKER=0`
|
43
|
+
to force local execution.
|
44
|
+
|
45
|
+
Type messages normally; use `/exit` to end the session. Each command is executed in the container and the result shown in the terminal.
|
46
|
+
|
47
|
+
## API usage
|
48
|
+
|
49
|
+
You can also interact directly with the Python code:
|
50
|
+
|
51
|
+
```python
|
52
|
+
from pygent import Agent
|
53
|
+
|
54
|
+
ag = Agent()
|
55
|
+
ag.step("echo 'Hello World'")
|
56
|
+
# ... more steps
|
57
|
+
ag.runtime.cleanup()
|
58
|
+
```
|
59
|
+
|
60
|
+
See the `examples/` folder for more complete scripts.
|
61
|
+
|
62
|
+
## Development
|
63
|
+
|
64
|
+
1. Install the test dependencies:
|
65
|
+
|
66
|
+
```bash
|
67
|
+
pip install -e .[test]
|
68
|
+
```
|
69
|
+
|
70
|
+
2. Run the test suite:
|
71
|
+
|
72
|
+
```bash
|
73
|
+
pytest
|
74
|
+
```
|
75
|
+
|
76
|
+
Use `mkdocs serve` to build the documentation locally.
|
77
|
+
|
78
|
+
## License
|
79
|
+
|
80
|
+
This project is released under the MIT license. See the `LICENSE` file for details.
|
81
|
+
|
@@ -1,4 +1,4 @@
|
|
1
|
-
"""
|
1
|
+
"""Orchestration layer: receives messages, calls the OpenAI-compatible backend and dispatches tools."""
|
2
2
|
|
3
3
|
import json
|
4
4
|
import os
|
@@ -8,7 +8,10 @@ import time
|
|
8
8
|
from dataclasses import dataclass, field
|
9
9
|
from typing import Any, Dict, List
|
10
10
|
|
11
|
-
|
11
|
+
try:
|
12
|
+
import openai # type: ignore
|
13
|
+
except ModuleNotFoundError: # pragma: no cover - fallback to bundled client
|
14
|
+
from . import openai_compat as openai
|
12
15
|
from rich.console import Console
|
13
16
|
from rich.panel import Panel
|
14
17
|
|
@@ -1,12 +1,12 @@
|
|
1
|
-
"""
|
1
|
+
"""Command-line entry point for Pygent."""
|
2
2
|
import argparse
|
3
3
|
|
4
4
|
from .agent import run_interactive
|
5
5
|
|
6
6
|
def main() -> None: # pragma: no cover
|
7
7
|
parser = argparse.ArgumentParser(prog="pygent")
|
8
|
-
parser.add_argument("--docker", dest="use_docker", action="store_true", help="
|
9
|
-
parser.add_argument("--no-docker", dest="use_docker", action="store_false", help="
|
8
|
+
parser.add_argument("--docker", dest="use_docker", action="store_true", help="run commands in a Docker container")
|
9
|
+
parser.add_argument("--no-docker", dest="use_docker", action="store_false", help="run locally")
|
10
10
|
parser.set_defaults(use_docker=None)
|
11
11
|
args = parser.parse_args()
|
12
12
|
run_interactive(use_docker=args.use_docker)
|
@@ -0,0 +1,71 @@
|
|
1
|
+
import os
|
2
|
+
import json
|
3
|
+
from dataclasses import dataclass
|
4
|
+
from typing import Any, Dict, List
|
5
|
+
from urllib import request
|
6
|
+
|
7
|
+
OPENAI_BASE_URL = os.getenv("OPENAI_BASE_URL", "https://api.openai.com/v1")
|
8
|
+
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY", "")
|
9
|
+
|
10
|
+
@dataclass
|
11
|
+
class ToolCallFunction:
|
12
|
+
name: str
|
13
|
+
arguments: str
|
14
|
+
|
15
|
+
@dataclass
|
16
|
+
class ToolCall:
|
17
|
+
id: str
|
18
|
+
type: str
|
19
|
+
function: ToolCallFunction
|
20
|
+
|
21
|
+
@dataclass
|
22
|
+
class Message:
|
23
|
+
role: str
|
24
|
+
content: str | None = None
|
25
|
+
tool_calls: List[ToolCall] | None = None
|
26
|
+
|
27
|
+
@dataclass
|
28
|
+
class Choice:
|
29
|
+
message: Message
|
30
|
+
|
31
|
+
@dataclass
|
32
|
+
class ChatCompletion:
|
33
|
+
choices: List[Choice]
|
34
|
+
|
35
|
+
|
36
|
+
def _post(path: str, payload: Dict[str, Any]) -> Dict[str, Any]:
|
37
|
+
data = json.dumps(payload).encode()
|
38
|
+
headers = {"Content-Type": "application/json"}
|
39
|
+
if OPENAI_API_KEY:
|
40
|
+
headers["Authorization"] = f"Bearer {OPENAI_API_KEY}"
|
41
|
+
req = request.Request(f"{OPENAI_BASE_URL}{path}", data=data, headers=headers)
|
42
|
+
with request.urlopen(req) as resp:
|
43
|
+
return json.loads(resp.read().decode())
|
44
|
+
|
45
|
+
|
46
|
+
class _ChatCompletions:
|
47
|
+
def create(self, model: str, messages: List[Dict[str, Any]], tools: Any = None, tool_choice: str | None = "auto") -> ChatCompletion:
|
48
|
+
payload: Dict[str, Any] = {"model": model, "messages": messages}
|
49
|
+
if tools is not None:
|
50
|
+
payload["tools"] = tools
|
51
|
+
if tool_choice is not None:
|
52
|
+
payload["tool_choice"] = tool_choice
|
53
|
+
raw = _post("/chat/completions", payload)
|
54
|
+
choices: List[Choice] = []
|
55
|
+
for ch in raw.get("choices", []):
|
56
|
+
msg_data = ch.get("message", {})
|
57
|
+
tool_calls = []
|
58
|
+
for tc in msg_data.get("tool_calls", []):
|
59
|
+
func = ToolCallFunction(**tc.get("function", {}))
|
60
|
+
tool_calls.append(ToolCall(id=tc.get("id", ""), type=tc.get("type", ""), function=func))
|
61
|
+
msg = Message(role=msg_data.get("role", ""), content=msg_data.get("content"), tool_calls=tool_calls or None)
|
62
|
+
choices.append(Choice(message=msg))
|
63
|
+
return ChatCompletion(choices=choices)
|
64
|
+
|
65
|
+
|
66
|
+
class _Chat:
|
67
|
+
def __init__(self) -> None:
|
68
|
+
self.completions = _ChatCompletions()
|
69
|
+
|
70
|
+
|
71
|
+
chat = _Chat()
|
@@ -1,4 +1,4 @@
|
|
1
|
-
"""
|
1
|
+
"""Run commands in a Docker container, falling back to local execution if needed."""
|
2
2
|
from __future__ import annotations
|
3
3
|
|
4
4
|
import os
|
@@ -16,7 +16,7 @@ except Exception: # pragma: no cover - optional dependency
|
|
16
16
|
|
17
17
|
|
18
18
|
class Runtime:
|
19
|
-
"""
|
19
|
+
"""Executes commands in a Docker container or locally if Docker is unavailable."""
|
20
20
|
|
21
21
|
def __init__(self, image: str | None = None, use_docker: bool | None = None) -> None:
|
22
22
|
self.base_dir = Path(tempfile.mkdtemp(prefix="pygent_"))
|
@@ -48,7 +48,7 @@ class Runtime:
|
|
48
48
|
|
49
49
|
# ---------------- public API ----------------
|
50
50
|
def bash(self, cmd: str, timeout: int = 30) -> str:
|
51
|
-
"""
|
51
|
+
"""Run a command in the container or locally and return the output."""
|
52
52
|
if self._use_docker and self.container is not None:
|
53
53
|
res = self.container.exec_run(
|
54
54
|
cmd,
|
@@ -1,14 +1,15 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: pygent
|
3
|
-
Version: 0.1.
|
4
|
-
Summary: Pygent
|
3
|
+
Version: 0.1.2
|
4
|
+
Summary: Pygent is a minimalist coding assistant that runs commands in a Docker container when available and falls back to local execution. See https://marianochaves.github.io/pygent for documentation and https://github.com/marianochaves/pygent for the source code.
|
5
5
|
Author-email: Mariano Chaves <mchaves.software@gmail.com>
|
6
6
|
Project-URL: Documentation, https://marianochaves.github.io/pygent
|
7
7
|
Project-URL: Repository, https://github.com/marianochaves/pygent
|
8
8
|
Requires-Python: >=3.9
|
9
9
|
License-File: LICENSE
|
10
|
-
Requires-Dist: openai>=1.0.0
|
11
10
|
Requires-Dist: rich>=13.7.0
|
11
|
+
Provides-Extra: llm
|
12
|
+
Requires-Dist: openai>=1.0.0; extra == "llm"
|
12
13
|
Provides-Extra: test
|
13
14
|
Requires-Dist: pytest; extra == "test"
|
14
15
|
Provides-Extra: docs
|
@@ -1,14 +1,19 @@
|
|
1
1
|
[project]
|
2
2
|
name = "pygent"
|
3
|
-
version = "0.1.
|
4
|
-
description = "Pygent
|
3
|
+
version = "0.1.2"
|
4
|
+
description = "Pygent is a minimalist coding assistant that runs commands in a Docker container when available and falls back to local execution. See https://marianochaves.github.io/pygent for documentation and https://github.com/marianochaves/pygent for the source code."
|
5
5
|
authors = [ { name = "Mariano Chaves", email = "mchaves.software@gmail.com" } ]
|
6
6
|
requires-python = ">=3.9"
|
7
7
|
dependencies = [
|
8
|
-
"
|
9
|
-
"rich>=13.7.0" # saídas coloridas (opcional)
|
8
|
+
"rich>=13.7.0" # colored output (optional)
|
10
9
|
]
|
11
10
|
|
11
|
+
[project.optional-dependencies]
|
12
|
+
llm = ["openai>=1.0.0"] # OpenAI-compatible library (optional)
|
13
|
+
test = ["pytest"]
|
14
|
+
docs = ["mkdocs"]
|
15
|
+
docker = ["docker>=7.0.0"]
|
16
|
+
|
12
17
|
[project.urls]
|
13
18
|
Documentation = "https://marianochaves.github.io/pygent"
|
14
19
|
Repository = "https://github.com/marianochaves/pygent"
|
@@ -16,10 +21,6 @@ Repository = "https://github.com/marianochaves/pygent"
|
|
16
21
|
[project.scripts]
|
17
22
|
pygent = "pygent.cli:main"
|
18
23
|
|
19
|
-
[project.optional-dependencies]
|
20
|
-
test = ["pytest"]
|
21
|
-
docs = ["mkdocs"]
|
22
|
-
docker = ["docker>=7.0.0"]
|
23
24
|
|
24
25
|
[tool.setuptools.package-data]
|
25
26
|
"pygent" = ["py.typed"]
|
pygent-0.1.1/README.md
DELETED
@@ -1,79 +0,0 @@
|
|
1
|
-
# Pygent
|
2
|
-
|
3
|
-
Pygent é um assistente de código que executa cada solicitação em um container Docker isolado sempre que possível. Caso Docker não esteja disponível (por exemplo em algumas instalações do Windows), o Pygent ainda funciona executando os comandos localmente.
|
4
|
-
|
5
|
-
## Recursos
|
6
|
-
|
7
|
-
* Execução de comandos em containers efêmeros (imagem padrão `python:3.12-slim`).
|
8
|
-
* Integração com modelos da OpenAI para orquestração das etapas.
|
9
|
-
* Histórico persistente das interações durante a sessão.
|
10
|
-
* API Python simples para integração em outros projetos.
|
11
|
-
|
12
|
-
## Instalação
|
13
|
-
|
14
|
-
Recomenda-se instalar a partir do código fonte:
|
15
|
-
|
16
|
-
```bash
|
17
|
-
pip install -e .
|
18
|
-
```
|
19
|
-
|
20
|
-
É necessário possuir Python ≥ 3.9. As dependências de runtime são `openai` e `rich`. Para executar dentro de containers Docker instale também `pygent[docker]`.
|
21
|
-
|
22
|
-
## Configuração
|
23
|
-
|
24
|
-
O comportamento pode ser ajustado via variáveis de ambiente:
|
25
|
-
|
26
|
-
* `OPENAI_API_KEY` – chave para acesso à API da OpenAI.
|
27
|
-
* `PYGENT_MODEL` – modelo utilizado nas chamadas (padrão `gpt-4o-mini-preview`).
|
28
|
-
* `PYGENT_IMAGE` – imagem Docker para criar o container (padrão `python:3.12-slim`).
|
29
|
-
* `PYGENT_USE_DOCKER` – defina `0` para desabilitar Docker e executar localmente.
|
30
|
-
|
31
|
-
## Uso via CLI
|
32
|
-
|
33
|
-
Após instalar, execute:
|
34
|
-
|
35
|
-
```bash
|
36
|
-
pygent
|
37
|
-
```
|
38
|
-
|
39
|
-
Use `--docker` para executar os comandos dentro de um container (requere
|
40
|
-
`pygent[docker]`). Utilize `--no-docker` ou defina `PYGENT_USE_DOCKER=0`
|
41
|
-
para forçar a execução local.
|
42
|
-
|
43
|
-
Digite mensagens normalmente; utilize `/exit` para encerrar a sessão. Todo comando é executado dentro do container e o resultado é exibido no terminal.
|
44
|
-
|
45
|
-
## Uso via API
|
46
|
-
|
47
|
-
Também é possível interagir diretamente com o código Python:
|
48
|
-
|
49
|
-
```python
|
50
|
-
from pygent import Agent
|
51
|
-
|
52
|
-
ag = Agent()
|
53
|
-
ag.step("echo 'Ola Mundo'")
|
54
|
-
# ... demias passos
|
55
|
-
ag.runtime.cleanup()
|
56
|
-
```
|
57
|
-
|
58
|
-
Confira a pasta `examples/` para scripts mais completos.
|
59
|
-
|
60
|
-
## Desenvolvimento
|
61
|
-
|
62
|
-
1. Instale as dependências de teste:
|
63
|
-
|
64
|
-
```bash
|
65
|
-
pip install -e .[test]
|
66
|
-
```
|
67
|
-
|
68
|
-
2. Rode o conjunto de testes:
|
69
|
-
|
70
|
-
```bash
|
71
|
-
pytest
|
72
|
-
```
|
73
|
-
|
74
|
-
Para gerar a documentação localmente utilize `mkdocs serve`.
|
75
|
-
|
76
|
-
## Licença
|
77
|
-
|
78
|
-
Este projeto é distribuído sob a licença MIT. Consulte o arquivo `LICENSE` para mais detalhes.
|
79
|
-
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|