Skip to content

Commit c1b20c9

Browse files
authored
Revert "feature: agent can now take in images in the form of urls (#884)"
This reverts commit e77b1aa.
1 parent fe98b92 commit c1b20c9

File tree

2 files changed

+16
-25
lines changed

2 files changed

+16
-25
lines changed

src/codegen/agents/code_agent.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,11 @@ def __init__(
106106
**metadata,
107107
}
108108

109-
def run(self, prompt: str, image_urls: Optional[list[str]] = None) -> str:
110-
"""Run the agent with a prompt and optional images.
109+
def run(self, prompt: str) -> str:
110+
"""Run the agent with a prompt.
111111
112112
Args:
113113
prompt: The prompt to run
114-
image_urls: Optional list of base64-encoded image strings. Example: ["data:image/png;base64,<base64_str>"]
115114
thread_id: Optional thread ID for message history
116115
117116
Returns:
@@ -125,15 +124,14 @@ def run(self, prompt: str, image_urls: Optional[list[str]] = None) -> str:
125124
"recursion_limit": 100,
126125
}
127126

128-
# Prepare content with prompt and images if provided
129-
content = [{"type": "text", "text": prompt}]
130-
if image_urls:
131-
content += [{"type": "image_url", "image_url": {"url": image_url}} for image_url in image_urls]
127+
# this message has a reducer which appends the current message to the existing history
128+
# see more https://langchain-ai.github.io/langgraph/concepts/low_level/#reducers
129+
input = {"query": prompt}
132130

133131
config = RunnableConfig(configurable={"thread_id": self.thread_id}, tags=self.tags, metadata=self.metadata, recursion_limit=200)
134132
# we stream the steps instead of invoke because it allows us to access intermediate nodes
135133

136-
stream = self.agent.stream({"messages": [HumanMessage(content=content)]}, config=config, stream_mode="values")
134+
stream = self.agent.stream(input, config=config, stream_mode="values")
137135

138136
_tracer = MessageStreamTracer(logger=self.logger)
139137

@@ -145,7 +143,7 @@ def run(self, prompt: str, image_urls: Optional[list[str]] = None) -> str:
145143

146144
for s in traced_stream:
147145
if len(s["messages"]) == 0 or isinstance(s["messages"][-1], HumanMessage):
148-
message = HumanMessage(content=content)
146+
message = HumanMessage(content=prompt)
149147
else:
150148
message = s["messages"][-1]
151149

src/codegen/agents/scratch.ipynb

+9-16
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
"metadata": {},
77
"outputs": [],
88
"source": [
9-
"from codegen.agents.code_agent import CodeAgent"
9+
"from codegen.agents.code_agent import CodeAgent\n",
10+
"\n",
11+
"\n",
12+
"CodeAgent"
1013
]
1114
},
1215
{
@@ -43,16 +46,8 @@
4346
"metadata": {},
4447
"outputs": [],
4548
"source": [
46-
"image = \"\""
47-
]
48-
},
49-
{
50-
"cell_type": "code",
51-
"execution_count": null,
52-
"metadata": {},
53-
"outputs": [],
54-
"source": [
55-
"agent = CodeAgent(codebase)"
49+
"agent = CodeAgent(codebase)\n",
50+
"agent.run(\"What is the main character's name? also show the source code where you find the answer\", logger=ConsoleLogger())"
5651
]
5752
},
5853
{
@@ -61,17 +56,15 @@
6156
"metadata": {},
6257
"outputs": [],
6358
"source": [
64-
"agent.run(\"Tell me about the images you see.\", image_urls=[f\"data:image/png;base64,{image}\", f\"data:image/png;base64,{image}\"])"
59+
"agent.run(\"What is the main character's name?\")"
6560
]
6661
},
6762
{
6863
"cell_type": "code",
6964
"execution_count": null,
7065
"metadata": {},
7166
"outputs": [],
72-
"source": [
73-
"agent.run(\"What is the main character's name?\")"
74-
]
67+
"source": []
7568
}
7669
],
7770
"metadata": {
@@ -90,7 +83,7 @@
9083
"name": "python",
9184
"nbconvert_exporter": "python",
9285
"pygments_lexer": "ipython3",
93-
"version": "3.13.1"
86+
"version": "3.13.0"
9487
}
9588
},
9689
"nbformat": 4,

0 commit comments

Comments
 (0)