agent-executor 0.1.0__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.
@@ -0,0 +1,15 @@
1
+ from .llm import ChatOllama
2
+ from .prompt import ChatPromptTemplate
3
+ from .parser import PydanticOutputParser
4
+ from .agent import create_tool_calling_agent
5
+ from .executor import AgentExecutor
6
+ from .tools import Tool
7
+
8
+ __all__ = [
9
+ "ChatOllama",
10
+ "ChatPromptTemplate",
11
+ "PydanticOutputParser",
12
+ "create_tool_calling_agent",
13
+ "AgentExecutor",
14
+ "Tool",
15
+ ]
@@ -0,0 +1,19 @@
1
+ def create_tool_calling_agent(llm, prompt, tools):
2
+ tool_names = [t.name for t in tools]
3
+
4
+ def agent(messages):
5
+ system = {
6
+ "role": "system",
7
+ "content": (
8
+ "You are an agent.\n"
9
+ f"Available tools: {', '.join(tool_names)}\n\n"
10
+ "When using tools, respond ONLY in JSON:\n"
11
+ "{type: tool, tool: name, args: {}}\n"
12
+ "or\n"
13
+ "{type: final, output: string}"
14
+ )
15
+ }
16
+
17
+ return llm([system] + messages)
18
+
19
+ return agent
@@ -0,0 +1,9 @@
1
+ from dotenv import load_dotenv
2
+ import os
3
+
4
+ load_dotenv() # MUST happen here
5
+
6
+ class Config:
7
+ OLLAMA_HOST = os.getenv("OLLAMA_HOST", "http://localhost:11434")
8
+ OLLAMA_MODEL = os.getenv("OLLAMA_MODEL", "qwen2.5-coder")
9
+ DEBUG = os.getenv("DEBUG", "false").lower() == "true"
@@ -0,0 +1,59 @@
1
+ import json
2
+
3
+
4
+ class AgentExecutor:
5
+ def __init__(self, agent, tools, verbose=False):
6
+ self.agent = agent
7
+ self.verbose = verbose
8
+
9
+ # map tools by name
10
+ self.tools = {t.name: t.func for t in tools}
11
+
12
+ def invoke(self, inputs: dict):
13
+ query = inputs["query"]
14
+
15
+ messages = [
16
+ {"role": "user", "content": query}
17
+ ]
18
+
19
+ while True:
20
+ result = self.agent(messages)
21
+ content = result["message"]["content"]
22
+
23
+ if self.verbose:
24
+ print("\n[RAW MODEL OUTPUT]\n", content)
25
+
26
+ try:
27
+ data = json.loads(content)
28
+ except Exception:
29
+ return {"output": [{"text": content}]}
30
+
31
+ # FINAL ANSWER
32
+ if data.get("type") == "final":
33
+ return {
34
+ "output": [{"text": data.get("output", "")}]
35
+ }
36
+
37
+ # TOOL CALL
38
+ if data.get("type") == "tool":
39
+ tool_name = data.get("tool")
40
+ args = data.get("args", {})
41
+
42
+ if tool_name not in self.tools:
43
+ tool_result = f"Tool not found: {tool_name}"
44
+ else:
45
+ tool_result = self.tools[tool_name](**args)
46
+
47
+ if self.verbose:
48
+ print(f"[TOOL] {tool_name} -> {tool_result}")
49
+
50
+ # feed result back into model
51
+ messages.append({
52
+ "role": "assistant",
53
+ "content": content
54
+ })
55
+
56
+ messages.append({
57
+ "role": "user",
58
+ "content": f"tool_result: {tool_result}"
59
+ })
agent_executer/llm.py ADDED
@@ -0,0 +1,29 @@
1
+ import requests
2
+ from .config import Config
3
+ print("OLLAMA HOST =", Config.OLLAMA_HOST)
4
+
5
+ class ChatOllama:
6
+ def __init__(self, model: str):
7
+ self.model = model
8
+
9
+ def __call__(self, messages):
10
+ payload = {
11
+ "model": self.model,
12
+ "messages": messages,
13
+ "stream": False
14
+ }
15
+
16
+ if Config.DEBUG:
17
+ print("\n[OLLAMA REQUEST]\n", payload)
18
+
19
+ res = requests.post(
20
+ f"{Config.OLLAMA_HOST}/api/chat",
21
+ json=payload
22
+ )
23
+
24
+ data = res.json()
25
+
26
+ if Config.DEBUG:
27
+ print("\n[OLLAMA RESPONSE]\n", data)
28
+
29
+ return data
@@ -0,0 +1,12 @@
1
+ class PydanticOutputParser:
2
+ def __init__(self, pydantic_object):
3
+ self.model = pydantic_object
4
+
5
+ def get_format_instructions(self):
6
+ return f"""
7
+ Return ONLY valid JSON matching this schema:
8
+ {self.model.model_json_schema()}
9
+ """
10
+
11
+ def parse(self, text: str):
12
+ return self.model.model_validate_json(text)
@@ -0,0 +1,25 @@
1
+ class ChatPromptTemplate:
2
+ def __init__(self, messages):
3
+ self.messages = messages
4
+
5
+ @staticmethod
6
+ def from_messages(messages):
7
+ return ChatPromptTemplate(messages)
8
+
9
+ def partial(self, **kwargs):
10
+ updated = []
11
+
12
+ for role, content in self.messages:
13
+
14
+ # ONLY format real strings that contain format variables safely
15
+ if isinstance(content, str):
16
+ try:
17
+ content = content.format(**kwargs)
18
+ except KeyError:
19
+ # ignore missing keys like chat_history / agent_scratchpad
20
+ pass
21
+
22
+ updated.append((role, content))
23
+
24
+ self.messages = updated
25
+ return self
@@ -0,0 +1,9 @@
1
+ from dataclasses import dataclass
2
+ from typing import Callable, Any
3
+
4
+
5
+ @dataclass
6
+ class Tool:
7
+ name: str
8
+ func: Callable[..., Any]
9
+ description: str
@@ -0,0 +1,9 @@
1
+ Metadata-Version: 2.4
2
+ Name: agent-executor
3
+ Version: 0.1.0
4
+ Summary: Minimal Ollama agent executor runtime
5
+ Requires-Python: >=3.10
6
+ Description-Content-Type: text/markdown
7
+ Requires-Dist: pydantic>=2.13.4
8
+ Requires-Dist: python-dotenv>=1.2.2
9
+ Requires-Dist: requests>=2.34.2
@@ -0,0 +1,12 @@
1
+ agent_executer/__init__.py,sha256=Ms5rWOMwtpt1K2K5yYO4MteYHGetopASO6eKD-y2diA,379
2
+ agent_executer/agent.py,sha256=rbs8S0AbswmAQaPuA5tqg0cxgop9NmnIF5OzijbHaBU,580
3
+ agent_executer/config.py,sha256=Nbl0_EaPLhe-9wdWXTJJw2-4ebwAtElNDzccVEOUK0k,287
4
+ agent_executer/executor.py,sha256=pNBjFhKVwkzpVW8Xatm9BWyX8ll-qBjWThGjYub0oEs,1748
5
+ agent_executer/llm.py,sha256=4wXHaayBQD9N-uiDHW_1Kz2uxrrdvQtvIDLD314MxPY,666
6
+ agent_executer/parser.py,sha256=6_SFeYRJx6TuJW-VkkLWa7tP3Ado7N6aS35jubChCxw,343
7
+ agent_executer/prompt.py,sha256=5_8rz82I8-WVJ_g35WPbw5kmwH-xoHLIVarnJChBJRw,741
8
+ agent_executer/tools.py,sha256=5QMeSiOJi4LShQ5vKkX8yUgabN55SRJO6soknCVNljo,163
9
+ agent_executor-0.1.0.dist-info/METADATA,sha256=NQSVPYilNtsjMadXf07G9eNg6O0fKjNjpher910Dl2U,278
10
+ agent_executor-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
11
+ agent_executor-0.1.0.dist-info/top_level.txt,sha256=YPWwC1wrGP2lUVUmi5iQhpx2yotJeA1MEqgICoRlYwY,15
12
+ agent_executor-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ agent_executer