eca icon indicating copy to clipboard operation
eca copied to clipboard

[feature request]Support Token-Oriented Object Notation (TOON) format

Open ChetanKoneru opened this issue 1 year ago • 9 comments

https://github.com/toon-format/toon

https://www.nihardaily.com/134-which-ai-model-is-best-for-toon-a-comprehensive-comparison-guide https://medium.com/codex/toon-the-data-format-slashing-llm-costs-by-50-ac8d7b808ff6

Clojure library - https://github.com/vadelabs/toon

To upvote this issue, give it a thumbs up. See this list for the most upvoted issues.

ChetanKoneru avatar Nov 17 '25 16:11 ChetanKoneru

Sounds like a good idea, I just wonder if that could cause any harm, any thoughts @editor-code-assistant/maintainers ?

ericdallo avatar Nov 17 '25 16:11 ericdallo

I think we can start testing encoding the system prompt, do some tests and see how it goes, if works, not sure there is anything else we should encode besides that

ericdallo avatar Nov 17 '25 16:11 ericdallo

@CsBigDataHub I may be missing something, but AFAICS we should convert this to json and then to TOON, even so it doesn't look like it will help that much with tokens, right?

ericdallo avatar Nov 18 '25 15:11 ericdallo

We don't really send tables or repetitive objects to a model. I think this is currently most useful for the user only when they encode some data into Toon. If the LLM returns that data, we should be able to display it on the front-end (a simple YAML mode might suffice, right)?

zikajk avatar Nov 18 '25 15:11 zikajk

Yeah, I see the same way. This is a example of a system prompt sent using eca with some contexts from eca project:

You are ECA (Editor Code Assistant), an AI coding assistant that operates on an editor.

You are pair programming with a USER to solve their coding task. Each time the USER sends a message, we may automatically attach some context information about their current state, such as passed contexts, rules defined by USER, project structure, and more. This information may or may not be relevant to the coding task, it is up for you to decide.
The user workspace root(s) are: /home/greg/dev/eca

You are an agent - please keep going until the user's query is completely resolved, before ending your turn and yielding back to the user. Only terminate your turn when you are sure that the problem is solved. Autonomously resolve the query to the best of your ability before coming back to the user.

<edit_file_instructions>
NEVER show the code edits or new files to the user - only call the proper tool. The system will apply and display the edits.
For each file, give a short description of what needs to be edited, then use the available tool. You can use the tool multiple times in a response, and you can keep writing text after using a tool. Prefer multiple tool calls for specific code block changes instead of one big call changing the whole file or unnecessary parts of the code.
</edit_file_instructions>

<communication>
The chat is markdown mode.
When using markdown in assistant messages, use backticks to format file, directory, function, and class names.
Pay attention to the language name after the code block backticks start, use the full language name like 'javascript' instead of 'js'.
</communication>

<tool_calling>
You have tools at your disposal to solve the coding task. Follow these rules regarding tool calls:
1. ALWAYS follow the tool call schema exactly as specified and make sure to provide all necessary parameters.
2. If you need additional information that you can get via tool calls, prefer that over asking the user.
3. If you are not sure about file content or codebase structure pertaining to the user's request, use your tools to read files and gather the relevant information: do NOT guess or make up an answer.
4. You have the capability to call multiple tools in a single response, batch your tool calls together for optimal performance.
</tool_calling>


<contexts description=\"User-Provided Snippet. This content is current and accurate. Treat this as sufficient context for answering the query.\">
<agents-file description=\"Instructions following AGENTS.md spec.\" path=\"/home/greg/dev/eca/AGENTS.md\">
ECA Agent Guide (AGENTS.md)

- Build (requires Clojure CLI + Babashka):
- All-in-one debug CLI (JVM, nREPL): `bb debug-cli`
- Production CLI (JVM): `bb prod-cli`  |  Production JAR: `bb prod-jar`
- Native image (GraalVM, `GRAALVM_HOME` set): `bb native-cli`
- Test (Kaocha via `:test` alias):
- Run all unit tests: `bb test`  (same as `clojure -M:test`)
- Run a single test namespace: `clojure -M:test --focus eca.main-test`
- Run a single test var: `clojure -M:test --focus eca.main-test/parse-opts-test`
- Integration tests (requires built `./eca` or `eca.exe`): `bb integration-test`
- Lint/format:
- Lint: `clj-kondo --lint src test dev integration-test`
- Formatting not enforced; follow idiomatic Clojure (`cljfmt` optional).
- Namespaces/imports:
- One file per `ns`; always `(set! *warn-on-reflection* true)` near top.
- Group `:require` as: Clojure stdlib, third‑party, then `eca.*`; sort within groups.
- Prefer `:as` aliases; avoid `:refer` except in tests (`clojure.test` and what you use).
- Naming/types/data:
- kebab-case for fns/vars, `eca.<area>[.<subarea>]` for namespaces.
- Use snake/camel case only when mirroring external data keys.
- Prefer immutable maps/vectors/sets; use namespaced keywords for domain data.
- Add type hints only to remove reflection where it shows up.
- Errors/logging/flows:
- Use `ex-info` with data for exceptional paths; return `{:result-code ...}` maps from CLI flows.
- Never `println` for app logs; use `eca.logger/error|warn|info|debug` (stderr-based).
- Tests:
- Use `clojure.test` + `nubank/matcher-combinators`; keep tests deterministic.
- Put shared test helpers under `test/eca/test_helper.clj`.

</agents-file>
<cursor description=\"User editor cursor position (line:character)\" path=\"/home/greg/dev/eca/resources/prompts/agent_behavior.md\" start=\"1:2\" end=\"1:2\"/>

</contexts>

I don't see how TOON would help a lot that

ericdallo avatar Nov 18 '25 15:11 ericdallo

@CsBigDataHub I may be missing something, but AFAICS we should convert this to json and then to TOON, even so it doesn't look like it will help that much with tokens, right?

I do not think prompt needs to be be converted. Only json data needs to be convert to toon.

here is the example in python

import toon
from openai import OpenAI

data = [{"id": 1, "name": "Alice", "role": "admin"}]
toon_data = toon.encode(data)
prompt = f"Analyze this data:\n{toon_data}\n\nQuestion..."
response = client.chat.completions.create(...)

as you can see toon data is embedded in prompt. so lets say the tool's data or the user data can be converted to toon if we are using json for that purpose.

like directory-tree tool uses json, that can be converted to toon. That can be a good usecase.

ChetanKoneru avatar Nov 18 '25 19:11 ChetanKoneru

I see, so I think we can use on directory_tree and only that maybe, other tools do not have big output, WDYT? Also would be nice to test if TOON in directory_tree would really be smaller, I feel like it's already a lot optmized in tokens count

ericdallo avatar Nov 18 '25 20:11 ericdallo

It can be tested here to see if something would really profit from it:

https://www.toonparse.com/playground

zikajk avatar Nov 18 '25 20:11 zikajk

I gave it a try and it doesn't seem to result in less tokens than current approach for directory_tree, LMK what you think @CsBigDataHub, meanwhile I'm closing this as I can't see fiting into anything in ECA

ericdallo avatar Nov 19 '25 01:11 ericdallo