Skip to content

Commit 030f316

Browse files
committed
Agent working and completing token successfully
1 parent f3767f8 commit 030f316

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

packages/python/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export const python = {
9393
throw new Error(
9494
`${scriptPath} ${scriptArgs.join(" ")} exited with a non-zero code ${
9595
result.exitCode
96-
}:\n${result.stderr}`
96+
}:\n${result.stdout}\n${result.stderr}`
9797
);
9898
}
9999

references/d3-demo/src/trigger/d3Demo.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,25 @@ export const rowAgentRunner = schemaTask({
136136
jsonSchema: z.any().describe("The JSON schema of the result"),
137137
}),
138138
run: async ({ row, waitToken, jsonSchema }) => {
139-
const result = await python.runScript("./src/trigger/python/agent.py", []);
139+
const inputData = JSON.stringify({
140+
row,
141+
waitToken,
142+
jsonSchema,
143+
});
144+
145+
const result = await python.runScript("./src/trigger/python/agent.py", [inputData]);
140146

141147
logger.debug("row-agent-runner", {
142148
result,
143149
});
144150

145151
return {} as unknown as RowEnrichmentResult;
146152
},
153+
catchError: async ({ error }) => {
154+
logger.error("row-agent-runner", {
155+
error,
156+
});
157+
},
147158
});
148159

149160
export const enrichmentResultsEvaluator = schemaTask({

references/d3-demo/src/trigger/python/agent.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ class CompanyInfo(BaseModel):
3333
industry: str = Field(description="The industry of the company")
3434

3535
class SocialInfo(BaseModel):
36-
twitter: Optional[HttpUrl] = Field(None, description="The Twitter URL of the person")
37-
linkedin: Optional[HttpUrl] = Field(None, description="The LinkedIn URL of the person")
38-
facebook: Optional[HttpUrl] = Field(None, description="The Facebook URL of the person")
39-
instagram: Optional[HttpUrl] = Field(None, description="The Instagram URL of the person")
36+
twitter: Optional[str] = Field(None, description="The Twitter username of the person")
37+
linkedin: Optional[str] = Field(None, description="The LinkedIn username of the person")
38+
facebook: Optional[str] = Field(None, description="The Facebook username of the person")
39+
instagram: Optional[str] = Field(None, description="The Instagram username of the person")
4040

4141
class RowEnrichmentResult(BaseModel):
4242
basicInfo: BasicInfo
@@ -50,7 +50,7 @@ def notify_trigger(wait_token: WaitToken, result: dict):
5050
"Authorization": f"Bearer {wait_token.publicAccessToken}",
5151
"Content-Type": "application/json"
5252
}
53-
response = requests.post(url, json=result, headers=headers)
53+
response = requests.post(url, json={"data": result}, headers=headers)
5454
response.raise_for_status()
5555
return response.json()
5656

@@ -121,13 +121,17 @@ async def main(agent_input: AgentInput):
121121
"""
122122
)
123123

124+
enriched_data = result.final_output
125+
if isinstance(enriched_data, BaseModel):
126+
enriched_data = enriched_data.model_dump()
127+
124128
print("Final Output:")
125129
# Pretty print the final output
126-
print(json.dumps(result.final_output, indent=2))
130+
print(json.dumps(enriched_data, indent=2))
127131

128132
try:
129133
# Send the result back to Trigger.dev
130-
notify_trigger(agent_input.waitToken, result.final_output)
134+
notify_trigger(agent_input.waitToken, enriched_data)
131135

132136
print("Successfully enriched data and notified Trigger.dev")
133137

0 commit comments

Comments
 (0)