Skip to content

Commit 5909ca1

Browse files
authored
Non-activity translation (#1434)
- When in activity, allow translation using other non-activity schema if we get an unknown action with activity schemas. - Activity can set "restricted" to disallow using non-activity schemas. - Make sure the activity state are not used in the prompt for non-activity schemas.
1 parent 413c5d3 commit 5909ca1

File tree

5 files changed

+246
-122
lines changed

5 files changed

+246
-122
lines changed

ts/packages/agentSdk/src/agentInterface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ export type ActivityContext<T = Record<string, unknown>> = {
211211
state: T;
212212
openLocalView?: boolean | undefined;
213213
activityEndAction?: AppAction | undefined;
214+
restricted?: boolean | undefined; // restrict the actions to this specific agent, default is false
214215
};
215216

216217
export interface ActionContext<T = void> {

ts/packages/dispatcher/src/context/dispatcher/handlers/requestCommandHandler.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ function getExplainerOptions(
200200

201201
const usedTranslators = new Map<string, TypeAgentTranslator>();
202202
const actions = requestAction.actions;
203+
const activeSchemas = new Set(context.agents.getActiveSchemas());
203204
for (const { action } of actions) {
204205
if (isUnknownAction(action)) {
205206
// can't explain unknown actions
@@ -212,9 +213,10 @@ function getExplainerOptions(
212213
return undefined;
213214
}
214215

216+
// TODO: This does not support activities.
215217
usedTranslators.set(
216218
schemaName,
217-
getTranslatorForSchema(context, schemaName),
219+
getTranslatorForSchema(context, schemaName, activeSchemas),
218220
);
219221
}
220222
const { list, value, translate } =

ts/packages/dispatcher/src/execute/activityContext.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,13 @@ export function setActivityContext(
6161
: undefined);
6262

6363
if (context.session.getConfig().execution.activity) {
64-
const { activityName, description, state, activityEndAction } =
65-
resultActivityContext;
64+
const {
65+
activityName,
66+
description,
67+
state,
68+
activityEndAction,
69+
restricted,
70+
} = resultActivityContext;
6671
let action: AppAction | undefined;
6772
if (activityEndAction !== undefined) {
6873
action = structuredClone(activityEndAction);
@@ -83,6 +88,7 @@ export function setActivityContext(
8388
openLocalView:
8489
localViewAction ?? context.activityContext?.openLocalView,
8590
activityEndAction: action,
91+
restricted,
8692
};
8793

8894
if (context.activityContext === undefined) {

0 commit comments

Comments
 (0)