pinecall 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +167 -0
- data/LICENSE +202 -0
- data/README.md +140 -0
- data/lib/pinecall/agent/author.rb +31 -0
- data/lib/pinecall/agent/config.rb +124 -0
- data/lib/pinecall/agent/doc.rb +73 -0
- data/lib/pinecall/agent/knowledge.rb +18 -0
- data/lib/pinecall/agent/searching.rb +33 -0
- data/lib/pinecall/agent/spec.rb +133 -0
- data/lib/pinecall/agent/state.rb +185 -0
- data/lib/pinecall/agent/tools.rb +119 -0
- data/lib/pinecall/agent.rb +160 -0
- data/lib/pinecall/blocks.rb +152 -0
- data/lib/pinecall/bridge.rb +239 -0
- data/lib/pinecall/call_world/answers.rb +61 -0
- data/lib/pinecall/call_world/room.rb +25 -0
- data/lib/pinecall/call_world.rb +175 -0
- data/lib/pinecall/client/agent.rb +179 -0
- data/lib/pinecall/client/call.rb +140 -0
- data/lib/pinecall/client/connection.rb +190 -0
- data/lib/pinecall/client/endpoints.rb +30 -0
- data/lib/pinecall/client/listeners.rb +42 -0
- data/lib/pinecall/client/observe.rb +109 -0
- data/lib/pinecall/client/rest.rb +61 -0
- data/lib/pinecall/client.rb +212 -0
- data/lib/pinecall/errors.rb +53 -0
- data/lib/pinecall/panel.rb +138 -0
- data/lib/pinecall/reading.rb +37 -0
- data/lib/pinecall/rules.rb +38 -0
- data/lib/pinecall/serve/held.rb +40 -0
- data/lib/pinecall/serve/loading.rb +102 -0
- data/lib/pinecall/serve/viewing.rb +40 -0
- data/lib/pinecall/serve.rb +169 -0
- data/lib/pinecall/testing.rb +190 -0
- data/lib/pinecall/version.rb +6 -0
- data/lib/pinecall/view.rb +70 -0
- data/lib/pinecall/wire/codec.rb +75 -0
- data/lib/pinecall/wire/enums.rb +104 -0
- data/lib/pinecall/wire/errors.rb +12 -0
- data/lib/pinecall/wire/reduce.rb +249 -0
- data/lib/pinecall/wire/registry.rb +168 -0
- data/lib/pinecall/wire/shapes.rb +33 -0
- data/lib/pinecall/wire/shapes_call_events.rb +137 -0
- data/lib/pinecall/wire/shapes_commands.rb +114 -0
- data/lib/pinecall/wire/shapes_config.rb +70 -0
- data/lib/pinecall/wire/shapes_doors.rb +96 -0
- data/lib/pinecall/wire/shapes_events.rb +358 -0
- data/lib/pinecall/wire/shapes_metrics.rb +109 -0
- data/lib/pinecall/wire/shapes_parts.rb +340 -0
- data/lib/pinecall/wire/state.rb +56 -0
- data/lib/pinecall/wire/validate.rb +154 -0
- data/lib/pinecall/wire.rb +43 -0
- data/lib/pinecall.rb +45 -0
- data/sig/pinecall.rbs +453 -0
- metadata +119 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: ab6b509c4c3b476fdf67322bdef9e0c37d86893204ca487b5bb369aa0f7490eb
|
|
4
|
+
data.tar.gz: 05b84996a5e4b1deb8f73e254d539b51f0768f84dde7654ed35bb9b7dac95967
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: '07945d49d0bcc224e39f5f6976e34ed9ff9cbf6cec56b0b1d8151ac7d0f538561fadaff755a8d0d52cf9d9b8ac5e0c323dcaff8267a28092776ff9677db5c61e'
|
|
7
|
+
data.tar.gz: 04d24ebd3800a149e3958fb34719b7daae2be9d6405c236cb3a297ba44e120ea7f168ba181a7291a9a4cdc002739d83889b3a97aa24476e4350d8a4529888ef2
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
Every change a person using this gem would notice. The format is
|
|
4
|
+
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/); nothing is versioned yet, because a
|
|
5
|
+
version number is the human's call.
|
|
6
|
+
|
|
7
|
+
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
## [0.0.1] — The first release: an agent as a Ruby class (2026-10-09)
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
- **The tutorial prints the prompt the gem sends**: the framework's rules and the channel's words
|
|
13
|
+
are in English, and the `<channel>` block was missing. Its `Pinecall::Client` example no longer
|
|
14
|
+
needs `PINECALL_URL`, which `pinecall link` writes only for a gateway other than Pinecall's.
|
|
15
|
+
- **`pinecall start` drains a Ruby agent whole on Ctrl-C or a SIGTERM.** The CLI passes the signal on
|
|
16
|
+
and closes the child's stdin together, and the serve entry took the second as "leave now": it
|
|
17
|
+
closed the socket mid-drain, with tools still running. Only a second signal cuts a drain short,
|
|
18
|
+
as in TypeScript; the drain line is printed. The serve entry no longer prints its own
|
|
19
|
+
`answering on` line, which the CLI already says.
|
|
20
|
+
- **Leaving after the socket closed is quiet.** When the gateway's socket closed just before the
|
|
21
|
+
drain was asked, `pinecall test` and `chat` ended with `Pinecall::NotConnected: agent.drain: the
|
|
22
|
+
gateway is not connected`; a drain with no socket has nothing to hand over, and says so.
|
|
23
|
+
- **A judged call's score reaches the agent.** The runtime's `call.score` says which judge model
|
|
24
|
+
gave it (`judged_by`), and the gem refused the field: `pinecall simulate --judge` and every
|
|
25
|
+
judged call printed `CallScore has no field called judged_by` and dropped the score.
|
|
26
|
+
- **`pinecall start`, `chat` and `test` see a Ruby agent register.** The serve entry's lines went
|
|
27
|
+
to a pipe's buffered `$stdout` and reached the CLI only when the process left, so every verb
|
|
28
|
+
that waits for `agent.registered` gave up after 30 seconds. Each line is flushed now.
|
|
29
|
+
- **A voice call whose vendor fails over no longer stops the agent.** The runtime writes
|
|
30
|
+
`vendor.switched` when a stage's fallback switches vendor, and the gem did not know the type: the
|
|
31
|
+
socket raised `unknown event type` mid-call. `vendor.switched` and `spend.unusual` are in the
|
|
32
|
+
wire now, both left to `call.on` and `client.on_any`.
|
|
33
|
+
|
|
34
|
+
### Changed
|
|
35
|
+
- **Breaking: the language is the world's, and the prompt says how to write for the channel** — as
|
|
36
|
+
the TypeScript package's 0.9.19. `language :es` is refused at load (`pinecall agent set
|
|
37
|
+
--language es`); the rules and protocols are English for every agent and tell the model to answer
|
|
38
|
+
in the caller's language; the `identity` block gains `<channel>`: speech, a website's Markdown, or
|
|
39
|
+
WhatsApp's formatting, by the call's channel and `medium`. `channel_rules false` leaves it out.
|
|
40
|
+
`call.started.medium` is in the wire (the runtime sends it from this release on, and a gem without
|
|
41
|
+
it refuses every call), on `CallWorld#medium` and `Client::Call#medium`; serve's `prompt` takes
|
|
42
|
+
`--medium`. `language` is no longer in `agent.configure`.
|
|
43
|
+
- **Breaking: no CLI, no console, no executable.** The verbs are the one `pinecall` CLI's (npm),
|
|
44
|
+
the same for a Ruby project as for a TypeScript one, in the same layout
|
|
45
|
+
(`agents/<slug>/agent.rb`): for `prompt`, `chat`, `test` and `start` it runs `Pinecall::Serve`.
|
|
46
|
+
`exe/pinecall`, `bin/pinecall`, the vendored console and `pinecall ui`, `run`, `whoami`,
|
|
47
|
+
`knowledge`, `memory`, `remember` and `keys` are gone, and so are `Client#knowledge`,
|
|
48
|
+
`#memory_of`, `#memory` and `#provider_keys`: those doors are the CLI's verbs.
|
|
49
|
+
- **Breaking: `Pinecall::Client.new` reads nothing from the environment.** It takes `url:`,
|
|
50
|
+
`api_key:` and `env:` (`"production"` names production for a person's key); the serve entry
|
|
51
|
+
reads `PINECALL_KEY`, and no other key variable is read anywhere.
|
|
52
|
+
- **Breaking: a call opens in the state its `call.started` carries.** `Pinecall.mount` takes no
|
|
53
|
+
`opening:`: the state a golden, a persona or a chat's `?state=` asked for rides the call, and the
|
|
54
|
+
bridge applies it after `on_call` and before the first render. `Testing::Gateway#call_started`
|
|
55
|
+
takes `state:`.
|
|
56
|
+
- **No `pinecall-protocol` dependency.** The gem keeps the runtime's wire it speaks in
|
|
57
|
+
`lib/pinecall/wire/` (`Pinecall::Wire`: the shapes, the validator, the codec, the reducer), held
|
|
58
|
+
to the runtime's golden call log; `Pinecall::Protocol` is `Pinecall::Wire` and `ProtocolError` is
|
|
59
|
+
`WireError`.
|
|
60
|
+
- **Breaking: the class is code, the world is environment.** A class declares the contract — its
|
|
61
|
+
`language`, `state` and `stage`, its `tool`s, `accepts`, its view — and nothing it runs on.
|
|
62
|
+
`voice`, `llm`, `stt`, `greeting`, `hangup`, `says`, `hears`, `memory`, `record`, `knowledge`
|
|
63
|
+
and `docs` in a class body now raise `DeclarationRefused` when the class loads, before a prompt
|
|
64
|
+
is printed or a gateway is knocked at, naming the verb that sets each instead:
|
|
65
|
+
`` `voice` is the world's now, not the class's: pinecall agent set --voice <name> — remove it
|
|
66
|
+
from the class``. What to run instead, per world, with the Node CLI or the console's Settings:
|
|
67
|
+
`pinecall agent set --voice | --llm | --stt | --greeting '…' (or --reply '…') | --hangup '…' |
|
|
68
|
+
--record on|off`, `pinecall lexicon add <word> --say '…'` and `pinecall lexicon hear <word>`,
|
|
69
|
+
`pinecall memory policy --remember '…' --forget '…'`, `pinecall agent knowledge edit` for what
|
|
70
|
+
the agent knows by heart, and `pinecall docs attach <base>` for the base it searches. None of
|
|
71
|
+
them travels on `agent.configure` any more, and the `knowledge` block is the gateway's to fill:
|
|
72
|
+
the class sends nothing for it, so `pinecall prompt` prints it empty.
|
|
73
|
+
- **A class declares no doors.** `phone`, `whatsapp` and `web` still load and are read by nobody:
|
|
74
|
+
`agent.register` carries no routes from the class, and nothing counts them. A
|
|
75
|
+
number is pointed at an agent with `pinecall numbers import <+34…> --agent <slug>`, and every
|
|
76
|
+
agent can be talked to from a page.
|
|
77
|
+
|
|
78
|
+
### Added
|
|
79
|
+
- **The console's panel: `panel "Cliente" do |who| … end`**, as the TypeScript package's `@view`.
|
|
80
|
+
The block draws with the console's catalogue — `panel`, `rows`, `row`, `stat`, `table`, `badge`,
|
|
81
|
+
`text` — and the nodes are the same JSON, drawn by the console's own parts. The gateway is told the
|
|
82
|
+
panel's name; serve's `start` answers `view.render` with it, and refuses every other console verb
|
|
83
|
+
as the TypeScript entry does. A class without one is the 404 the console falls back from.
|
|
84
|
+
- **`agent.on_dev { |verb, data| … }`** answers a console's ask (raise `DevRefused` to refuse with a
|
|
85
|
+
status); without one an ask is a 501 saying this process answers none. It replaces the fixed "a
|
|
86
|
+
Ruby agent draws no panel".
|
|
87
|
+
- **`client.on_connected`**, each time the socket is up and every agent on it registered.
|
|
88
|
+
- **`call.opt_out(note)`**: the caller's number joins the org's do-not-call list (`call.opt_out`).
|
|
89
|
+
- **`Pinecall::Serve`, the entry the one `pinecall` CLI starts a Ruby agent with**:
|
|
90
|
+
`start --file --slug [--console] [--events] [--prod]` holds the agents (its door from
|
|
91
|
+
`PINECALL_URL`, `PINECALL_KEY`, `PINECALL_ENV` alone; the wire entry by entry on stdout with
|
|
92
|
+
`--events`; leaves draining on a signal or the end of its stdin) and `prompt --file --slug
|
|
93
|
+
[--state field=json]… [--show-machine]` prints a prompt. `Pinecall.serve(klass, url:, api_key:,
|
|
94
|
+
env:)` holds one inside your own Ruby process. The client gains `drain`, `on_entries`,
|
|
95
|
+
`on_stopped` and the `pinecall-env` header, registers its machine as `host`, and answers a
|
|
96
|
+
console's ask with `a Ruby agent draws no panel`. `docs/production.md` says how a server runs it.
|
|
97
|
+
- **A call handed over mid-conversation is served.** On `call.attached` (another process drained
|
|
98
|
+
or died) the agent opens in the state the gateway kept, with no `on_call`; one this process
|
|
99
|
+
already serves sends its whole prompt again. A call knows the code it claimed (`call.claimed`)
|
|
100
|
+
and the eval run that opened it. `Testing::Gateway#call_attached(state:)`.
|
|
101
|
+
- **`examples/clinica_norte` is the TypeScript example's agent, in Ruby**, in the one CLI's layout
|
|
102
|
+
(`agents/clinica-norte/`, `docs/clinica-norte/`, `test/clinica-norte/`): the same agenda —
|
|
103
|
+
specialties, slots booked by id, a day resolved to a date — the same documents, the same three
|
|
104
|
+
extraction cases and the same eleven goldens. `rake ring1` runs them through the CLI.
|
|
105
|
+
- A stage restored from JSON — a golden's, `call.started.state` — is the declared stage it names.
|
|
106
|
+
- **The whole call.** `call.transfer(to, mode:)` and `call.attention(reason, wait_s:)` block until
|
|
107
|
+
the log answers (a `Transferred`, an `Attended`); `call.hold`, `unhold`, `dtmf(digits)`,
|
|
108
|
+
`claim(code)` (then `call.claimed`) and `callback(number, at:, note:)` are one command each.
|
|
109
|
+
`knowledge.search(query, k:)` — or `call.search` — searches the bases attached to the agent
|
|
110
|
+
through the gateway, and a class that searches registers `uses_knowledge`. The view is rendered
|
|
111
|
+
again on the caller's turn, on a claim and on recall, and reads `call[:claimed]`. The call ending
|
|
112
|
+
answers every verb still waiting. `Testing::Gateway#finds` and `#searched` for ring 0.
|
|
113
|
+
- The wire reads `call.started`'s `worker`, which the runtime writes on every spoken call: until
|
|
114
|
+
now a Ruby app refused a phone call's first entry.
|
|
115
|
+
- The wire reads `call.started`'s `state`, the state a call opens in when its opener asked for
|
|
116
|
+
one, and `agent.register` may carry `answers_dev`. Nothing sends or reads either yet.
|
|
117
|
+
- **`pinecall remember [PATHS]`**, and `client.memory.extraction(slug, cases)` — the goldens
|
|
118
|
+
the memory policy is held to, which is the write side and the half that persists. A case is one
|
|
119
|
+
call already held (both speakers, in `said`), the facts memory already holds (`holds`), and what
|
|
120
|
+
must come of the hang-up's one model call: which categories got a fact (`writes`), which never
|
|
121
|
+
did (`never`), which values must not survive in any fact's text (`never_says`), and which held
|
|
122
|
+
facts the call contradicted (`invalidates`) — its mirror included, so a model that supersedes
|
|
123
|
+
whatever it touches is caught too. A case may `plants` sentences somebody tried to get into
|
|
124
|
+
memory, and planting one IS the assertion that admission refuses it. Nothing asks a model whether
|
|
125
|
+
two sentences mean the same thing: a category is your own word, a value is a literal, a
|
|
126
|
+
supersession is an id. The class is mounted in this terminal, because the tool names admission
|
|
127
|
+
refuses a fact for are the class's own declaration; the one
|
|
128
|
+
model call per case runs in the gateway on the org's keys. Exits 1 when a case did not hold.
|
|
129
|
+
`test/memory` beside the `agent.rb` by default; Clínica Norte ships three.
|
|
130
|
+
- `pinecall memory eval [GOLDEN] [--k N]`, and `client.memory.eval`: the other table's golden.
|
|
131
|
+
A list of `{ "holds", "asks", "expects" }` — what memory holds about a question's contact, what
|
|
132
|
+
the caller said, and the fact or facts that should come back — asked of `recall`, and `recall@k`
|
|
133
|
+
and `nDCG@10` printed, computed by code with no model. No contact of the org is read or written:
|
|
134
|
+
each question's facts go to a scratch contact and are deleted again, which is what makes the
|
|
135
|
+
figures the real ranking. A fact answers when what came back CONTAINS what was expected, folded
|
|
136
|
+
for case, accents and whitespace, because a fact is a sentence a model wrote. Names every
|
|
137
|
+
question memory did not answer whole with what came back instead and exits 1 when anything did.
|
|
138
|
+
Clínica Norte ships one of seven questions, eight or nine facts each.
|
|
139
|
+
- `pinecall knowledge eval [GOLDEN] [--base NAME] [--k N]`, and `client.knowledge.eval`: every
|
|
140
|
+
question of a golden asked of the base, and `recall@k` and `nDCG@10` printed — computed by code
|
|
141
|
+
with no model, so two runs answer the same numbers. Names every question it missed with what came
|
|
142
|
+
back instead and exits 1 when anything did, so a base can be held to its golden in CI. Clínica
|
|
143
|
+
Norte ships one. A base listing now names the embedder that wrote its vectors.
|
|
144
|
+
|
|
145
|
+
- The package itself: `Pinecall::Agent` (config on the class, state on the instance, `tool` above
|
|
146
|
+
the method, the comment as the docstring), the ERB view resolved as `views/<slug>.erb`,
|
|
147
|
+
`Pinecall.mount`, `Pinecall::Client`, and `pinecall/testing` — the gateway that is not there,
|
|
148
|
+
which is what a ring-0 suite mounts against.
|
|
149
|
+
- The prompt as four named blocks in two regions: `identity` · `knowledge` · `tools` (static,
|
|
150
|
+
cached), the history, `view` (dynamic). The bridge sends each block by name and only when its
|
|
151
|
+
text changed. `Pinecall.render` returns `Blocks` (`[:name]`, `static`, `dynamic`,
|
|
152
|
+
`instructions`); `pinecall prompt` prints one section per block. In a test,
|
|
153
|
+
`call.block("knowledge")`.
|
|
154
|
+
- `pinecall-protocol`: Ruby's side of the wire, generated from the same JSON Schema as the Python
|
|
155
|
+
and TypeScript packages, with the log reducer proved against the same golden fixture.
|
|
156
|
+
- `sig/`: the public surface as RBS, checked by `rake rbs`.
|
|
157
|
+
- `examples/clinica_norte`: a whole agent, its view, and its own ring-0 suite.
|
|
158
|
+
- **A lookup is a tool result, never a piece of the prompt.** What memory kept from an earlier
|
|
159
|
+
call and what the knowledge base returned no longer travel through the view: the platform runs
|
|
160
|
+
its own `recall` and `search` tools and their answers reach the model as `tool_result` blocks,
|
|
161
|
+
JSON, in the history — which is where both vendors say content from outside the conversation
|
|
162
|
+
belongs (`runtime/docs/security/prompt-injection.md`). So a view is now the tenant's own prose
|
|
163
|
+
and conditions and nothing else: the `memory`, `retrieved` and `knowledge` template tags are
|
|
164
|
+
gone, and so are the tenant-declared blocks (`prompt static:`/`dynamic:`) and the render props
|
|
165
|
+
that came with them. What a view may still do with memory is ask it a question —
|
|
166
|
+
`remembers?("médico habitual")`, answered by the runtime — and say a sentence of its own about
|
|
167
|
+
the answer.
|
data/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 Pinecall
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
data/README.md
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# pinecall
|
|
2
|
+
|
|
3
|
+
Build voice agents as Ruby classes. Declared fields are the agent's state, `tool` methods are
|
|
4
|
+
what the model can call, the comment above each tool is its description, and an ERB view renders
|
|
5
|
+
the part of the prompt that changes during the call.
|
|
6
|
+
|
|
7
|
+
```ruby
|
|
8
|
+
require "pinecall"
|
|
9
|
+
|
|
10
|
+
# Eres la recepción de Clínica Norte. Hablas de usted, con frases cortas.
|
|
11
|
+
class ClinicaNorte < Pinecall::Agent
|
|
12
|
+
stage :identify, :book
|
|
13
|
+
state :patient, visibility: :pii
|
|
14
|
+
state :slots, []
|
|
15
|
+
|
|
16
|
+
# Busca al paciente por nombre y teléfono. Pide los dos antes de llamarla.
|
|
17
|
+
tool stage: :identify, pii: %i[name phone]
|
|
18
|
+
def find_patient(name:, phone:)
|
|
19
|
+
self.patient = Agenda.buscar(name, phone)
|
|
20
|
+
self.stage = :book if patient
|
|
21
|
+
patient
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Horas libres de un día.
|
|
25
|
+
tool stage: :book, preview: 2
|
|
26
|
+
def free_slots(day:)
|
|
27
|
+
self.slots = Agenda.libres(day)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
`views/clinica-norte.erb` renders the prompt from that state:
|
|
33
|
+
|
|
34
|
+
```erb
|
|
35
|
+
<% if stage == :identify -%>
|
|
36
|
+
Saluda y pide nombre y teléfono. Nada más hasta identificar al paciente.
|
|
37
|
+
<% end -%>
|
|
38
|
+
|
|
39
|
+
<% if remembers?("médico habitual") -%>
|
|
40
|
+
Ofrece primero las horas de su médico habitual.
|
|
41
|
+
<% end -%>
|
|
42
|
+
|
|
43
|
+
<% if slots.any? -%>
|
|
44
|
+
## Horas libres, en orden
|
|
45
|
+
|
|
46
|
+
<% slots.each do |hueco| -%>
|
|
47
|
+
<%= hueco.cuando %> con <%= hueco.doctor %>
|
|
48
|
+
<% end -%>
|
|
49
|
+
<% end -%>
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
The prompt has four named blocks: `identity`, `knowledge` and `tools` are static and cached
|
|
53
|
+
before the history; `view` comes after it and is replaced every turn. A block is re-sent only when
|
|
54
|
+
its text changes.
|
|
55
|
+
|
|
56
|
+
Memory and knowledge-base results never enter the prompt. The platform runs `recall` and `search`
|
|
57
|
+
and returns their results to the model as tool results, so retrieved text is treated as data, not
|
|
58
|
+
instructions. A view can ask `remembers?("médico habitual")` and write its own sentence about the
|
|
59
|
+
answer.
|
|
60
|
+
|
|
61
|
+
## Five minutes
|
|
62
|
+
|
|
63
|
+
This gem is a library: the verbs are the one `pinecall` CLI's, the same for every language. In a
|
|
64
|
+
project laid out as `agents/<name>/agent.rb`, with this gem in its `Gemfile`:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
bundle add pinecall
|
|
68
|
+
npm i -g pinecall # the CLI: Node, whatever the agent is written in
|
|
69
|
+
pinecall link # this folder tied to your org: its key, in ./.env
|
|
70
|
+
pinecall prompt --state test/<name>/goldens/a.json # the exact prompt a state produces. No gateway.
|
|
71
|
+
pinecall chat # the agent served from this terminal, and a caller against it
|
|
72
|
+
pinecall test # ring 1: the goldens, scored by the gateway
|
|
73
|
+
pinecall start # registered and answering: the process you deploy
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
The CLI never loads your class: for `prompt`, `chat`, `test` and `start` it runs this gem's serve
|
|
77
|
+
entry, `bundle exec ruby -r pinecall -e 'exit Pinecall::Serve.main(ARGV)'`, and talks to it through
|
|
78
|
+
the gateway. The console, the knowledge bases, memory, keys and every other verb are the CLI's.
|
|
79
|
+
How a server runs the agent, with the CLI or inside your own Ruby process, is
|
|
80
|
+
[docs/production.md](docs/production.md).
|
|
81
|
+
|
|
82
|
+
## Architecture
|
|
83
|
+
|
|
84
|
+
This gem is the application side. It never talks to a model vendor or handles audio: it sends
|
|
85
|
+
commands and reads log entries over one WebSocket, in the runtime's own wire (`lib/pinecall/wire/`),
|
|
86
|
+
held to the runtime's golden call log. Tools are the only code that may change state.
|
|
87
|
+
|
|
88
|
+
| you want | you use |
|
|
89
|
+
|---|---|
|
|
90
|
+
| the class and the view | `Pinecall::Agent`, `Pinecall.mount` |
|
|
91
|
+
| the agent held inside your own process | `Pinecall.serve` |
|
|
92
|
+
| the socket alone, your own way of deciding what to answer | `Pinecall::Client` |
|
|
93
|
+
| a suite with no network, no key and no model | `pinecall/testing` |
|
|
94
|
+
|
|
95
|
+
```ruby
|
|
96
|
+
pc = Pinecall::Client.new(url: "https://cloud.pinecall.io", api_key: ENV.fetch("PINECALL_KEY"))
|
|
97
|
+
agent = pc.agent("clinica-norte", tools: [])
|
|
98
|
+
agent.on("turn.user") { |data, call| call.say("Le he oído: #{data[:text]}") }
|
|
99
|
+
pc.connect
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Testing it
|
|
103
|
+
|
|
104
|
+
Agent tests run with no network, key, model or gateway:
|
|
105
|
+
|
|
106
|
+
```ruby
|
|
107
|
+
require "pinecall/testing"
|
|
108
|
+
|
|
109
|
+
gateway = Pinecall::Testing::Gateway.new
|
|
110
|
+
Pinecall.mount(ClinicaNorte, client: gateway)
|
|
111
|
+
|
|
112
|
+
call = gateway.call_started(from: "+34600123456")
|
|
113
|
+
call.tool("free_slots", day: "martes")
|
|
114
|
+
|
|
115
|
+
assert_includes call.prompt, "el martes a las diez"
|
|
116
|
+
assert_equal %w[propose], call.tools
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Where the rest is
|
|
120
|
+
|
|
121
|
+
| what | where |
|
|
122
|
+
|---|---|
|
|
123
|
+
| tutorial: an agent with knowledge and memory, from an empty directory | [docs/tutorial.md](docs/tutorial.md) |
|
|
124
|
+
| every file, entity and rule | [ARCHITECTURE.md](ARCHITECTURE.md) |
|
|
125
|
+
| how to write an agent, step by step | [docs/writing-an-agent.md](docs/writing-an-agent.md) |
|
|
126
|
+
| the view, and the blocks of a prompt | [docs/the-view.md](docs/the-view.md) |
|
|
127
|
+
| how to test one | [docs/testing-an-agent.md](docs/testing-an-agent.md) |
|
|
128
|
+
| running it in production | [docs/production.md](docs/production.md) |
|
|
129
|
+
| the CLI, verb by verb | the one CLI's reference, at docs.pinecall.io |
|
|
130
|
+
| a complete example agent | [examples/clinica_norte](examples/clinica_norte) |
|
|
131
|
+
| the wire itself | `lib/pinecall/wire/`, the runtime's shapes this gem speaks |
|
|
132
|
+
|
|
133
|
+
## Requirements
|
|
134
|
+
|
|
135
|
+
Ruby 3.2+. The only runtime dependency is `websocket-driver` (the driver ActionCable uses). The
|
|
136
|
+
`pinecall` CLI is a Node program (Node 24+): the verbs need it, the library does not.
|
|
137
|
+
|
|
138
|
+
## License
|
|
139
|
+
|
|
140
|
+
[Apache-2.0](LICENSE), including its patent grant. No CLA.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Pinecall
|
|
4
|
+
class Agent
|
|
5
|
+
# Tracks who is writing state, so each write is attributed to its tool or hook.
|
|
6
|
+
#
|
|
7
|
+
# Uses fiber storage, not a module variable: concurrent calls must not see each other's author.
|
|
8
|
+
# `Fiber[]` is inherited by child fibers and separate per thread.
|
|
9
|
+
module Author
|
|
10
|
+
KEY = :pinecall_author
|
|
11
|
+
|
|
12
|
+
module_function
|
|
13
|
+
|
|
14
|
+
# The current author, or nil.
|
|
15
|
+
def current
|
|
16
|
+
Fiber[KEY]
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Run the block with state writes attributed to `name`.
|
|
20
|
+
def with(name)
|
|
21
|
+
held = Fiber[KEY]
|
|
22
|
+
Fiber[KEY] = name
|
|
23
|
+
begin
|
|
24
|
+
yield
|
|
25
|
+
ensure
|
|
26
|
+
Fiber[KEY] = held
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|