Skip to content

Commit 4359d64

Browse files
Asaif AliAsaif Ali
authored andcommitted
Fixing the conversion and post migration gateway pipeline
1 parent bf1f28a commit 4359d64

5 files changed

Lines changed: 368 additions & 153 deletions

File tree

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
1-
from agno.agent import Agent
2-
from app.infrastructure.agents_backend.model_provider import model
3-
4-
conversion_agent = Agent(
5-
model=model,
6-
markdown=False,
7-
debug_mode=True,
8-
retries=1,
9-
instructions="""
10-
You are a code migration agent. You will be given context for a source to target symbol/code conversion.
11-
Context will include:
12-
- Source code for the source symbol
13-
- Code from any dependent plans/symbols (if any)
14-
- Similar code snippets that were already migrated (if any)
15-
Important
16-
- Using the context, generate new code in target laguage in text format & return it.
17-
- If similar already migrated code snippets are given, use them as coding guidelines/format references to generate new code. We must follow existing coding standards.
18-
19-
Rules:
20-
- Output ONLY raw executable code. No markdown, no fences, no comments outside the code.
21-
- No explanations, no notes, no "Note:" lines, no section headers.
22-
- No import statements unless they are strictly required by the converted symbol.
23-
- Follow the coding style of any similar snippets provided.
24-
- Do not add example usage blocks or standalone invocation calls at the end.
25-
"""
26-
)
1+
from agno.agent import Agent
2+
from app.infrastructure.agents_backend.model_provider import model
3+
4+
conversion_agent = Agent(
5+
model=model,
6+
markdown=False,
7+
debug_mode=True,
8+
retries=1,
9+
instructions="""
10+
You are a code migration agent. You will be given context for a source to target symbol/code conversion.
11+
Context will include:
12+
- Source code for the source symbol
13+
- Code from any dependent plans/symbols (if any)
14+
- Similar code snippets that were already migrated (if any)
15+
Important
16+
- Using the context, generate new code in target laguage in text format & return it.
17+
- If similar already migrated code snippets are given, use them as coding guidelines/format references to generate new code. We must follow existing coding standards.
18+
19+
Rules:
20+
- Output ONLY raw executable code. No markdown, no fences, no comments outside the code.
21+
- No explanations, no notes, no "Note:" lines, no section headers.
22+
- No import statements unless they are strictly required by the converted symbol.
23+
- Follow the coding style of any similar snippets provided.
24+
- Do not add example usage blocks or standalone invocation calls at the end.
25+
- Preserve executable entry-point semantics from the source module. If the source
26+
module executes a translated symbol at runtime, the target must preserve that
27+
behavior using the idiomatic entry-point convention of the target language.
28+
Do not add an entry point when the source is clearly a reusable library/module.
29+
"""
30+
)

agent_service/app/application/agents/conversion/conversion_tools.py

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import app.application.agents.knowledge_base.knowledge_base_agent as kb
2020
from app.application.agents.conversion.conversion_agent import conversion_agent
2121
from app.infrastructure.utils.Agent_helpers.conversion_helper import _conversion_event_helper
22+
from app.infrastructure.utils.language_adapters import adapter_for_file, get_adapter, ExecutionContract
2223
from app.domain.interfaces.i_folder_structure_goals_repository import (
2324
IFolderStructureGoalsRepository,
2425
)
@@ -53,11 +54,6 @@
5354
logging.basicConfig(level=logging.INFO)
5455
_conversion_step_start_sent: set = set()
5556

56-
def _ensure_qdrant_kb_ready() -> None:
57-
if kb.source_knowledge is None or kb.target_knowledge is None:
58-
kb.init_knowledge_bases()
59-
60-
6157
_folder_goals_repo: Optional[IFolderStructureGoalsRepository] = None
6258
_json_artifact_repo: Optional[IJsonArtifactRepository] = None
6359
__all__=[
@@ -257,6 +253,29 @@ def generate_new_code(step_input: StepInput) -> dict:
257253
f"Architecture : {runtime_tech['architecture'] or 'Unknown'}\n"
258254
)
259255

256+
# Resolve executable behavior through the language adapter registry. The
257+
# conversion engine never branches on source/target language itself.
258+
execution_contract = None
259+
entrypoint_context = ""
260+
try:
261+
source_adapter = adapter_for_file(Path(str(source_file_path)))
262+
if source_adapter is not None:
263+
execution_contract = source_adapter.detect_execution_contract(
264+
Path(str(source_file_path)), target_symbol_name
265+
)
266+
if execution_contract and execution_contract.executable:
267+
target_adapter = get_adapter(runtime_tech.get("language", ""))
268+
target_name = target_adapter.display_name if target_adapter else runtime_tech.get("language", "target")
269+
entrypoint_context = (
270+
"SOURCE EXECUTION CONTRACT: the source module executes the translated "
271+
f"symbol '{execution_contract.entry_symbol}'. Preserve that runtime behavior "
272+
f"using the idiomatic executable entry-point convention of the target language ({target_name}). "
273+
"Do not add an entry point when the source is clearly a reusable library/module."
274+
)
275+
except Exception:
276+
execution_contract = None
277+
entrypoint_context = ""
278+
260279
try:
261280
user = current_user.get()
262281
migration_name = migration_name_ctx.get(None)
@@ -295,6 +314,7 @@ def generate_new_code(step_input: StepInput) -> dict:
295314
EXISTING DEPENDENCIES TO USE: {deps_content}
296315
EXISTING SIMILAR CODE SNIPPETS: []
297316
PRE-APPROVED LIBRARIES (from dependency file — use these for imports, do not invent others): {file_deps_content}
317+
{entrypoint_context}
298318
When writing the target code, make sure to correctly use the exisisting dependencies alongwith their correct import paths/naming conventions.
299319
Return just the final raw code, no extra explanations & no extra formatting such as ```python, ```, etc.
300320
"""
@@ -306,6 +326,12 @@ def generate_new_code(step_input: StepInput) -> dict:
306326
if target_code.endswith("```"):
307327
target_code = target_code.rsplit("\n", 1)[0] if "\n" in target_code else target_code[:-3]
308328

329+
target_adapter = get_adapter(runtime_tech.get("language", ""))
330+
if target_adapter is not None and execution_contract is not None:
331+
target_code = target_adapter.ensure_entrypoint(
332+
target_code, execution_contract, target_symbol_name
333+
)
334+
309335
track_tokens(resp, source="conversion:symbol_convert")
310336

311337
try:

0 commit comments

Comments
 (0)