pygent 0.1.3__py3-none-any.whl → 0.1.5__py3-none-any.whl

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/__init__.py CHANGED
@@ -7,5 +7,6 @@ except _metadata.PackageNotFoundError: # pragma: no cover - fallback for tests
7
7
  __version__ = "0.0.0"
8
8
 
9
9
  from .agent import Agent, run_interactive # noqa: E402,F401, must come after __version__
10
+ from .models import Model, OpenAIModel # noqa: E402,F401
10
11
 
11
- __all__ = ["Agent", "run_interactive"]
12
+ __all__ = ["Agent", "run_interactive", "Model", "OpenAIModel"]
pygent/__main__.py ADDED
@@ -0,0 +1,4 @@
1
+ from .cli import main
2
+
3
+ if __name__ == "__main__":
4
+ main()
pygent/agent.py CHANGED
@@ -8,17 +8,14 @@ import time
8
8
  from dataclasses import dataclass, field
9
9
  from typing import Any, Dict, List
10
10
 
11
- try:
12
- import openai # type: ignore
13
- except ModuleNotFoundError: # pragma: no cover - fallback to bundled client
14
- from . import openai_compat as openai
15
11
  from rich.console import Console
16
12
  from rich.panel import Panel
17
13
 
18
14
  from .runtime import Runtime
19
15
  from .tools import TOOL_SCHEMAS, execute_tool
16
+ from .models import Model, OpenAIModel
20
17
 
21
- MODEL = os.getenv("PYGENT_MODEL", "gpt-4.1-mini")
18
+ DEFAULT_MODEL = os.getenv("PYGENT_MODEL", "gpt-4.1-mini")
22
19
  SYSTEM_MSG = (
23
20
  "You are Pygent, a sandboxed coding assistant.\n"
24
21
  "Respond with JSON when you need to use a tool."
@@ -27,26 +24,20 @@ SYSTEM_MSG = (
27
24
  console = Console()
28
25
 
29
26
 
30
- def _chat(messages: List[Dict[str, str]]) -> str:
31
- resp = openai.chat.completions.create(
32
- model=MODEL,
33
- messages=messages,
34
- tools=TOOL_SCHEMAS,
35
- tool_choice="auto",
36
- )
37
- return resp.choices[0].message
38
27
 
39
28
 
40
29
  @dataclass
41
30
  class Agent:
42
31
  runtime: Runtime = field(default_factory=Runtime)
32
+ model: Model = field(default_factory=OpenAIModel)
33
+ model_name: str = DEFAULT_MODEL
43
34
  history: List[Dict[str, Any]] = field(default_factory=lambda: [
44
35
  {"role": "system", "content": SYSTEM_MSG}
45
36
  ])
46
37
 
47
38
  def step(self, user_msg: str) -> None:
48
39
  self.history.append({"role": "user", "content": user_msg})
49
- assistant_msg = _chat(self.history)
40
+ assistant_msg = self.model.chat(self.history, self.model_name, TOOL_SCHEMAS)
50
41
  self.history.append(assistant_msg)
51
42
 
52
43
  if assistant_msg.tool_calls:
pygent/models.py ADDED
@@ -0,0 +1,33 @@
1
+ from __future__ import annotations
2
+
3
+ """Model interface and default implementation for OpenAI-compatible APIs."""
4
+
5
+ from typing import Any, Dict, List, Protocol
6
+
7
+ try:
8
+ import openai # type: ignore
9
+ except ModuleNotFoundError: # pragma: no cover - fallback to bundled client
10
+ from . import openai_compat as openai
11
+
12
+ from .openai_compat import Message
13
+
14
+
15
+ class Model(Protocol):
16
+ """Protocol for chat models used by :class:`~pygent.agent.Agent`."""
17
+
18
+ def chat(self, messages: List[Dict[str, Any]], model: str, tools: Any) -> Message:
19
+ """Return the assistant message for the given prompt."""
20
+ ...
21
+
22
+
23
+ class OpenAIModel:
24
+ """Default model using the OpenAI-compatible API."""
25
+
26
+ def chat(self, messages: List[Dict[str, Any]], model: str, tools: Any) -> Message:
27
+ resp = openai.chat.completions.create(
28
+ model=model,
29
+ messages=messages,
30
+ tools=tools,
31
+ tool_choice="auto",
32
+ )
33
+ return resp.choices[0].message
pygent/ui.py CHANGED
@@ -1,6 +1,6 @@
1
- from .agent import Agent, _chat
1
+ from .agent import Agent
2
2
  from .runtime import Runtime
3
- from .tools import execute_tool
3
+ from .tools import execute_tool, TOOL_SCHEMAS
4
4
 
5
5
 
6
6
  def run_gui(use_docker: bool | None = None) -> None:
@@ -16,7 +16,7 @@ def run_gui(use_docker: bool | None = None) -> None:
16
16
 
17
17
  def _respond(message: str, history: list[tuple[str, str]] | None) -> str:
18
18
  agent.history.append({"role": "user", "content": message})
19
- assistant_msg = _chat(agent.history)
19
+ assistant_msg = agent.model.chat(agent.history, agent.model_name, TOOL_SCHEMAS)
20
20
  agent.history.append(assistant_msg)
21
21
  reply = assistant_msg.content or ""
22
22
  if assistant_msg.tool_calls:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pygent
3
- Version: 0.1.3
3
+ Version: 0.1.5
4
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
@@ -0,0 +1,16 @@
1
+ pygent/__init__.py,sha256=_YO8FYMUMAWlRYCa6OBsfmJ9P4mCiYoOqFBLrQDP8qQ,442
2
+ pygent/__main__.py,sha256=MSmt_5Xg84uHqzTN38JwgseJK8rsJn_11A8WD99VtEo,61
3
+ pygent/agent.py,sha256=aR1lHtI3ouI9rEMZLE5lr8tIdC9-A_ZtvdwsvqwxRMg,2010
4
+ pygent/cli.py,sha256=Hz2FZeNMVhxoT5DjCqphXla3TisGJtPEz921LEcpxrA,527
5
+ pygent/models.py,sha256=_3Y1Z5wL6FUqzC-EOjZe3Vkcq4SzbPdGz6TbshcEB98,992
6
+ pygent/openai_compat.py,sha256=mS6ntl70jpVH3JzfNYEDhg-z7QIQcMqQTuEV5ja7VOo,2173
7
+ pygent/py.typed,sha256=0Wh72UpGSn4lSGW-u3xMV9kxcBHMdwE15IGUqiJTwqo,52
8
+ pygent/runtime.py,sha256=33y4jieNeyZ-9nxtVlOmO236u2fDAAv2GaaEWTQDdm8,3173
9
+ pygent/tools.py,sha256=Ru2_voFgPUVc6YgBTRVByn7vWTxXAXT-loAWFMkXHno,1460
10
+ pygent/ui.py,sha256=xqPAvweghPOBBvoD72HzhN6zlXew_3inb8AN7Ck2zpQ,1328
11
+ pygent-0.1.5.dist-info/licenses/LICENSE,sha256=rIktBU2VR4kHzsWul64cbom2zHIgGqYmABoZwSur6T8,1071
12
+ pygent-0.1.5.dist-info/METADATA,sha256=Ajg8ejlOp6EVdNGBs589xrAqcnzwwlH19ZE49KIeDOU,913
13
+ pygent-0.1.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
14
+ pygent-0.1.5.dist-info/entry_points.txt,sha256=b9j216E5UpuMrQWRZrwyEmacNEAYvw1tCKkZqdIVIOc,70
15
+ pygent-0.1.5.dist-info/top_level.txt,sha256=P26IYsb-ThK5IkGP_bRuGJQ0Q_Y8JCcbYqVpvULdxDw,7
16
+ pygent-0.1.5.dist-info/RECORD,,
@@ -1,14 +0,0 @@
1
- pygent/__init__.py,sha256=3YOE3tjTGEc987Vz-TqmYwQ4ogLwTmue642Enf4NVBg,360
2
- pygent/agent.py,sha256=1CGNB0rUmn-oiZ6HGfbr7fBwB_VtIVMR4xP3fISy_YM,2228
3
- pygent/cli.py,sha256=Hz2FZeNMVhxoT5DjCqphXla3TisGJtPEz921LEcpxrA,527
4
- pygent/openai_compat.py,sha256=mS6ntl70jpVH3JzfNYEDhg-z7QIQcMqQTuEV5ja7VOo,2173
5
- pygent/py.typed,sha256=0Wh72UpGSn4lSGW-u3xMV9kxcBHMdwE15IGUqiJTwqo,52
6
- pygent/runtime.py,sha256=33y4jieNeyZ-9nxtVlOmO236u2fDAAv2GaaEWTQDdm8,3173
7
- pygent/tools.py,sha256=Ru2_voFgPUVc6YgBTRVByn7vWTxXAXT-loAWFMkXHno,1460
8
- pygent/ui.py,sha256=DSW1o3gdhuEdJkyBkJmPE_NUHgvowzMjW2Hs2kGh_4A,1278
9
- pygent-0.1.3.dist-info/licenses/LICENSE,sha256=rIktBU2VR4kHzsWul64cbom2zHIgGqYmABoZwSur6T8,1071
10
- pygent-0.1.3.dist-info/METADATA,sha256=tyOn6Jgwd70ALAlVa21m7XulzU4nnGCC_KKquKNKsWg,913
11
- pygent-0.1.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
12
- pygent-0.1.3.dist-info/entry_points.txt,sha256=b9j216E5UpuMrQWRZrwyEmacNEAYvw1tCKkZqdIVIOc,70
13
- pygent-0.1.3.dist-info/top_level.txt,sha256=P26IYsb-ThK5IkGP_bRuGJQ0Q_Y8JCcbYqVpvULdxDw,7
14
- pygent-0.1.3.dist-info/RECORD,,
File without changes