Skip to content

SWE-agent takes a GitHub issue and tries to automatically fix it, using your LM of choice. It can also be employed for offensive cybersecurity or competitive coding challenges. [NeurIPS 2024]

Fix: Inspector needs to handle new message format (#1094)

Kilian Lierete7d452e98102
diff --git a/.cursor/rules/project-overview.mdc b/.cursor/rules/project-overview.mdc
index d5bb010f..45a8925e 100644
--- a/.cursor/rules/project-overview.mdc
+++ b/.cursor/rules/project-overview.mdc
@@ -5,11 +5,13 @@ alwaysApply: true
---
# SWE-agent overview
-SWE-agent implements an AI agent that runs over github issues.
+SWE-agent implements an AI software engineering agent that uses language models to
+fix github issues.
Here's what you need to know about the project structure:
-- The main entry points to running are in the `sweagent/run`, in particular `run_single.py` and `run_batch.py`
+- The main entry points to running are in the `sweagent/run`, in particular `run_single.py` and `run_batch.py`, where the latter is used for benchmarking.
- The main class that governs agent behavior is `sweagent/agent/agents.py`
- The AI agent proposes actions that are executed in sandboxed docker containers
- At the beginning of an agent class, we initialize a `SWEEnv` class from `sweagent/environment/swe_env.py`. This class interfaces with the SWE-ReX project to interface with the sandboxed docker containers
-- Part of the SWE-agent project are tools in `tools/`. They are organized in bundles. These bundles are copied to the sandboxed container and made available in the $PATH variable.
\ No newline at end of file
+- Part of the SWE-agent project are tools in `tools/`. They are organized in bundles. These bundles are copied to the sandboxed container and made available in the $PATH variable.
+- In addition we provide two "inspectors" that allow to inspect trajectories (the output files of agents), `inspector_cli.py` provides a command line interface and `sweagent/inspector/server.py` a web interface.
\ No newline at end of file
diff --git a/sweagent/inspector/fileViewer.js b/sweagent/inspector/fileViewer.js
index 78825ce8..ce1fc4f8 100644
--- a/sweagent/inspector/fileViewer.js
+++ b/sweagent/inspector/fileViewer.js
@@ -47,12 +47,35 @@ function createTrajectoryItem(item, index) {
.replace(/'/g, "'");
};
+ const getMessageContent = (msg) => {
+ if (!msg.content) {
+ return "";
+ }
+
+ // Handle content as a string
+ if (typeof msg.content === "string") {
+ return msg.content;
+ }
+
+ // Handle content as an array with a dictionary containing 'text' key
+ if (
+ Array.isArray(msg.content) &&
+ msg.content.length > 0 &&
+ msg.content[0].text
+ ) {
+ return msg.content[0].text;
+ }
+
+ // Fallback to stringifying the content
+ return JSON.stringify(msg.content);
+ };
+
const messagesContent = hasMessages
? item.messages
.map((msg, msgIndex) => {
let content = `----Item ${msgIndex}-----\n`;
content += `role: ${msg.role}\n`;
- content += `content: |\n${escapeHtml(msg.content)}\n`;
+ content += `content: |\n${escapeHtml(getMessageContent(msg))}\n`;
if (msg.tool_calls && msg.tool_calls.length > 0) {
msg.tool_calls.forEach((tool, idx) => {