### Overview Major restructuring from monolithic `arcade-ai` package to modular library architecture with standardized uv-based dependency management.  ### New Package Structure - **`arcade-tdk`** - Lightweight toolkit development kit (core decorators, auth) - **`arcade-core`** - Core execution engine and catalog functionality - **`arcade-serve`** - FastAPI/MCP server components - **`arcade-ai`** - Meta package that includes CLI functionality. Optionally include evals via the `evals` extra. Optionally include all packages via the `all` extra. ### Key Benefits - **Lighter Dependencies**: Toolkits now depend only on `arcade-tdk` (~2 deps) vs full `arcade-ai` (~30+ deps) - **Faster Builds**: uv provides 10-100x faster dependency resolution and installation - **Better Modularity**: Clear separation of concerns, consumers import only what they need - **Standard Tooling**: Eliminates custom poetry scripts, uses standard Python packaging ### Migration Impact - All 20 toolkits converted from poetry → uv with `arcade-tdk` dependencies plus `arcade-ai[evals]` and `arcade-serve` dev dependencies. When developing locally, devs should install toolkits via `make install-local`. - Modern Python 3.10+ type hints throughout - Standardized build system with hatchling backend - Enhanced Makefile with robust toolkit management commands - Removed `arcade dev` CLI command - Reduce the number of files created by `arcade new` and add an option to not generate a tests and evals folder. This foundation enables faster development cycles and cleaner dependency chains for the growing toolkit ecosystem. ### Todo After this PR is merged - [ ] Post-merge workflow(s) (release & publish containers, etc) - [ ] Release order plan. @EricGustin suggests releasing in the following order: 1. `arcade-core` version 0.1.0 2. `arcade-serve` version 0.1.0 and `arcade-tdk` version 0.1.0 3. `arcade-ai` version 2.0.0 4. Patch release for all toolkits (all changes in toolkits are internal refactors) - [ ] [Update docs](https://github.com/ArcadeAI/docs/pull/318) --------- Co-authored-by: Eric Gustin <eric@arcade.dev> Co-authored-by: Eric Gustin <34000337+EricGustin@users.noreply.github.com>
126 lines
4.2 KiB
Python
126 lines
4.2 KiB
Python
import asyncio
|
|
from typing import Annotated
|
|
|
|
from arcade_tdk import ToolContext, tool
|
|
from arcade_tdk.auth import OAuth2
|
|
from arcade_tdk.errors import ToolExecutionError
|
|
|
|
from arcade_salesforce.enums import SalesforceObject
|
|
from arcade_salesforce.models import SalesforceClient
|
|
from arcade_salesforce.utils import clean_account_data
|
|
|
|
|
|
# TODO: We only return up to 10 items of each related object (e.g. contacts). Need to implement
|
|
# separate tools for each related object, so that we can return more items, when needed.
|
|
@tool(
|
|
requires_auth=OAuth2(
|
|
id="salesforce",
|
|
scopes=[
|
|
"read_account",
|
|
"read_contact",
|
|
"read_lead",
|
|
"read_note",
|
|
"read_opportunity",
|
|
"read_task",
|
|
],
|
|
)
|
|
)
|
|
async def get_account_data_by_keywords(
|
|
context: ToolContext,
|
|
query: Annotated[
|
|
str,
|
|
"The query to search for accounts. MUST be longer than one character. It will match the "
|
|
"keywords against all account fields, such as name, website, phone, address, etc. "
|
|
"E.g. 'Acme'",
|
|
],
|
|
# Note: Salesforce supports up to 200 results, but since we're enriching each account with
|
|
# related objects, we limit to 10, so that the response is not too lengthy for LLMs.
|
|
limit: Annotated[
|
|
int,
|
|
"The maximum number of accounts to return. Defaults to 10. Maximum allowed is 10.",
|
|
] = 10,
|
|
page: Annotated[int, "The page number to return. Defaults to 1 (first page of results)."] = 1,
|
|
) -> Annotated[
|
|
dict,
|
|
"The accounts matching the query with related info: contacts, leads, notes, calls, "
|
|
"opportunities, tasks, emails, and events (up to 10 items of each type)",
|
|
]:
|
|
"""Searches for accounts in Salesforce and returns them with related info: contacts, leads,
|
|
notes, calls, opportunities, tasks, emails, and events (up to 10 items of each type).
|
|
|
|
An account is an organization (such as a customer, supplier, or partner, though more commonly
|
|
a customer). In some Salesforce account setups, an account can also represent a person.
|
|
"""
|
|
if len(query) < 2:
|
|
raise ToolExecutionError("The `query` argument must have two or more characters.")
|
|
|
|
limit = min(limit, 10)
|
|
|
|
client = SalesforceClient(context.get_auth_token_or_empty())
|
|
|
|
params = {
|
|
"q": query,
|
|
"sobjects": [
|
|
{
|
|
"name": "Account",
|
|
"fields": await client.get_object_fields(SalesforceObject.ACCOUNT),
|
|
}
|
|
],
|
|
"in": "ALL",
|
|
"overallLimit": limit,
|
|
"offset": (page - 1) * limit,
|
|
}
|
|
response = await client.post("parameterizedSearch", json_data=params)
|
|
search_results = response["searchRecords"]
|
|
|
|
accounts = await asyncio.gather(*[
|
|
client.enrich_account(
|
|
account_data=account,
|
|
limit_per_association=10,
|
|
)
|
|
for account in search_results
|
|
])
|
|
return {"accounts": [clean_account_data(account) for account in accounts]}
|
|
|
|
|
|
@tool(
|
|
requires_auth=OAuth2(
|
|
id="salesforce",
|
|
scopes=[
|
|
"read_account",
|
|
"read_contact",
|
|
"read_lead",
|
|
"read_note",
|
|
"read_opportunity",
|
|
"read_task",
|
|
],
|
|
)
|
|
)
|
|
async def get_account_data_by_id(
|
|
context: ToolContext,
|
|
account_id: Annotated[
|
|
str,
|
|
"The ID of the account to get data for.",
|
|
],
|
|
) -> Annotated[
|
|
dict,
|
|
"The account with related info: contacts, leads, notes, calls, opportunities, tasks, emails, "
|
|
"and events (up to 10 items of each type)",
|
|
]:
|
|
"""Gets the account with related info: contacts, leads, notes, calls, opportunities, tasks,
|
|
emails, and events (up to 10 items of each type).
|
|
|
|
An account is an organization (such as a customer, supplier, or partner, though more commonly
|
|
a customer). In some Salesforce account setups, an account can also represent a person.
|
|
"""
|
|
client = SalesforceClient(context.get_auth_token_or_empty())
|
|
|
|
account = await client.get_account(account_id)
|
|
|
|
if not account:
|
|
return {"account": None, "error": f"No account found with id '{account_id}'"}
|
|
|
|
account = await client.enrich_account(account_data=account)
|
|
account = clean_account_data(account)
|
|
|
|
return {"account": account}
|