Skip to content

Commit

Permalink
Agent toggles with no param shows current status (#437)
Browse files Browse the repository at this point in the history
`@config agent` and independent toggles `schema`, `action` and `command`
will show the current status when no parameters is specified.

Add capability to display `string[][]` as a table.
Update documentation.
  • Loading branch information
curtisman authored Nov 27, 2024
1 parent d10d68a commit 45180fa
Show file tree
Hide file tree
Showing 24 changed files with 365 additions and 88 deletions.
7 changes: 5 additions & 2 deletions ts/packages/agentSdk/src/display.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ export type DynamicDisplay = {
nextRefreshMs: number; // in milliseconds, -1 means no more refresh.
};

// Single line, multiple lines, or table
export type MessageContent = string | string[] | string[][];

export type DisplayContent =
| string
| MessageContent
| {
type: DisplayType; // Type of the content
content: string;
content: MessageContent;
kind?: DisplayMessageKind; // Optional message kind for client specific styling
speak?: boolean; // Optional flag to indicate if the content should be spoken
};
Expand Down
24 changes: 10 additions & 14 deletions ts/packages/agentSdk/src/helpers/displayHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
DisplayAppendMode,
DisplayContent,
DisplayMessageKind,
MessageContent,
} from "../display.js";

function gatherMessages(callback: (log: (message?: string) => void) => void) {
Expand All @@ -19,20 +20,15 @@ function gatherMessages(callback: (log: (message?: string) => void) => void) {

type LogFn = (log: (message?: string) => void) => void;
function getMessage(
input: string | string[] | LogFn,
input: MessageContent | LogFn,
kind?: DisplayMessageKind,
): DisplayContent {
const content =
typeof input === "function"
? gatherMessages(input)
: Array.isArray(input)
? input.join("\n")
: input;
const content = typeof input === "function" ? gatherMessages(input) : input;
return kind ? { type: "text", content, kind } : content;
}

function displayMessage(
message: string | string[] | LogFn,
message: MessageContent | LogFn,
context: ActionContext<unknown>,
kind?: DisplayMessageKind,
appendMode: DisplayAppendMode = "block",
Expand All @@ -41,42 +37,42 @@ function displayMessage(
}

export async function displayInfo(
message: string | string[] | LogFn,
message: MessageContent | LogFn,
context: ActionContext<unknown>,
) {
displayMessage(message, context, "info");
}

export async function displayStatus(
message: string | string[] | LogFn,
message: MessageContent | LogFn,
context: ActionContext<unknown>,
) {
displayMessage(message, context, "status", "temporary");
}

export async function displayWarn(
message: string | string[] | LogFn,
message: MessageContent | LogFn,
context: ActionContext<unknown>,
) {
displayMessage(message, context, "warning");
}

export async function displayError(
message: string | string[] | LogFn,
message: MessageContent | LogFn,
context: ActionContext<unknown>,
) {
displayMessage(message, context, "error");
}

export async function displaySuccess(
message: string | string[] | LogFn,
message: MessageContent | LogFn,
context: ActionContext<unknown>,
) {
displayMessage(message, context, "success");
}

export async function displayResult(
message: string | string[] | LogFn,
message: MessageContent | LogFn,
context: ActionContext<unknown>,
) {
displayMessage(message, context);
Expand Down
1 change: 1 addition & 0 deletions ts/packages/agentSdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export {
ClientAction,
DisplayType,
DynamicDisplay,
MessageContent,
DisplayContent,
DisplayAppendMode,
DisplayMessageKind,
Expand Down
6 changes: 2 additions & 4 deletions ts/packages/agents/code/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ The code dispatcher agent is not enabled by default. It is integrated to work wi
You can enable all the sub-agents as part of the code agent by running the following commands on the typeagent cli or shell:

```
@config action code*
@config translator code*
@config agent code*
```

Please look at the agent [manifest](./src/codeManifest.json) file to look at other sub-agents that are part of the code agent. The code agent shows how to extend an agent to handle a hierarchical set of actions. For instance if you want to run different commands related to debugging an application on vscode, you will want to run these commands:

```
@config translator code.code-debug
@config action code.code-debug
@config agent code.code-debug
```

## Trademarks
Expand Down
2 changes: 1 addition & 1 deletion ts/packages/cache/src/explanation/explainerFactories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { GenericExplainer } from "./genericExplainer.js";
import { createExplainerV5 } from "./v5/explanationV5.js";

// A list of available explainer factories. The properties are the name used to look up
// the explainer with the @config translator command.
// the explainer with the `@config explainer name` command.
const explainerFactories: {
[key: string]: (model: string | undefined) => GenericExplainer;
} = {
Expand Down
8 changes: 4 additions & 4 deletions ts/packages/cli/demo/demo.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ====== Init =======
@session new --memory
@config action -*
@config translator -* player calendar
@config schema -* player calendar
@config serviceHost off

# =============================================
Expand Down Expand Up @@ -37,7 +37,7 @@ Could you play Liebesleid please?
# -------------------------------------
# Calendar - cross domain generalization
# -------------------------------------
@config translator calendar
@config schema calendar

# Request with explanation
Can you schedule design meeting starting at 2 pm with Piali?
Expand All @@ -50,15 +50,15 @@ kindly plan meeting to discuss office assignment from 4 pm with John?
# ==========================
# Prebuilt caches
# ==========================
@config translator player
@config schema player
@const import

begin playing Deutsche Motette by Richard Strauss
Please play Symphony No. 8 by Shostakovich.
if you don't mind, begin playing a selection of Phillip Glass for us?
I want to listen to a selection of Johann Sebastian Bach

@config translator calendar
@config schema calendar
@const import

Add meeting 3-4pm next Thursday
Expand Down
2 changes: 1 addition & 1 deletion ts/packages/cli/demo/history.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ====== Init =======
@session new --memory
@config action -*
@config translator -* player calendar
@config schema -* player calendar
@config serviceHost off

# Initialize context
Expand Down
62 changes: 46 additions & 16 deletions ts/packages/dispatcher/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,34 +35,66 @@ Beyond natural language, users can specify system command with inputs starting w

### Toggling Dispatcher Agents

Dispatcher agent's translation can be enabled and disabled.
Dispatcher agent can be enabled and disabled.

- `@config translator <translator>` | Enables the supplied translator
- `@config translator -<translator>` | Disables the supplied translator
- `@config translator *` | Enable all translators
- `@config translator code*` | Enable a pattern of translators (useful for sub-translators)
- `@config translator @` | Reset enable or disable of the translator to default
Toggle a specific `<agent>`:

Similarly, dispatcher agent's action can be enabled and disable independent of translation with similar pattern using `@config action`
- `@config agent <agent>` _(Enable `<agent>`)_
- `@config agent --off <agent>` or `@config agent -x <agent>` _(Disable `<agent>`)_

To list all the translator (and explainer) configured:
Toggle using `*` pattern:

- `@config agent *` (Enable all agents)
- `@config agent *l*` | (Enable agents that has "l" in the name)

Reset to default:

- `@config agent --reset` or `@config agent -r`

Dispatcher agent's schema, action and command can be toggled independently as well, using `@config schema`, `@config action`, `@config command`.

To list all avaiable agents and their status, just the command without any parameters:

```bash
[📅💊📩📝👀🪟⚛️💬🔧]>@config translator
Usage: @config translator [-]<translator>]
<translator>: player, calendar, email, list, browser, browser.paleoBioDb, desktop, code, code.code-debug, code.code-display, code.code-general, phrases, books, chat, correction, photo, system.config, system.session
🤖🚧💾 [🎧📅📩📝🌐🪟⚛️💬🤖🔧📷🖐🖼️📱🗎]@config agent
|Agent |Schemas|Actions|Commands|
|--------------------|-------|-------|--------|
|androidMobile ||||
|browser ||||
| browser.commerce ||| |
| browser.crossword ||| |
| browser.paleoBioDb||| |
|calendar ||||
|chat ||||
|code ||||
| code.code-debug ||| |
| code.code-display ||| |
| code.code-general ||| |
|desktop ||||
|dispatcher ||||
| dispatcher.clarify||| |
|email ||||
|greeting ||||
|image ||||
|list ||||
|markdown ||||
|photo ||||
|player ||||
|system | | ||
| system.config ||| |
| system.session ||| |
```

### Explainer

Explainer is the step where the dispatcher leverages the cache to ask the GPT to explain the generated translations once the user accepted it. The result is used to create constructions if it is enabled (see below). (Explanation is not generated for translations using constructions if it is enabled).

As part of the exploration, the cache has multiple explainer implementations, which can be changed in the CLI's interactive mode using the command `@config explainer <explainer>`.
As part of the exploration, the cache has multiple explainer implementations, which can be changed in the CLI's interactive mode using the command `@config explainer name <explainer>`.

For example, in the [CLI](../cli):

```bash
[📅💊📩📝👀🪟⚛️💬🔧]> @config explainer v4
[📅💊📩📝👀🪟⚛️💬🔧]> @config explainer name v4

[📅💊📩📝👀🪟⚛️💬🔧 (explainer: v4)]>
```
Expand All @@ -71,7 +103,7 @@ To list all configured explainers:

```bash
🤖🚧💾 [📅💊📩📝👀🪟⚛️💬🔧]>@config explainer
Usage: @config explainer <explainer>
Usage: @config explainer name <explainer>
<explainer>: v4, v5
```

Expand All @@ -81,7 +113,6 @@ There are other short cut commands to exercise specify part of the TypeAgent Dis

- `@translate <request>` - Only do the translation (no follow up explanation )
- `@explain <request> => <action>` - only do the explanation of the request/action combo
- `@correct <correction prompt>` - based on the response of the last explanation, send a follow up prompt for correction

### Sessions

Expand All @@ -98,7 +129,6 @@ For dispatcher configured to persist sessions (i.e. [CLI](../cli) and [shell](..
| `@session clear` | Clear all data but keep the settings. |
| `@session list` | List all sessions |
| `@session delete [<name>] [-a]` | Delete a session. If no session is specified, delete the current sessions.`-a` to delete all sessions. If the current session is deleted, a new session will be created. |
| `@session history <on/off>` | Turn history on/off for the current session |

### Constructions

Expand Down
1 change: 1 addition & 0 deletions ts/packages/dispatcher/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"music": "workspace:*",
"photo-agent": "workspace:*",
"proper-lockfile": "^4.1.2",
"string-width": "^7.2.0",
"telemetry": "workspace:*",
"typeagent": "workspace:*",
"typechat": "^0.1.1",
Expand Down
6 changes: 3 additions & 3 deletions ts/packages/dispatcher/src/handlers/common/appAgentManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,15 @@ export class AppAgentManager implements ActionConfigProvider {
return record.manifest.description;
}

public isTranslatorEnabled(schemaName: string) {
public isSchemaEnabled(schemaName: string) {
const appAgentName = getAppAgentName(schemaName);
const record = this.getRecord(appAgentName);
return record.schemas.has(schemaName);
}

public isTranslatorActive(schemaName: string) {
return (
this.isTranslatorEnabled(schemaName) &&
this.isSchemaEnabled(schemaName) &&
this.transientAgents[schemaName] !== false
);
}
Expand All @@ -188,7 +188,7 @@ export class AppAgentManager implements ActionConfigProvider {
);
}

private isActionEnabled(schemaName: string) {
public isActionEnabled(schemaName: string) {
const appAgentName = getAppAgentName(schemaName);
const record = this.getRecord(appAgentName);
return record.actions.has(schemaName);
Expand Down
Loading

0 comments on commit 45180fa

Please sign in to comment.