Skip to content

Commit 85ecd28

Browse files
committed
organize: kubernetes should have a subdirectory for a job
antipating other kubernetes abstractions, lets move job into a submodule of kubernetes. Signed-off-by: vsoch <[email protected]>
1 parent a5120b0 commit 85ecd28

File tree

9 files changed

+76
-54
lines changed

9 files changed

+76
-54
lines changed

examples/agent/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ We haven't hit the case yet where the manager needs to take over - that needs fu
7272
#### To do items
7373

7474
- Figure out optimization agent (with some goal)
75+
- The LLM absolutely needs detail about the data, and what to run.
76+
- Error messages from programs are immensely important now since the LLM makes decisions entirely from it.
7577
- Right now when we restart, we do with fresh slate (no log memory) - should there be?
7678
- We likely want some want to quantify the amount of change between prompts, and the difficulty of the task.
7779
- I think likely when we return to the manager, we want the last response (that might say why it is returning) should inform step selection. But not just step selection, the updated prompt to the step missing something.

fractale/agent/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from fractale.agent.build import BuildAgent
2-
from fractale.agent.kubernetes_job import KubernetesJobAgent
2+
from fractale.agent.kubernetes import KubernetesJobAgent
33
from fractale.agent.manager import ManagerAgent
44

55

fractale/agent/base.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,6 @@ def ask_gemini(self, prompt, with_history=True):
272272
"""
273273
Ask gemini adds a wrapper with some error handling.
274274
"""
275-
# Always remove lines with empty spaces
276-
if len(prompt) > 15000:
277-
print("FOUND CHONKER PROMPT")
278-
import IPython
279-
280-
IPython.embed()
281275
try:
282276
start = time.perf_counter()
283277
if with_history:

fractale/agent/kubernetes/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from .job import KubernetesJobAgent
2+
assert KubernetesJobAgent

fractale/agent/kubernetes/base.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import argparse
2+
from rich.syntax import Syntax
3+
4+
import fractale.agent.logger as logger
5+
from fractale.agent.base import GeminiAgent
6+
7+
8+
class KubernetesAgent(GeminiAgent):
9+
"""
10+
A Kubernetes agent is a base class for a generic Kubernetes agent.
11+
"""
12+
13+
def _add_arguments(self, subparser):
14+
"""
15+
Add arguments for the plugin to show up in argparse
16+
"""
17+
agent = subparser.add_parser(
18+
self.name,
19+
formatter_class=argparse.RawTextHelpFormatter,
20+
description=self.description,
21+
)
22+
agent.add_argument(
23+
"container",
24+
help="Container unique resource identifier to use (required)",
25+
)
26+
agent.add_argument(
27+
"--environment",
28+
help="Environment description to build for (defaults to generic)",
29+
)
30+
agent.add_argument(
31+
"--no-pull",
32+
default=False,
33+
action="store_true",
34+
help="Do not pull the image, assume pull policy is Never",
35+
)
36+
agent.add_argument("--context-file", help="Context from a deploy failure or similar.")
37+
return agent
38+
39+
def print_result(self, job_crd):
40+
"""
41+
Print Job CRD with highlighted Syntax
42+
"""
43+
highlighted_syntax = Syntax(job_crd, "yaml", theme="monokai", line_numbers=True)
44+
logger.custom(
45+
highlighted_syntax, title="Final Kubernetes Job", border_style="green", expand=True
46+
)
47+
48+
49+
def save_log(self, full_logs):
50+
"""
51+
Save logs to metadata
52+
"""
53+
if self.save_incremental:
54+
if "logs" not in self.metadata["assets"]:
55+
self.metadata["assets"]["logs"] = []
56+
self.metadata["assets"]["logs"].append({"item": full_logs, "attempt": self.attempts})
57+
58+
def save_job_manifest(self, job):
59+
"""
60+
Save job manifest to metadata
61+
"""
62+
if self.save_incremental:
63+
if self.result_type not in self.metadata["assets"]:
64+
self.metadata["assets"][self.result_type] = []
65+
self.metadata["assets"][self.result_type].append(
66+
{"item": job, "attempt": self.attempts}
67+
)

fractale/agent/kubernetes_job/agent.py renamed to fractale/agent/kubernetes/job/agent.py

Lines changed: 4 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
from rich import print
1414
from rich.syntax import Syntax
1515

16-
import fractale.agent.kubernetes_job.objects as objects
17-
import fractale.agent.kubernetes_job.prompts as prompts
16+
import fractale.agent.kubernetes.objects as objects
17+
from fractale.agent.kubernetes.base import KubernetesAgent
18+
import fractale.agent.kubernetes.job.prompts as prompts
1819
import fractale.agent.logger as logger
1920
import fractale.utils as utils
2021
from fractale.agent.base import GeminiAgent
@@ -23,7 +24,7 @@
2324
from fractale.agent.errors import DebugAgent
2425

2526

26-
class KubernetesJobAgent(GeminiAgent):
27+
class KubernetesJobAgent(KubernetesAgent):
2728
"""
2829
A Kubernetes Job agent knows how to design a Kubernetes job.
2930
"""
@@ -32,32 +33,6 @@ class KubernetesJobAgent(GeminiAgent):
3233
description = "Kubernetes Job agent"
3334
result_type = "kubernetes-job-manifest"
3435

35-
def _add_arguments(self, subparser):
36-
"""
37-
Add arguments for the plugin to show up in argparse
38-
"""
39-
agent = subparser.add_parser(
40-
self.name,
41-
formatter_class=argparse.RawTextHelpFormatter,
42-
description=self.description,
43-
)
44-
agent.add_argument(
45-
"container",
46-
help="Container unique resource identifier to use (required)",
47-
)
48-
agent.add_argument(
49-
"--environment",
50-
help="Environment description to build for (defaults to generic)",
51-
)
52-
agent.add_argument(
53-
"--no-pull",
54-
default=False,
55-
action="store_true",
56-
help="Do not pull the image, assume pull policy is Never",
57-
)
58-
agent.add_argument("--context-file", help="Context from a deploy failure or similar.")
59-
return agent
60-
6136
def get_prompt(self, context):
6237
"""
6338
Get the prompt for the LLM. We expose this so the manager can take it
@@ -135,15 +110,6 @@ def add_build_context(self, context):
135110
context.dockerfile = utils.read_file(build_context)
136111
return context
137112

138-
def print_result(self, job_crd):
139-
"""
140-
Print Job CRD with highlighted Syntax
141-
"""
142-
highlighted_syntax = Syntax(job_crd, "yaml", theme="monokai", line_numbers=True)
143-
logger.custom(
144-
highlighted_syntax, title="Final Kubernetes Job", border_style="green", expand=True
145-
)
146-
147113
def get_diagnostics(self, job, pod):
148114
"""
149115
Helper to collect rich error data for a failed job.
@@ -369,15 +335,6 @@ def deploy(self, context):
369335
# Save full logs for the step
370336
return 0, full_logs
371337

372-
def save_log(self, full_logs):
373-
"""
374-
Save logs to metadata
375-
"""
376-
if self.save_incremental:
377-
if "logs" not in self.metadata["assets"]:
378-
self.metadata["assets"]["logs"] = []
379-
self.metadata["assets"]["logs"].append({"item": full_logs, "attempt": self.attempts})
380-
381338
def save_job_manifest(self, job):
382339
"""
383340
Save job manifest to metadata

0 commit comments

Comments
 (0)