diff --git a/src/agent/nodes.py b/src/agent/nodes.py index e9f4fbe..34ee0bb 100644 --- a/src/agent/nodes.py +++ b/src/agent/nodes.py @@ -66,6 +66,16 @@ def _apply_changes(changes: list[dict], repo_dir: Path) -> None: logger.info("%s: %s", "Created" if action == "create" else "Modified", change["file"]) +def _get_metadata(state: AgentState, config: RunnableConfig) -> tuple[str, str]: + """Return (model_name, thread_id) from the current state and config.""" + settings: Settings = state["settings"] + # Get model for current prompt type if set, else default + prompt_type = state.get("prompt_type", "") + model_name = settings.llm.get_model(prompt_type) + thread_id = config.get("configurable", {}).get("thread_id", "unknown") + return model_name, thread_id + + async def _run_checks(repo_config, repo_dir: Path) -> CommandResult: """Run test suite and linter in parallel, returning combined result.""" coros = [] @@ -261,7 +271,11 @@ async def implement_post(state: AgentState, config: RunnableConfig) -> dict: impl = _json_parser.parse(last_message.content) _apply_changes(impl.get("changes", []), state["repo_dir"]) - state["git"].commit_all(impl.get("commit_message", "feat: implement task")) + + model, thread_id = _get_metadata(state, config) + commit_msg = impl.get("commit_message", "feat: implement task") + full_msg = f"{commit_msg}\n\nmodel: {model}\nthread_id: {thread_id}" + state["git"].commit_all(full_msg) return {"fix_history": []} @@ -326,8 +340,11 @@ async def fix_post(state: AgentState, config: RunnableConfig) -> dict: fix_data = _json_parser.parse(last_message.content) _apply_changes(fix_data.get("changes", []), state["repo_dir"]) + + model, thread_id = _get_metadata(state, config) commit_msg = fix_data.get("commit_message", f"fix: attempt {state['attempt']}") - state["git"].commit_all(commit_msg) + full_msg = f"{commit_msg}\n\nmodel: {model}\nthread_id: {thread_id}" + state["git"].commit_all(full_msg) history = list(state.get("fix_history", [])) history.append({ @@ -365,10 +382,14 @@ async def create_pr(state: AgentState, config: RunnableConfig) -> dict: # Template-based PR — skip the LLM call file_list = "\n".join(f"- `{f}`" for f in changed) title = f"Agent: {state['task'][:60]}" + + model, thread_id = _get_metadata(state, config) body = ( f"## Task\n{state['task']}\n\n" f"## Changes\n{file_list}\n\n" - f"```\n{git.diff_stat()}\n```" + f"```\n{git.diff_stat()}\n```\n\n" + f"model: {model}\n" + f"thread_id: {thread_id}" ) pr_url = git.create_pull_request( @@ -402,6 +423,9 @@ async def create_pr_post(state: AgentState, config: RunnableConfig) -> dict: body = pr.get("body", "Automated changes by coding agent.") body = f"## Task\n{state['task']}\n\n{body}" + model, thread_id = _get_metadata(state, config) + body += f"\n\nmodel: {model}\nthread_id: {thread_id}" + pr_url = state["git"].create_pull_request( branch=state["active_branch"], title=pr.get("title", f"Agent: {state['task'][:60]}"),