Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions src/codegen/agents/code_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ def __init__(
model_name: str = "claude-3-7-sonnet-latest",
memory: bool = True,
tools: Optional[list[BaseTool]] = None,
run_id: Optional[str] = None,
instance_id: Optional[str] = None,
difficulty: Optional[int] = None,
tags: Optional[list[str]] = [],
metadata: Optional[dict] = {},
**kwargs,
):
"""Initialize a CodeAgent.
Expand All @@ -46,6 +45,8 @@ def __init__(
model_name: Name of the model to use
memory: Whether to let LLM keep track of the conversation history
tools: Additional tools to use
tags: Tags to add to the agent trace. Must be of the same type.
metadata: Metadata to use for the agent. Must be a dictionary.
**kwargs: Additional LLM configuration options. Supported options:
- temperature: Temperature parameter (0-1)
- top_p: Top-p sampling parameter (0-1)
Expand All @@ -63,14 +64,21 @@ def __init__(
)
self.model_name = model_name
self.langsmith_client = Client()
self.run_id = run_id
self.instance_id = instance_id
self.difficulty = difficulty

# Get project name from environment variable or use a default
self.project_name = os.environ.get("LANGCHAIN_PROJECT", "RELACE")
print(f"Using LangSmith project: {self.project_name}")

# Initialize tags for agent trace
self.tags = [*tags, self.model_name]

# Initialize metadata for agent trace
self.metadata = {
"project": self.project_name,
"model": self.model_name,
**metadata,
}

def run(self, prompt: str, thread_id: Optional[str] = None) -> str:
"""Run the agent with a prompt.

Expand All @@ -95,9 +103,8 @@ def run(self, prompt: str, thread_id: Optional[str] = None) -> str:
# this message has a reducer which appends the current message to the existing history
# see more https://langchain-ai.github.io/langgraph/concepts/low_level/#reducers
input = {"messages": [("user", prompt)]}
tags, metadata = self.get_tags_metadata()

config = RunnableConfig(configurable={"thread_id": thread_id}, tags=tags, metadata=metadata, recursion_limit=100)
config = RunnableConfig(configurable={"thread_id": thread_id}, tags=self.tags, metadata=self.metadata, recursion_limit=100)
# we stream the steps instead of invoke because it allows us to access intermediate nodes
stream = self.agent.stream(input, config=config, stream_mode="values")

Expand Down
4 changes: 3 additions & 1 deletion src/codegen/extensions/swebench/harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ def run_agent_on_entry(entry: SweBenchExample, model: str, codebase: Codebase |
)
codebase = Codebase.from_repo(repo_full_name=entry.repo, commit=base_commit, language="python", config=config) # check out the repo

agent = CodeAgent(codebase=codebase, run_id=run_id, instance_id=instance_id, model_name=model, difficulty=entry.difficulty)
metadata = {"run_id": run_id, "instance_id": instance_id, "difficulty": f"difficulty_{entry.difficulty}"}
tags = [str(value) for value in metadata.values()]
agent = CodeAgent(codebase=codebase, tags=tags, metadata=metadata)

pprint.pprint(instance_id)
pprint.pprint(gold_files)
Expand Down
Loading