Skip to content

Commit 5330538

Browse files
authored
Merge pull request #42 from lbarcziova/introduce-dry-run
Introduce dry-run mode for skipping pushing and creating MRs
2 parents 1feca93 + aa8ae1e commit 5330538

File tree

7 files changed

+130
-25
lines changed

7 files changed

+130
-25
lines changed

beeai/Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
IMAGE_NAME ?= beeai-agent
22
COMPOSE_FILE ?= compose.yaml
3+
DRY_RUN ?= false
34

45
COMPOSE ?= $(shell command -v podman >/dev/null 2>&1 && echo "podman compose" || echo "docker-compose")
56

@@ -28,6 +29,7 @@ run-rebase-agent-standalone:
2829
-e VERSION=$(VERSION) \
2930
-e JIRA_ISSUE=$(JIRA_ISSUE) \
3031
-e BRANCH=$(BRANCH) \
32+
-e DRY_RUN=$(DRY_RUN) \
3133
rebase-agent
3234

3335

@@ -41,6 +43,7 @@ run-backport-agent-standalone:
4143
-e UPSTREAM_FIX=$(UPSTREAM_FIX) \
4244
-e JIRA_ISSUE=$(JIRA_ISSUE) \
4345
-e BRANCH=$(BRANCH) \
46+
-e DRY_RUN=$(DRY_RUN) \
4447
backport-agent
4548

4649

@@ -51,11 +54,11 @@ run-backport-agent-standalone:
5154

5255
.PHONY: start
5356
start:
54-
$(COMPOSE) -f $(COMPOSE_FILE) up
57+
DRY_RUN=$(DRY_RUN) $(COMPOSE) -f $(COMPOSE_FILE) up
5558

5659
.PHONY: start-detached
5760
start-detached:
58-
$(COMPOSE) -f $(COMPOSE_FILE) up -d
61+
DRY_RUN=$(DRY_RUN) $(COMPOSE) -f $(COMPOSE_FILE) up -d
5962

6063
.PHONY: stop
6164
stop:

beeai/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ make PACKAGE=httpd VERSION=2.4.62 JIRA_ISSUE=RHEL-12345 BRANCH=c10s run-rebase-a
4141
make PACKAGE=httpd UPSTREAM_FIX=https://github.com/... JIRA_ISSUE=RHEL-12345 BRANCH=c10s run-backport-agent-standalone
4242
```
4343

44+
## Dry-Run mode
45+
46+
Both backport and rebase agents support **dry-run mode** for testing workflows without actually pushing changes or creating merge requests. By default, agents run in **production mode** and will create actual commits, pushes, and merge requests.
47+
48+
To enable dry-run mode for testing, set the `DRY_RUN=true` environment variable.
49+
4450
## Observability
4551

4652
You can connect to http://localhost:6006/ to access Phoenix web interface and trace agents

beeai/agents/backport_agent.py

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@
1313
from beeai_framework.errors import FrameworkError
1414
from beeai_framework.memory import UnconstrainedMemory
1515
from beeai_framework.middleware.trajectory import GlobalTrajectoryMiddleware
16+
from beeai_framework.template import PromptTemplate, PromptTemplateInput
1617
from beeai_framework.tools import Tool
1718
from beeai_framework.tools.search.duckduckgo import DuckDuckGoSearchTool
1819
from beeai_framework.tools.think import ThinkTool
1920

2021
from base_agent import BaseAgent, TInputSchema, TOutputSchema
22+
from constants import COMMIT_PREFIX, BRANCH_PREFIX
2123
from observability import setup_observability
2224
from tools import ShellCommandTool
2325
from triage_agent import BackportData, ErrorData
24-
from utils import redis_client
26+
from utils import redis_client, get_git_finalization_steps
2527

2628

2729
class InputSchema(BaseModel):
@@ -70,6 +72,33 @@ def input_schema(self) -> type[TInputSchema]:
7072
def output_schema(self) -> type[TOutputSchema]:
7173
return OutputSchema
7274

75+
def _render_prompt(self, input: TInputSchema) -> str:
76+
# Define template function that can be called from the template
77+
def backport_git_steps(data: dict) -> str:
78+
input_data = self.input_schema.model_validate(data)
79+
return get_git_finalization_steps(
80+
package=input_data.package,
81+
jira_issue=input_data.jira_issue,
82+
commit_title=f"{COMMIT_PREFIX} backport {input_data.jira_issue}",
83+
files_to_commit=f"*.spec and {input_data.jira_issue}.patch",
84+
branch_name=f"{BRANCH_PREFIX}-{input_data.jira_issue}",
85+
git_user=input_data.git_user,
86+
git_email=input_data.git_email,
87+
git_url=input_data.git_url,
88+
dist_git_branch=input_data.dist_git_branch,
89+
)
90+
91+
template = PromptTemplate(
92+
PromptTemplateInput(
93+
schema=self.input_schema,
94+
template=self.prompt,
95+
functions={
96+
"backport_git_steps": backport_git_steps
97+
}
98+
)
99+
)
100+
return template.render(input)
101+
73102
@property
74103
def prompt(self) -> str:
75104
return """
@@ -106,16 +135,7 @@ def prompt(self) -> str:
106135
to the build environment as required by the command).
107136
* Verify the newly added patch applies cleanly using the command `centpkg prep`.
108137
109-
6. Commit the changes:
110-
* The title of the Git commit should be in the format "[DO NOT MERGE: AI EXPERIMENTS] backport {{ jira_issue }}"
111-
* Include the reference to Jira as "Resolves: <jira_issue>" for the issue {{ jira_issue }}.
112-
* Commit the RPM spec file change and the newly added patch file.
113-
* Push the commit to the fork.
114-
115-
7. Open a merge request:
116-
* Authenticate using `glab`
117-
* Open a merge request against the upstream repository of the {{ package }} in {{ git_url }}
118-
with previously created commit.
138+
6. {{ backport_git_steps }}
119139
"""
120140

121141

beeai/agents/constants.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
COMMIT_PREFIX = "[DO NOT MERGE: AI EXPERIMENTS]"
3+
4+
BRANCH_PREFIX = "automated-package-update"

beeai/agents/rebase_agent.py

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@
1313
from beeai_framework.errors import FrameworkError
1414
from beeai_framework.memory import UnconstrainedMemory
1515
from beeai_framework.middleware.trajectory import GlobalTrajectoryMiddleware
16+
from beeai_framework.template import PromptTemplate, PromptTemplateInput
1617
from beeai_framework.tools import Tool
1718
from beeai_framework.tools.search.duckduckgo import DuckDuckGoSearchTool
1819
from beeai_framework.tools.think import ThinkTool
1920

2021
from base_agent import BaseAgent, TInputSchema, TOutputSchema
22+
from constants import COMMIT_PREFIX, BRANCH_PREFIX
2123
from observability import setup_observability
2224
from tools import ShellCommandTool
2325
from triage_agent import RebaseData, ErrorData
24-
from utils import redis_client
26+
from utils import redis_client, get_git_finalization_steps
2527

2628

2729
class InputSchema(BaseModel):
@@ -70,6 +72,33 @@ def input_schema(self) -> type[TInputSchema]:
7072
def output_schema(self) -> type[TOutputSchema]:
7173
return OutputSchema
7274

75+
def _render_prompt(self, input: TInputSchema) -> str:
76+
# Define template function that can be called from the template
77+
def rebase_git_steps(data: dict) -> str:
78+
input_data = self.input_schema.model_validate(data)
79+
return get_git_finalization_steps(
80+
package=input_data.package,
81+
jira_issue=input_data.jira_issue,
82+
commit_title=f"{COMMIT_PREFIX} Update to version {input_data.version}",
83+
files_to_commit="*.spec",
84+
branch_name=f"{BRANCH_PREFIX}-{input_data.version}",
85+
git_user=input_data.git_user,
86+
git_email=input_data.git_email,
87+
git_url=input_data.git_url,
88+
dist_git_branch=input_data.dist_git_branch,
89+
)
90+
91+
template = PromptTemplate(
92+
PromptTemplateInput(
93+
schema=self.input_schema,
94+
template=self.prompt,
95+
functions={
96+
"rebase_git_steps": rebase_git_steps
97+
}
98+
)
99+
)
100+
return template.render(input)
101+
73102
@property
74103
def prompt(self) -> str:
75104
return """
@@ -131,16 +160,7 @@ def prompt(self) -> str:
131160
* Generate the SRPM using `rpmbuild -bs` (ensure your .spec file and source files are correctly
132161
copied to the build environment as required by the command).
133162
134-
6. Commit the changes:
135-
* The title of the Git commit should be in the format "[DO NOT MERGE: AI EXPERIMENTS] Update to version {{ version }}"
136-
* Include the reference to Jira as "Resolves: <jira_issue>" for each issue in {{ jira_issues }}.
137-
* Commit just the specfile change.
138-
139-
7. Open a merge request:
140-
* Authenticate using `glab`
141-
* Push the commit to the fork.
142-
* Open a merge request against the upstream repository of the {{ package }} in {{ git_url }}
143-
with previously created commit.
163+
6. {{ rebase_git_steps }}
144164
145165
Report the status of the rebase operation including:
146166
- Whether the package was already up to date
@@ -161,7 +181,10 @@ async def main() -> None:
161181
and (branch := os.getenv("BRANCH", None))
162182
):
163183
input = InputSchema(
164-
package=package, version=version, jira_issue=jira_issue, dist_git_branch=branch
184+
package=package,
185+
version=version,
186+
jira_issue=jira_issue,
187+
dist_git_branch=branch,
165188
)
166189
output = await agent.run_with_schema(input)
167190
print(output.model_dump_json(indent=4))

beeai/agents/utils.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import os
2+
13
from contextlib import asynccontextmanager
24
from typing import AsyncGenerator, Callable
35

@@ -28,3 +30,49 @@ async def mcp_tools(
2830
if filter:
2931
tools = [t for t in tools if filter(t.name)]
3032
yield tools
33+
34+
35+
def get_git_finalization_steps(
36+
package: str,
37+
jira_issue: str,
38+
commit_title: str,
39+
files_to_commit: str,
40+
branch_name: str,
41+
git_user: str = "RHEL Packaging Agent",
42+
git_email: str = "[email protected]",
43+
git_url: str = "https://gitlab.com/redhat/centos-stream/rpms",
44+
dist_git_branch: str = "c9s",
45+
) -> str:
46+
"""Generate Git finalization steps with dry-run support"""
47+
dry_run = os.getenv("DRY_RUN", "False").lower() == "true"
48+
49+
# Common commit steps
50+
git_config_steps = f"""* Configure git user: `git config user.name "{git_user}"`
51+
* Configure git email: `git config user.email "{git_email}"`"""
52+
53+
commit_steps = f"""* Add files to commit: {files_to_commit}
54+
* Create commit with title: "{commit_title}"
55+
* Include JIRA reference: "Resolves: {jira_issue}" in commit body"""
56+
57+
if dry_run:
58+
return f"""
59+
**DRY RUN MODE**: Commit changes locally only
60+
61+
Commit the changes:
62+
{git_config_steps}
63+
{commit_steps}
64+
65+
**Important**: In dry-run mode, only commit locally. Do not push or create merge requests.
66+
"""
67+
else:
68+
return f"""
69+
Commit and push the changes:
70+
{git_config_steps}
71+
{commit_steps}
72+
* Push the branch `{branch_name}` to the fork
73+
74+
Open a merge request:
75+
* Authenticate using `glab`
76+
* Open a merge request against {git_url}/{package}
77+
* Target branch: {dist_git_branch}
78+
"""

beeai/compose.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ x-beeai-agent: &beeai-agent
1313
- REDIS_URL=redis://valkey:6379/0
1414
- COLLECTOR_ENDPOINT=http://phoenix:6006/v1/traces
1515
- MAX_RETRIES=3
16+
- DRY_RUN=${DRY_RUN:-false}
1617
env_file:
1718
- .secrets/beeai-agent.env
1819
volumes:

0 commit comments

Comments
 (0)