AI Real State Agent avatar
AI Real State Agent

Deprecated

Pricing

Pay per event

Go to Store
AI Real State Agent

AI Real State Agent

Deprecated

Developed by

Max F. Findel

Max F. Findel

Maintained by Community

This AI agent helps users discover their ideal home effortlessly. Simply input preferences like budget, number of bedrooms, bathrooms, pet-friendliness, and the AI does the rest. It analyzes listings, filters properties based on your criteria and delivers tailored recommendations.

0.0 (0)

Pricing

Pay per event

0

Total users

2

Monthly users

2

Runs succeeded

>99%

Last modified

a month ago

.dockerignore

# configurations
.idea
.vscode
# crawlee and apify storage folders
apify_storage
crawlee_storage
storage
# installed files
node_modules
# git folder
.git
# dist folder
dist

.editorconfig

root = true
[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
end_of_line = lf

.env.example

APIFY_TOKEN="apify_api_1234"
ACTOR_TEST_PAY_PER_EVENT=true
LANGSMITH_TRACING=false
LANGSMITH_ENDPOINT="https://api.smith.langchain.com"
LANGSMITH_API_KEY="lsv2_pt_1234"
LANGSMITH_PROJECT="langsmith-cool-project-name"
OPENAI_API_KEY="sk-proj-1234"

.eslintrc

{
"root": false,
"env": {
"browser": true,
"es2020": true,
"node": true
},
"extends": [
"@apify/eslint-config-ts"
],
"parserOptions": {
"project": "./tsconfig.json",
"ecmaVersion": 2020
},
"ignorePatterns": [
"node_modules",
"dist",
"**/*.d.ts"
],
"rules": {
"indent": ["error", 2],
"comma-dangle": ["off", 0],
"prefer-rest-params": ["off", 0],
"max-len": ["error", { "ignoreComments": true, "ignoreStrings": true, "ignoreUrls": true, "ignoreTemplateLiterals": true }]
}
}

.gitignore

# This file tells Git which files shouldn't be added to source control
.idea
.vscode
storage
apify_storage
crawlee_storage
node_modules
dist
tsconfig.tsbuildinfo
.env
# Added by Apify CLI
.venv

.gitpod.yml

image: gitpod/workspace-base:latest
tasks:
- name: main
init: >
nvm use lts/jod &&
npm install -g npm@11 &&
npm install -g eslint@^8.50.0 &&
npm install -g apify-cli
command: echo "Login to apify to get an API Key, export your APIFY_TOKEN, create an INPUT.json file and run npm start!"
- name: config
before: >
(([[ ! -z $GITCONFIG ]] &&
echo $GITCONFIG | base64 -d > ~/.gitconfig &&
chmod 644 ~/.gitconfig) || unset GITCONFIG) &&
(([[ ! -z $GNUPG_1 ]] &&
rm -rf ~/.gnupg &&
cd / &&
echo $GNUPG_1$GNUPG_2 | base64 -d | tar --no-same-owner -xzf -) || unset GNUPG_1)
command: echo "Ready! Start a new terminal session in order to use GPG." && exit

LICENSE

Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

environment.d.ts

1declare global {
2 namespace NodeJS {
3 interface ProcessEnv {
4 APIFY_TOKEN: string;
5 LANGSMITH_TRACING: string;
6 LANGSMITH_ENDPOINT: string;
7 LANGSMITH_API_KEY: string;
8 LANGSMITH_PROJECT: string;
9 OPENAI_API_KEY: string;
10 ZIP_API_KEY: string;
11 NODE_ENV: 'development' | 'production';
12 }
13 }
14}
15
16// If this file has no import/export statements (i.e. is a script)
17// convert it into a module by adding an empty export statement.
18export {}

package.json

{
"name": "ai-real-state-agent",
"version": "0.0.1",
"type": "module",
"description": "This is an example of a Crawlee project.",
"engines": {
"node": ">=22.0.0"
},
"dependencies": {
"@langchain/core": "^0.3.42",
"@langchain/langgraph": "^0.2.54",
"@langchain/openai": "^0.4.4",
"apify": "^3.3.2",
"dotenv": "^16.4.7",
"langchain": "^0.3.19",
"zod": "^3.24.2"
},
"devDependencies": {
"@apify/eslint-config-ts": "^0.3.0",
"@apify/tsconfig": "^0.1.0",
"@eslint/js": "^9.21.0",
"@types/node": "^22.0.0",
"@typescript-eslint/eslint-plugin": "^7.18.0",
"@typescript-eslint/parser": "^7.18.0",
"eslint": "^8.57.1",
"globals": "^16.0.0",
"tsx": "^4.4.0",
"typescript": "~5.5.0",
"typescript-eslint": "^8.26.0"
},
"scripts": {
"start": "npm run start:dev",
"start:prod": "node dist/main.js",
"start:dev": "tsx src/main.ts",
"build": "tsc",
"lint": "eslint src",
"test": "echo \"Error: oops, the actor has no tests yet, sad!\" && exit 1"
},
"author": "It's not you it's me",
"license": "ISC"
}

tsconfig.json

{
"extends": "@apify/tsconfig",
"compilerOptions": {
"module": "NodeNext",
"moduleResolution": "NodeNext",
"target": "ES2022",
"outDir": "dist",
"noUnusedLocals": false,
"skipLibCheck": true,
"lib": ["DOM"],
},
"include": [
"./*.d.ts",
"./src/**/*",
]
}

.actor/Dockerfile

# Specify the base Docker image. You can read more about
# the available images at https://docs.apify.com/sdk/js/docs/guides/docker-images
# You can also use any other image from Docker Hub.
FROM apify/actor-node:22 AS builder
# Check preinstalled packages
RUN npm ls crawlee apify puppeteer playwright
# Copy just package.json and package-lock.json
# to speed up the build using Docker layer cache.
COPY package*.json ./
# Install all dependencies. Don't audit to speed up the installation.
RUN npm install --include=dev --audit=false
# Next, copy the source files using the user set
# in the base image.
COPY . ./
# Install all dependencies and build the project.
# Don't audit to speed up the installation.
RUN npm run build
# Create final image
FROM apify/actor-node:22
# Check preinstalled packages
RUN npm ls crawlee apify puppeteer playwright
# Copy just package.json and package-lock.json
# to speed up the build using Docker layer cache.
COPY package*.json ./
# Install NPM packages, skip optional and development dependencies to
# keep the image small. Avoid logging too much and print the dependency
# tree for debugging
RUN npm --quiet set progress=false \
&& npm install --omit=dev --omit=optional \
&& echo "Installed NPM packages:" \
&& (npm list --omit=dev --all || true) \
&& echo "Node.js version:" \
&& node --version \
&& echo "NPM version:" \
&& npm --version \
&& rm -r ~/.npm
# Copy built JS files from builder image
COPY --from=builder /usr/src/app/dist ./dist
# Next, copy the remaining files and directories with the source code.
# Since we do this after NPM install, quick build will be really fast
# for most source file changes.
COPY . ./
# Create and run as a non-root user.
RUN adduser -h /home/apify -D apify && \
chown -R apify:apify ./
USER apify
# Run the image.
CMD npm run start:prod --silent

.actor/actor.json

{
"actorSpecification": 1,
"name": "ai-real-state-agent",
"version": "0.1",
"buildTag": "latest",
"title": "AI Real State Agent",
"description": "AI agent that uses a multi-agent approach to find you the best home recommendations using a natural language prompt.",
"meta": {
"templateId": "ts-empty"
},
"environmentVariables": {
"OPENAI_API_KEY": "@defaultOpenaiApiKey",
"APIFY_TOKEN": "@defaultApifyToken"
},
"dockerfile": "./Dockerfile",
"input": "./input_schema.json",
"storages": {
"dataset": "./dataset_schema.json"
}
}

.actor/dataset_schema.json

{
"actorSpecification": 1,
"views": {
"overview": {
"title": "Overview",
"transformation": {
"fields": ["actorName", "response"]
},
"display": {
"component": "table",
"properties": {
"actorName": {
"label": "Actor name",
"format": "text"
},
"response": {
"label": "Actor evaluation",
"format": "text"
}
}
}
}
}
}

.actor/input_schema.json

{
"title": "Web Automation Agent",
"type": "object",
"schemaVersion": 1,
"properties": {
"instructions": {
"title": "Instructions for the AI Real State Agent",
"type": "string",
"description": "Ask the agent for help to find the perfect home.",
"editor": "textarea",
"prefill": "I want to buy a house with a pool in Miami for less than 1 million dollars. Can you help me?"
},
"openaiApiKey": {
"title": "OpenAI API key",
"type": "string",
"description": "The API key for accessing OpenAI. You can get it from <a href='https://platform.openai.com/account/api-keys' target='_blank' rel='noopener'>OpenAI platform</a>.",
"editor": "textfield",
"isSecret": true
},
"model": {
"title": "GPT model",
"type": "string",
"description": "Select a GPT model. See <a href='https://platform.openai.com/docs/models/overview' target='_blank' rel='noopener'>models overview</a>. Keep in mind that each model has different pricing and features.",
"editor": "select",
"default": "gpt-4o-mini",
"prefill": "gpt-4o-mini",
"enum": ["gpt-4o", "gpt-4o-mini", "gpt-3.5-turbo", "o3-mini", "o1-mini"]
}
},
"required": ["instructions", "model"]
}

.actor/pay_per_event.json

{
"actor-start-gb": {
"eventTitle": "Actor start per 1 GB",
"eventDescription": "Flat fee for starting an Actor run for each 1 GB of memory.",
"eventPriceUsd": 0.01
},
"openai-1000-tokens-gpt-4o": {
"eventTitle": "Price per 1000 OpenAI tokens for gpt-4o",
"eventDescription": "Flat fee for every 1000 tokens (input/output) used with gpt-4o.",
"eventPriceUsd": 0.01
},
"openai-1000-tokens-gpt-4o-mini": {
"eventTitle": "Price per 1000 OpenAI tokens for gpt-4o-mini",
"eventDescription": "Flat fee for every 1000 tokens (input/output) used with gpt-4o-mini.",
"eventPriceUsd": 0.0006
},
"openai-1000-tokens-gpt-3.5-turbo": {
"eventTitle": "Price per 1000 OpenAI tokens for gpt-3.5-turbo",
"eventDescription": "Flat fee for every 1000 tokens (input/output) used with gpt-3.5-turbo.",
"eventPriceUsd": 0.0015
},
"openai-1000-tokens-gpt-o3-mini": {
"eventTitle": "Price per 1000 OpenAI tokens for gpt-o3-mini",
"eventDescription": "Flat fee for every 1000 tokens (input/output) used with gpt-o3-mini.",
"eventPriceUsd": 0.0044
},
"openai-1000-tokens-gpt-o1-mini": {
"eventTitle": "Price per 1000 OpenAI tokens for gpt-o1-mini",
"eventDescription": "Flat fee for every 1000 tokens (input/output) used with gpt-o1-mini.",
"eventPriceUsd": 0.0044
},
"duck-duck-go": {
"eventTitle": "Price per Duck Duck Go search",
"eventDescription": "Flat fee for every Duck Duck Go search.",
"eventPriceUsd": 0.01
},
"website-scraper':": {
"eventTitle": "Price per web page scraped",
"eventDescription": "Flat fee for every web page scraped.",
"eventPriceUsd": 0.01
},
"zillow-search':": {
"eventTitle": "Price per Zillow search result",
"eventDescription": "Flat fee for every result when searching Zillow.",
"eventPriceUsd": 0.002
},
"zip-code-search": {
"eventTitle": "Price per Zip Code search",
"eventDescription": "Flat fee for every Zip Code search.",
"eventPriceUsd": 0.01
}
}

src/main.ts

1import dotenv from 'dotenv';
2import { Actor, ApifyClient, log } from 'apify';
3import { StateGraph, StateGraphArgs, START, END } from '@langchain/langgraph';
4import LocationExpertAgent from './agents/location_expert.js';
5import ResearcherAgent from './agents/researcher.js';
6import { chargeForActorStart } from './utils/ppe_handler.js';
7
8// if available, .env variables are loaded
9dotenv.config();
10
11/**
12 * Actor input schema
13 */
14type Input = {
15 instructions: string;
16 modelName?: string;
17 openaiApiKey?: string;
18 debug?: boolean;
19}
20
21/**
22 * Actor initialization code
23*/
24await Actor.init();
25await chargeForActorStart();
26
27const userToken = Actor.getEnv().token;
28if (!userToken) {
29 throw new Error('User token is required. Use `apify login` and export your secret as APIFY_TOKEN.');
30}
31
32// Handle and validate input
33const {
34 instructions,
35 modelName = 'gpt-4o-mini',
36 openaiApiKey,
37 debug,
38} = await Actor.getInput() as Input;
39if (debug) {
40 log.setLevel(log.LEVELS.DEBUG);
41} else {
42 log.setLevel(log.LEVELS.INFO);
43}
44// if available, the Actor uses the user's openaiApiKey. Otherwise it charges for use.
45const tokenCostActive = (openaiApiKey ?? '').length === 0;
46if (tokenCostActive) {
47 log.info("No openaiApiKey was detected. You'll be charged for token usage.");
48} else {
49 log.info("Env openaiApiKey detected. You won't be charged for token usage.");
50}
51if (!instructions) {
52 throw new Error('Instructions are required. Create an INPUT.json file in the `storage/key_value_stores/default` folder and add the respective keys.');
53}
54
55// Apify is used to call tools and manage datasets
56const apifyClient = new ApifyClient({
57 token: userToken,
58});
59
60/**
61 * LangGraph StateGraph schema
62 */
63type StateSchema = {
64 instructions: string;
65 bestLocations: string;
66 recommendations: string[];
67 output: string;
68}
69
70const graphState: StateGraphArgs<StateSchema>['channels'] = {
71 instructions: {
72 value: (x?: string, y?: string) => y ?? x ?? '',
73 default: () => instructions,
74 },
75 bestLocations: {
76 value: (x?: string, y?: string) => y ?? x ?? '',
77 default: () => '',
78 },
79 recommendations: {
80 value: (x?: string[], y?: string[]) => y ?? x ?? [],
81 default: () => [],
82 },
83 output: {
84 value: (x?: string, y?: string) => y ?? x ?? '',
85 default: () => '',
86 },
87};
88
89async function locationExpert(state: StateSchema) {
90 // The researcher agent gets initialized
91 const locationExpertAgent = new LocationExpertAgent({
92 apifyClient,
93 modelName,
94 openaiApiKey: openaiApiKey ?? process.env.OPENAI_API_KEY,
95 log,
96 });
97 const { agentExecutor, costHandler } = locationExpertAgent;
98 const response = await agentExecutor.invoke({ input: state.instructions });
99 log.debug(`locationExpert 🤖 : ${response.output}`);
100 await costHandler.logOrChargeForTokens(modelName, tokenCostActive);
101 return { bestLocations: response.output };
102}
103
104async function researcher(state: StateSchema) {
105 // The researcher agent gets initialized
106 const researcherAgent = new ResearcherAgent({
107 apifyClient,
108 modelName,
109 openaiApiKey: openaiApiKey ?? process.env.OPENAI_API_KEY,
110 log,
111 });
112 const { agentExecutor, costHandler } = researcherAgent;
113 const input = 'The user asked sent this exact query:\n\n'
114 + `'${state.instructions}'\n\n`
115 + 'You asked someone for help to get the best locations in that city and state. '
116 + 'The answer you received was this:\n\n'
117 + `'${state.bestLocations}'\n\n`
118 + 'Please answer the user accordingly.';
119 const response = await agentExecutor.invoke({ input });
120 await costHandler.logOrChargeForTokens(modelName, tokenCostActive);
121 return { output: response.output };
122}
123
124const graph = new StateGraph({ channels: graphState })
125 .addNode('location_expert', locationExpert)
126 .addNode('researcher', researcher)
127 .addEdge(START, 'location_expert')
128 .addEdge('location_expert', 'researcher')
129 .addEdge('researcher', END);
130
131const runnable = graph.compile();
132const response = await runnable.invoke(
133 { input: instructions },
134 { configurable: { thread_id: 42 } }, // this line shows that the agent can be thread-aware
135);
136
137log.debug(`Agent 🤖 : ${response.output}`);
138
139await Actor.pushData({
140 actorName: 'AI Real State Agent',
141 response: response.output,
142});
143
144await Actor.exit();

src/agents/location_expert.ts

1import { Log, ApifyClient } from 'apify';
2import { ChatPromptTemplate } from '@langchain/core/prompts';
3import { createToolCallingAgent, AgentExecutor } from 'langchain/agents';
4import { ChatOpenAI } from '@langchain/openai';
5import { StructuredToolInterface } from '@langchain/core/tools';
6import DuckDuckGo from '../tools/duck_duck_go.js';
7import WebsiteScraper from '../tools/website_scraper.js';
8// import ZipCodeSearch from '../tools/zip_code_search.js';
9import { CostHandler } from '../utils/cost_handler.js';
10
11/**
12 * Interface for parameters required by LocationExpertAgent class.
13 */
14export interface LocationExpertAgentParams {
15 apifyClient: ApifyClient,
16 modelName: string,
17 openaiApiKey: string,
18 log: Log | Console;
19}
20
21/**
22 * Tool that uses the MagicTool function. This is an example function to use as template.
23 */
24export class LocationExpertAgent {
25 protected log: Log | Console;
26 protected apifyClient: ApifyClient;
27 public agentExecutor: AgentExecutor;
28 public costHandler: CostHandler;
29
30 constructor(fields?: LocationExpertAgentParams) {
31 this.log = fields?.log ?? console;
32 this.apifyClient = fields?.apifyClient ?? new ApifyClient();
33 this.costHandler = new CostHandler(fields?.modelName ?? 'gpt-4o-mini', this.log);
34 const llm = new ChatOpenAI({
35 model: fields?.modelName,
36 apiKey: fields?.openaiApiKey,
37 temperature: 0,
38 callbacks: [
39 this.costHandler,
40 ],
41 });
42 const tools = this.buildTools(this.apifyClient, this.log);
43 const prompt = this.buildPrompt();
44 const agent = createToolCallingAgent({
45 llm,
46 tools,
47 prompt,
48 });
49 this.agentExecutor = new AgentExecutor({
50 agent,
51 tools,
52 verbose: false,
53 maxIterations: 5,
54 });
55 }
56
57 protected buildTools(
58 apifyClient: ApifyClient, log: Log | Console
59 ): StructuredToolInterface[] {
60 // Tools are initialized to be passed to the agent
61 const duckDuckGo = new DuckDuckGo({ apifyClient, log });
62 const websiteScraper = new WebsiteScraper({ apifyClient, log });
63 // const zipCodeSearch = new ZipCodeSearch({ log });
64 return [
65 duckDuckGo,
66 websiteScraper,
67 // zipCodeSearch,
68 ];
69 }
70
71 protected buildPrompt(): ChatPromptTemplate {
72 return ChatPromptTemplate.fromMessages([
73 ['system',
74 'You are a experienced real state agent that wants to help the user to find the perfect home. '
75 + "You will stick to the following steps, but notify the user if you get stuck or can't continue. "
76 + 'Step 1. The user will ask you for advice regarding a specific city in the US. '
77 + 'If the user does not provide a state (like CA or NY), try to guess to which state a city belongs to. '
78 + 'If the user does not provide a state, try to guess to which state a city belongs to. '
79 + 'If from the input you cannot get a city and a state or you think that the city is not in US territory, '
80 + 'end the conversation and help the user with the input. '
81 + "Make sure to convert the state to a two-letter ISO standard. For example, if the user says 'New York', store it as 'NY' before using it. \n"
82 // 2. Fetch best Zip Codes to live using DuckDuckGo
83 + 'Step 2. With the city and state in hand, use DuckDuckGo replacing the following query: '
84 + "'best places to live near [city], [state] by zip code site:niche.com'. "
85 + 'If there the results, use a website scraper on the URLs you think will show you this information. '
86 + 'Iterate until you find the best 3 Zip Codes near the selected city. '
87 + "For best performance when using the website scraper, you can use method='getBestZipCodesToLive' and output=null'. "
88 + 'Instead of answering the original question, just return the top 3 Zip Codes and explain to the user why you selected those Zip Codes. \n'
89 ],
90 ['placeholder', '{chat_history}'],
91 ['human', '{input}'],
92 ['placeholder', '{agent_scratchpad}'],
93 ]);
94 }
95}
96
97export default LocationExpertAgent;

src/agents/researcher.ts

1import { Log, ApifyClient } from 'apify';
2import { ChatPromptTemplate } from '@langchain/core/prompts';
3import { createToolCallingAgent, AgentExecutor } from 'langchain/agents';
4import { ChatOpenAI } from '@langchain/openai';
5import { StructuredToolInterface } from '@langchain/core/tools';
6import ZillowSearch from '../tools/zillow_search.js';
7import { CostHandler } from '../utils/cost_handler.js';
8
9/**
10 * Interface for parameters required by ResearcherAgent class.
11 */
12export interface ResearcherAgentParams {
13 apifyClient: ApifyClient,
14 modelName: string,
15 openaiApiKey: string,
16 log: Log | Console;
17}
18
19/**
20 * Tool that uses the MagicTool function. This is an example function to use as template.
21 */
22export class ResearcherAgent {
23 protected log: Log | Console;
24 protected apifyClient: ApifyClient;
25 public agentExecutor: AgentExecutor;
26 public costHandler: CostHandler;
27
28 constructor(fields?: ResearcherAgentParams) {
29 this.log = fields?.log ?? console;
30 this.apifyClient = fields?.apifyClient ?? new ApifyClient();
31 this.costHandler = new CostHandler(fields?.modelName ?? 'gpt-4o-mini', this.log);
32 const llm = new ChatOpenAI({
33 model: fields?.modelName,
34 apiKey: fields?.openaiApiKey,
35 temperature: 0,
36 callbacks: [
37 this.costHandler,
38 ],
39 });
40 const tools = this.buildTools(this.apifyClient, this.log);
41 const prompt = this.buildPrompt();
42 const agent = createToolCallingAgent({
43 llm,
44 tools,
45 prompt,
46 });
47 this.agentExecutor = new AgentExecutor({
48 agent,
49 tools,
50 verbose: false,
51 maxIterations: 5,
52 });
53 }
54
55 protected buildTools(
56 apifyClient: ApifyClient, log: Log | Console
57 ): StructuredToolInterface[] {
58 // Tools are initialized to be passed to the agent
59 const zillowSearch = new ZillowSearch({ apifyClient, log });
60 return [
61 zillowSearch,
62 ];
63 }
64
65 protected buildPrompt(): ChatPromptTemplate {
66 return ChatPromptTemplate.fromMessages([
67 ['system',
68 'You are a experienced real state agent that wants to help the user to find the perfect home. '
69 + "You will stick to the following steps, but notify the user if you get stuck or can't continue. "
70 + 'Step 1. Using the selected Zip Codes, search on Zillow for properties that match the user requirements. '
71 // + "Remember: Don't perform a Zillow Search until you find a good ranking (every search costs money and you want to save). "
72 + 'The user must specify if he or she is looking to rent or buy a property (default to rent if the information is not given). '
73 + 'The user can specify if the ideal property has a minimum value (default to 1 if the information is not given). '
74 + 'The user can specify if the ideal property has a maximum value (default to 1000 if the information is not given). '
75 + 'Inform the user of the assumptions you make before delivering any results. \n'
76 + 'Step 2. Based on the results, use your expertise to recommend the best 5 properties that you found. '
77 + 'The user may have specified other requests like pets, pool, beds, baths, sqft, gym, etc. '
78 + 'Filter the results based on this information or notify the user if you are unable to do so. '
79 + 'Make sure that you show the address, price and a link to view more information about the chosen properties. '
80 + 'At the end, please explain why you chose those properties. '
81 ],
82 ['placeholder', '{chat_history}'],
83 ['human', '{input}'],
84 ['placeholder', '{agent_scratchpad}'],
85 ]);
86 }
87}
88
89export default ResearcherAgent;

src/tools/duck_duck_go.ts

1import { Log, ApifyClient } from 'apify';
2import { StructuredTool } from '@langchain/core/tools';
3import { z } from 'zod';
4import { chargeForToolUsage } from '../utils/ppe_handler.js';
5
6/**
7 * Interface for parameters required by DuckDuckGo class.
8 */
9export interface DuckDuckGoParams {
10 apifyClient: ApifyClient;
11 log: Log | Console;
12}
13
14/**
15 * Tool that uses the DuckDuckGo function
16 */
17export class DuckDuckGo extends StructuredTool {
18 protected log: Log | Console;
19 protected apifyClient: ApifyClient;
20
21 name = 'duck_duck_go';
22
23 description = 'Performs a search on the search engine DuckDuckGo and returns a stringified JSON with the results.';
24
25 schema = z.object({
26 keywords: z.string(),
27 locale: z.enum(['us-en', 'uk-en', 'cz-cs', 'cl-es']) || undefined,
28 maximum: z.number() || undefined,
29 });
30
31 constructor(fields?: DuckDuckGoParams) {
32 super(...arguments);
33 this.log = fields?.log ?? console;
34 this.apifyClient = fields?.apifyClient ?? new ApifyClient();
35 }
36
37 override async _call(arg: z.output<typeof this.schema>) {
38 const actorInput = {
39 keywords: arg.keywords,
40 proxy: {
41 useApifyProxy: true,
42 apifyProxyGroups: [
43 'RESIDENTIAL'
44 ],
45 apifyProxyCountry: 'US'
46 },
47 locale: arg.locale ?? 'us-en',
48 operation: 'st',
49 safe: 'Partial',
50 daterange: 'all',
51 img_type: 'all',
52 img_size: 'all',
53 vid_duration: 'all',
54 maximum: arg.maximum ?? 5,
55 timeout: 30
56 };
57 this.log.debug(
58 `Calling DuckDuckGo with input: ${JSON.stringify(actorInput)}`
59 );
60 const actorRun = await this.apifyClient
61 .actor('canadesk/duckduckgo-serp-api')
62 .call(actorInput);
63 const dataset = await this.apifyClient
64 .dataset(actorRun.defaultDatasetId)
65 .listItems();
66 const { items } = dataset;
67 this.log.debug(`DuckDuckGo response: ${JSON.stringify(items)}`);
68 await chargeForToolUsage(this.name, 1);
69 return JSON.stringify(items);
70 }
71}
72
73export default DuckDuckGo;

src/tools/magictool.ts

1import { Log } from 'apify';
2import { Tool } from '@langchain/core/tools';
3
4/**
5 * Interface for parameters required by MagicTool class.
6 */
7export interface MagicToolParams {
8 apiKey?: string;
9 log: Log | Console;
10}
11
12/**
13 * Tool that uses the MagicTool function. This is an example function to use as template.
14 */
15export class MagicTool extends Tool {
16 static override lc_name() {
17 return 'MagicTool';
18 }
19
20 protected log: Log | Console;
21 protected apiKey: string;
22
23 name = 'magic_function';
24
25 description = 'Applies a magic function to an input.';
26
27 constructor(fields?: MagicToolParams) {
28 super(...arguments);
29 this.log = fields?.log ?? console;
30 const apiKey = fields?.apiKey ?? process.env.SECRET_API_KEY ?? '';
31 if (apiKey === undefined) {
32 this.log.debug(
33 "Secret API key not set. You can set it as 'SECRET_API_KEY' in your environment variables."
34 );
35 }
36 this.apiKey = apiKey;
37 }
38
39 async _call(rawInput: string) {
40 this.log.debug(`rawInput: ${rawInput}`);
41 const number = parseInt(rawInput, 10);
42 return `${number + 2}`;
43 }
44}
45
46export default MagicTool;

src/tools/website_scraper.ts

1import { Log, ApifyClient } from 'apify';
2import { StructuredTool } from '@langchain/core/tools';
3import { z } from 'zod';
4import { chargeForToolUsage } from '../utils/ppe_handler.js';
5
6/**
7 * Interface for parameters required by WebsiteScraper class.
8 */
9export interface WebsiteScraperParams {
10 apifyClient: ApifyClient;
11 log: Log | Console;
12}
13
14/**
15 * An example input that serves as a good default
16 */
17const sampleInput = {
18 method: 'getAllItems',
19 output: '{"results":[""]}',
20};
21
22/**
23 * Tool that uses the WebsiteScraper function
24 */
25export class WebsiteScraper extends StructuredTool {
26 protected log: Log | Console;
27 protected apifyClient: ApifyClient;
28
29 name = 'website_scraper';
30
31 description = 'Scrapes a URL aiming the search based on a method (for example: getAllItems) and returns a stringified JSON with the results using the specified output format (for example: {"results":[""]}).';
32
33 schema = z.object({
34 url: z.string(),
35 method: z.string() || undefined,
36 // output: z.string() || undefined || null,
37 });
38
39 constructor(fields?: WebsiteScraperParams) {
40 super(...arguments);
41 this.log = fields?.log ?? console;
42 this.apifyClient = fields?.apifyClient ?? new ApifyClient();
43 }
44
45 override async _call(arg: z.output<typeof this.schema>) {
46 const actorInput = {
47 url: arg.url,
48 method: arg.method ?? sampleInput.method,
49 output: sampleInput.output,
50 };
51 const callOptions = {
52 timeout: 60,
53 };
54 this.log.debug(
55 `Calling WebsiteScraper with input: ${JSON.stringify(actorInput)}`
56 );
57 const actorRun = await this.apifyClient
58 .actor('zeeb0t/web-scraping-api---scrape-any-website')
59 .call(actorInput, callOptions);
60 const dataset = await this.apifyClient
61 .dataset(actorRun.defaultDatasetId)
62 .listItems();
63 const { items } = dataset;
64 this.log.debug(`WebsiteScraper response: ${JSON.stringify(items)}`);
65 await chargeForToolUsage(this.name, 1);
66 return JSON.stringify(items);
67 }
68}
69
70export default WebsiteScraper;

src/tools/zillow_search.ts

1import { Log, ApifyClient } from 'apify';
2import { StructuredTool } from '@langchain/core/tools';
3import { z } from 'zod';
4import { chargeForToolUsage } from '../utils/ppe_handler.js';
5
6/**
7 * Interface for parameters required by ZillowSearch class.
8 */
9export interface ZillowSearchParams {
10 apifyClient: ApifyClient;
11 log: Log | Console;
12}
13
14/**
15 * Tool that uses the ZillowSearch function
16 */
17export class ZillowSearch extends StructuredTool {
18 protected log: Log | Console;
19 protected apifyClient: ApifyClient;
20
21 name = 'zillow_search';
22
23 description = 'Searches for properties on Zillow based on a list of Zip Codes (at least one) and returns a stringified JSON with the results.';
24
25 schema = z.object({
26 zipCodes: z.string().array(),
27 minimumPrice: z.number(),
28 maximumPrice: z.number(),
29 forRent: z.boolean(),
30 });
31
32 constructor(fields?: ZillowSearchParams) {
33 super(...arguments);
34 this.log = fields?.log ?? console;
35 this.apifyClient = fields?.apifyClient ?? new ApifyClient();
36 }
37
38 override async _call(arg: z.output<typeof this.schema>) {
39 const actorInput = {
40 forRent: arg.forRent,
41 forSaleByAgent: true,
42 forSaleByOwner: true,
43 priceMax: arg.maximumPrice,
44 priceMin: arg.minimumPrice,
45 sold: false,
46 zipCodes: arg.zipCodes,
47 };
48 this.log.debug(
49 `Calling ZillowSearch with input: ${JSON.stringify(actorInput)}`
50 );
51 const actorRun = await this.apifyClient
52 .actor('maxcopell/zillow-zip-search')
53 .call(actorInput);
54 const dataset = await this.apifyClient
55 .dataset(actorRun.defaultDatasetId)
56 .listItems();
57 await chargeForToolUsage(this.name, dataset.total);
58 // returns only the top 10 properties to avoid sending too much data
59 // NOTE: this tool could return the dataset-id and use another tool to read it
60 const cappedItems = dataset.items.slice(0, 10);
61 this.log.debug(`ZillowSearch response: ${JSON.stringify(cappedItems)}`);
62 return JSON.stringify(cappedItems);
63 }
64}
65
66export default ZillowSearch;

src/tools/zip_code_search.ts

1import { Log } from 'apify';
2import { StructuredTool } from '@langchain/core/tools';
3import { z } from 'zod';
4import { chargeForToolUsage } from '../utils/ppe_handler.js';
5
6/**
7 * Interface for parameters required by ZipCodeSearch class.
8 */
9export interface ZipCodeSearchParams {
10 apiKey?: string;
11 log: Log | Console;
12}
13
14/**
15 * Tool that uses the ZipCodeSearch function
16 */
17export class ZipCodeSearch extends StructuredTool {
18 protected log: Log | Console;
19 protected apiKey: string;
20
21 name = 'zip_code_search';
22
23 description = 'Returns a list of Zip Codes for a city and the state it belongs to.';
24
25 schema = z.object({
26 city: z.string(),
27 state: z.string(),
28 });
29
30 constructor(fields?: ZipCodeSearchParams) {
31 super(...arguments);
32 this.log = fields?.log ?? console;
33 const apiKey = fields?.apiKey ?? process.env.ZIP_API_KEY ?? '';
34 if (apiKey === undefined) {
35 this.log.debug(
36 "Secret API key not set. You can set it as 'ZIP_API_KEY' in your environment variables."
37 );
38 }
39 this.apiKey = apiKey;
40 }
41
42 protected buildUrl = (city: string, state: string): string => {
43 const baseUrl = `https://www.zipcodeapi.com/rest/${this.apiKey}/city-zips.json`;
44 return `${baseUrl}/${city}/${state}`;
45 };
46
47 override async _call(arg: z.output<typeof this.schema>) {
48 const serviceUrl = this.buildUrl(arg.city, arg.state);
49 this.log.debug(
50 `Calling ZipCodeSearch with city='${arg.city}' and state='${arg.state}'`
51 );
52 const resp = await fetch(serviceUrl);
53 const json = await resp.json();
54 this.log.debug(`ZipCodeSearch response: ${JSON.stringify(json)}`);
55 await chargeForToolUsage(this.name, 1);
56 const zipCodes = (json.zip_codes || []).join(', ');
57 return zipCodes;
58 }
59}
60
61export default ZipCodeSearch;

src/utils/cost_handler.ts

1import { Log } from 'apify';
2import { BaseTracer } from 'langchain/callbacks';
3import { Run } from '@langchain/core/tracers/tracer_langchain';
4import { GPT_MODEL_LIST, OpenaiAPICost } from './openai_models.js';
5import { chargeForModelTokens } from './ppe_handler.js';
6
7interface TotalCost {
8 usd: number;
9 inputTokens: number;
10 outputTokens: number;
11 totalModelCalls: number;
12}
13
14export class CostHandler extends BaseTracer {
15 protected log: Log | Console;
16 name: string;
17 modelName: string;
18 modelCost: OpenaiAPICost;
19 totalCost: TotalCost;
20
21 constructor(modelName: string, log?: Log | Console) {
22 super();
23 this.log = log ?? console;
24 this.name = 'cost_handler';
25 this.modelName = modelName;
26 this.modelCost = GPT_MODEL_LIST[this.modelName].cost;
27 this.totalCost = {
28 usd: 0,
29 inputTokens: 0,
30 outputTokens: 0,
31 totalModelCalls: 0,
32 };
33 }
34
35 // NOTE: We do not need to persist runs in this handler.
36 // eslint-disable-next-line @typescript-eslint/no-unused-vars
37 persistRun(_run: Run) {
38 return Promise.resolve();
39 }
40
41 /**
42 * Logs tokens usage in $.
43 * @returns void
44 */
45 override onLLMEnd(run: Run) {
46 const tokenUsage = run?.outputs?.llmOutput?.tokenUsage;
47 if (tokenUsage) {
48 const inputCostsUSD = this.modelCost.input
49 * (tokenUsage.promptTokens / 1000);
50 const outputCostsUSD = this.modelCost.output
51 * (tokenUsage.completionTokens / 1000);
52 const callCostUSD = inputCostsUSD + outputCostsUSD;
53 this.totalCost.usd += inputCostsUSD + outputCostsUSD;
54 this.totalCost.inputTokens += tokenUsage.promptTokens;
55 this.totalCost.outputTokens += tokenUsage.completionTokens;
56 this.totalCost.totalModelCalls++;
57 const durationSecs = run.end_time && run.start_time
58 && (run.end_time - run.start_time) / 1000;
59 this.log.debug(`LLM model call processed`,
60 {
61 durationSecs,
62 callCostUSD,
63 totalCostUSD: this.totalCost.usd,
64 inputTokens: this.totalCost.inputTokens,
65 outputTokens: this.totalCost.outputTokens,
66 }
67 );
68 }
69 }
70
71 override onLLMStart(run: Run) {
72 this.log.debug(`Calling LLM model`, run);
73 }
74
75 getTotalCost() {
76 return this.totalCost;
77 }
78
79 async logOrChargeForTokens(modelName: string, tokenCostActive: boolean) {
80 const costs = this.totalCost;
81 if (tokenCostActive) {
82 const tokens = costs.inputTokens + costs.outputTokens;
83 const tokensCost = this.modelCost.output * (tokens / 1000);
84 this.log.info(`Total tokens processed: ${tokens}. Usage cost: ${tokensCost}`);
85 await chargeForModelTokens(modelName, tokens);
86 } else {
87 this.log.info(`Estimated OpenAI cost: $${costs.usd} USD`);
88 }
89 }
90}

src/utils/openai_models.ts

1export interface OpenaiAPICost {
2 input: number; // USD cost per 1000 tokens
3 output: number; // USD cost per 1000 tokens
4}
5
6export interface GPTModelConfig {
7 model: string;
8 maxTokens: number;
9 maxOutputTokens?: number;
10 interface: 'text' | 'chat';
11 cost: OpenaiAPICost; // USD cost per 1000 tokens
12}
13
14/**
15* List of GPT models that can be used.
16* Should be in sync with https://platform.openai.com/docs/models/
17* Last updated on 2025-03-09
18*/
19export const GPT_MODEL_LIST: {[key: string]: GPTModelConfig} = {
20 'gpt-4o': {
21 model: 'gpt-4o',
22 maxTokens: 16384,
23 interface: 'chat',
24 cost: {
25 input: 0.0025,
26 output: 0.01,
27 },
28 },
29 'gpt-4o-mini': {
30 model: 'gpt-4o-mini',
31 maxTokens: 16384,
32 interface: 'chat',
33 cost: {
34 input: 0.00015,
35 output: 0.0006,
36 },
37 },
38 'gpt-3.5-turbo': {
39 model: 'gpt-3.5-turbo',
40 maxTokens: 8192,
41 interface: 'chat',
42 cost: {
43 input: 0.0005,
44 output: 0.0015,
45 },
46 },
47 'o3-mini': {
48 model: 'o3-mini',
49 maxTokens: 4096,
50 interface: 'chat',
51 cost: {
52 input: 0.0011,
53 output: 0.0044,
54 },
55 },
56 'o1-mini': {
57 model: 'o1-mini',
58 maxTokens: 2048,
59 interface: 'chat',
60 cost: {
61 input: 0.0011,
62 output: 0.0044,
63 },
64 },
65};

src/utils/ppe_events.ts

1export const PPE_EVENT = {
2 ACTOR_START_GB: 'actor-start-gb',
3 GPT_4O: 'openai-1000-tokens-gpt-4o',
4 GPT_4O_MINI: 'openai-1000-tokens-gpt-4o-mini',
5 GPT_3_5_TURBO: 'openai-1000-tokens-gpt-3.5-turbo',
6 GPT_O3_MINI: 'openai-1000-tokens-gpt-o3-mini',
7 GPT_O1_MINI: 'openai-1000-tokens-gpt-o1-mini',
8 DUCK_DUCK_GO: 'duck-duck-go-search',
9 WEBSITE_SCRAPER: 'site-scraped',
10 ZILLOW_SEARCH: 'zillow-results',
11 ZIP_CODE_SEARCH: 'zip-code-search',
12} as const;

src/utils/ppe_handler.ts

1import { Actor, log } from 'apify';
2import { PPE_EVENT } from './ppe_events.js';
3
4/**
5 * Charges for the tokens used by a specific model.
6 *
7 * @param modelName - The name of the model.
8 * @param tokens - The number of tokens to charge for.
9 * @throws Will throw an error if the model name is unknown.
10 */
11export async function chargeForModelTokens(modelName: string, tokens: number) {
12 const tokensK = Math.ceil(tokens / 1000);
13 log.debug(`Charging for ${tokens} tokens (${tokensK}k) for model ${modelName}`);
14 let eventName: string = PPE_EVENT.GPT_4O;
15 switch (modelName) {
16 case 'gpt-4o-mini':
17 eventName = PPE_EVENT.GPT_4O_MINI;
18 break;
19 case 'gpt-3.5-turbo':
20 eventName = PPE_EVENT.GPT_3_5_TURBO;
21 break;
22 case 'gpt-o3-mini':
23 eventName = PPE_EVENT.GPT_O3_MINI;
24 break;
25 case 'gpt-o1-mini':
26 eventName = PPE_EVENT.GPT_O1_MINI;
27 break;
28 default:
29 eventName = PPE_EVENT.GPT_4O;
30 break;
31 }
32 await Actor.charge(
33 { eventName, count: tokensK }
34 );
35}
36
37export async function chargeForActorStart() {
38 if (
39 Actor.getChargingManager()
40 .getChargedEventCount(PPE_EVENT.ACTOR_START_GB) === 0
41 ) {
42 const count = Math.ceil((Actor.getEnv().memoryMbytes || 1024) / 1024);
43 await Actor.charge({ eventName: PPE_EVENT.ACTOR_START_GB, count });
44 }
45}
46
47export async function chargeForToolUsage(toolName: string, count: number) {
48 log.debug(`Charging #${count} times for tool ${toolName}`);
49 let eventName: string = '';
50 switch (toolName) {
51 case 'duck_duck_go':
52 eventName = PPE_EVENT.DUCK_DUCK_GO;
53 break;
54 case 'website_scraper':
55 eventName = PPE_EVENT.WEBSITE_SCRAPER;
56 break;
57 case 'zillow_search':
58 eventName = PPE_EVENT.ZILLOW_SEARCH;
59 break;
60 case 'zip_code_search':
61 eventName = PPE_EVENT.ZIP_CODE_SEARCH;
62 break;
63 default:
64 eventName = '';
65 break;
66 }
67 await Actor.charge({ eventName, count });
68}