Compare commits

..

2866 Commits

Author SHA1 Message Date
Codex 3fb54b662f docs: refresh planner priorities for 4351
Harness (E2E) / Harnesses (mock LLM) (push) Waiting to run
Harness (E2E) / Provider harnesses (live LLM conformance) (push) Waiting to run
Lint / golangci-lint (push) Waiting to run
Run Tests / Unit Tests (push) Waiting to run
Run Tests / Etcd Integration Tests (push) Waiting to run
2026-07-08 12:43:57 +00:00
Asim Aslam 415e95c0f1 test agent startup resume checkpoints (#4350)
Co-authored-by: Codex <codex@openai.com>
2026-07-08 13:20:15 +01:00
Asim Aslam 36c42d0cfa docs: refresh planner priorities for 4345 (#4346)
Co-authored-by: Codex <codex@openai.com>
2026-07-08 12:50:35 +01:00
Asim Aslam 459dff8e7a ci: add first-agent CLI wayfinding target (#4344)
Co-authored-by: Codex <codex@openai.com>
2026-07-08 12:26:26 +01:00
Asim Aslam 6c74ae0f9c docs: refresh planner priorities for 4340 (#4342)
Co-authored-by: Codex <codex@openai.com>
2026-07-08 11:55:34 +01:00
Asim Aslam 224e107f1c Stabilize plan-delegate notify recovery (#4339)
Co-authored-by: Codex <codex@openai.com>
2026-07-08 11:28:41 +01:00
Asim Aslam e0b9f1323f docs: refresh planner priorities for 4335 (#4337)
Co-authored-by: Codex <codex@openai.com>
2026-07-08 11:00:58 +01:00
Asim Aslam 35d3d99428 Fail agent-flow on missing onboarding side effects (#4334)
Co-authored-by: Codex <codex@openai.com>
2026-07-08 10:30:24 +01:00
Asim Aslam 656c0ce9d6 docs: refresh planner priorities for 4331 (#4332)
Co-authored-by: Codex <codex@openai.com>
2026-07-08 10:05:26 +01:00
Asim Aslam 7734f5605d Verify zero-to-hero deploy dry-run (#4330)
Co-authored-by: Codex <codex@openai.com>
2026-07-08 09:26:45 +01:00
Asim Aslam affd61e69b docs: refresh coherence changelog (#4326)
Co-authored-by: Codex <codex@openai.com>
2026-07-08 08:57:36 +01:00
Asim Aslam 171da77817 docs: refresh planner priorities for 4319 (#4320)
Co-authored-by: Codex <codex@openai.com>
2026-07-08 08:03:31 +01:00
Asim Aslam 83a6b2004a Propagate provider HTTP retry signals (#4318)
Co-authored-by: Codex <codex@openai.com>
2026-07-08 06:43:28 +01:00
Asim Aslam ae5ead7914 docs: refresh planner priorities for 4314 (#4316)
Co-authored-by: Codex <codex@openai.com>
2026-07-08 06:16:36 +01:00
Asim Aslam a1d17ec984 Avoid recording failed stream turns (#4313)
Co-authored-by: Codex <codex@openai.com>
2026-07-08 04:57:10 +01:00
Asim Aslam a8b89c2142 docs: refresh planner priorities for 4308 (#4310)
Co-authored-by: Codex <codex@openai.com>
2026-07-08 04:06:25 +01:00
Asim Aslam 76fea3f01c agent: parse function-style text tool calls (#4307)
Co-authored-by: Codex <codex@openai.com>
2026-07-08 03:29:12 +01:00
Asim Aslam a5f8ff518d docs: refresh planner priorities for 4304 (#4305)
Co-authored-by: Codex <codex@openai.com>
2026-07-08 02:40:13 +01:00
Asim Aslam cf9c015cf8 ci: add docs wayfinding guard (#4303)
Co-authored-by: Codex <codex@openai.com>
2026-07-08 02:12:09 +01:00
Asim Aslam 7248270f28 docs: refresh planner priorities for 4300 (#4301)
Co-authored-by: Codex <codex@openai.com>
2026-07-08 01:48:45 +01:00
Asim Aslam 243d7904e8 Fix plan-delegate notify recovery (#4299)
Co-authored-by: Codex <codex@openai.com>
2026-07-08 01:00:03 +01:00
Asim Aslam 364fb33cc8 docs: refresh planner priorities for 4290 (#4292)
goreleaser / goreleaser (push) Waiting to run
Co-authored-by: Codex <codex@openai.com>
2026-07-07 23:37:43 +01:00
Asim Aslam 7697b2587c Wire universe harness services to shared broker (#4289)
Co-authored-by: Codex <codex@openai.com>
2026-07-07 23:08:10 +01:00
Asim Aslam fa36114d73 docs: refresh planner priorities for 4286 (#4287)
Co-authored-by: Codex <codex@openai.com>
2026-07-07 22:44:12 +01:00
Asim Aslam 5c5186a230 Add agent debugging quickcheck docs (#4285)
Co-authored-by: Codex <codex@openai.com>
2026-07-07 22:17:15 +01:00
Asim Aslam 58a76bc32f docs: refresh planner priorities for 4280 (#4281)
Co-authored-by: Codex <codex@openai.com>
2026-07-07 21:48:53 +01:00
Asim Aslam 2c562c8827 Add scaffold check to zero-to-hero harness (#4279)
Co-authored-by: Codex <codex@openai.com>
2026-07-07 21:24:27 +01:00
Asim Aslam ff1c6173cd docs: refresh planner priorities for 4271 (#4275)
Co-authored-by: Codex <codex@openai.com>
2026-07-07 20:41:27 +01:00
Asim Aslam 2c7b2dbe51 Harden text tool call parsing for AtlasCloud (#4270)
Co-authored-by: Codex <codex@openai.com>
2026-07-07 20:24:31 +01:00
Asim Aslam c51d53f5ec docs: refresh planner priorities for 4267 (#4268)
Co-authored-by: Codex <codex@openai.com>
2026-07-07 19:55:16 +01:00
Asim Aslam 6a25bbfc05 docs: link website first-agent examples map (#4266)
Co-authored-by: Codex <codex@openai.com>
2026-07-07 19:24:22 +01:00
Asim Aslam ff1bf69252 docs: refresh planner priorities for 4263 (#4264)
Co-authored-by: Codex <codex@openai.com>
2026-07-07 18:51:28 +01:00
Asim Aslam 92853d353e fix atlascloud multi-step tool followups (#4262)
Co-authored-by: Codex <codex@openai.com>
2026-07-07 18:28:59 +01:00
Asim Aslam 391dc1cf05 docs: refresh planner priorities for 4258 (#4259)
Co-authored-by: Codex <codex@openai.com>
2026-07-07 17:59:36 +01:00
Asim Aslam ae69583f34 Parse OpenAI-compatible text tool calls (#4257)
Co-authored-by: Codex <codex@openai.com>
2026-07-07 16:40:58 +01:00
Asim Aslam e2729b2c32 docs: refresh planner queue for 4252 (#4253)
Co-authored-by: Codex <codex@openai.com>
2026-07-07 16:13:07 +01:00
Asim Aslam ef46bfc37f Prevent duplicate delegate replays (#4251)
Co-authored-by: Codex <codex@openai.com>
2026-07-07 15:30:36 +01:00
Asim Aslam 81d61f93d0 docs: refresh planner priorities for 4248 (#4249)
Co-authored-by: Codex <codex@openai.com>
2026-07-07 14:56:26 +01:00
Asim Aslam 5dc2a32233 fix atlascloud minimax tool fallback (#4247)
Co-authored-by: Codex <codex@openai.com>
2026-07-07 14:30:38 +01:00
Asim Aslam d8562edcf6 docs: refresh planner priorities for 4240 (#4242)
Co-authored-by: Codex <codex@openai.com>
2026-07-07 14:02:07 +01:00
Asim Aslam 5a85cba982 docs: add examples wayfinding index (#4239)
Co-authored-by: Codex <codex@openai.com>
2026-07-07 13:34:38 +01:00
Asim Aslam 019420c123 docs: refresh planner priorities for 4233 (#4234)
Co-authored-by: Codex <codex@openai.com>
2026-07-07 12:13:53 +01:00
Asim Aslam 5b32014de1 agent: trace tool retry attempts (#4232)
Co-authored-by: Codex <codex@openai.com>
2026-07-07 10:58:59 +01:00
Asim Aslam 32e522a2a9 docs: refresh planner priorities for 4229 (#4230)
Co-authored-by: Codex <codex@openai.com>
2026-07-07 10:18:29 +01:00
Asim Aslam 811d617b46 docs: refresh coherence changelog (#4228)
Co-authored-by: Codex <codex@openai.com>
2026-07-07 09:15:15 +01:00
Asim Aslam 32d0c46676 agent: cancel stream ask on close (#4226)
Co-authored-by: Codex <codex@openai.com>
2026-07-07 09:05:08 +01:00
Asim Aslam 34e7cf1f5f docs: refresh planner priorities for 4222 (#4224)
Co-authored-by: Codex <codex@openai.com>
2026-07-07 08:26:57 +01:00
Asim Aslam 091fb1d4df agent: add resume pending helper (#4221)
Co-authored-by: Codex <codex@openai.com>
2026-07-07 07:05:27 +01:00
Asim Aslam 1c56d77c86 docs: refresh planner priorities for 4216 (#4219)
Co-authored-by: Codex <codex@openai.com>
2026-07-07 06:32:27 +01:00
Asim Aslam 6f220089d5 test agent retry side-effect dedupe (#4215)
Co-authored-by: Codex <codex@openai.com>
2026-07-07 04:57:01 +01:00
Asim Aslam 58249e4a2f docs: refresh planner priorities for 4212 (#4213)
Co-authored-by: Codex <codex@openai.com>
2026-07-07 04:19:05 +01:00
Asim Aslam e51cbfba01 agent: harden conformance delegate retry (#4211)
Co-authored-by: Codex <codex@openai.com>
2026-07-07 03:30:56 +01:00
Asim Aslam e68d0e0018 docs: refresh planner priorities for 4208 (#4209)
Co-authored-by: Codex <codex@openai.com>
2026-07-07 02:48:36 +01:00
Asim Aslam e96898d362 test: verify installed on-ramp wayfinding (#4207)
Co-authored-by: Codex <codex@openai.com>
2026-07-07 02:20:46 +01:00
Asim Aslam c88a090d10 docs: refresh planner priorities for 4201 (#4203)
Co-authored-by: Codex <codex@openai.com>
2026-07-07 01:53:07 +01:00
Asim Aslam f6951d2bb0 Enforce idempotent delegate notifications (#4200)
Co-authored-by: Codex <codex@openai.com>
2026-07-07 01:03:54 +01:00
Asim Aslam 94286204ad docs: refresh planner priorities for 4196 (#4198)
Co-authored-by: Codex <codex@openai.com>
2026-07-07 00:41:56 +01:00
Asim Aslam d54139c02d Harden agent conformance retry prompts (#4195)
goreleaser / goreleaser (push) Waiting to run
Co-authored-by: Codex <codex@openai.com>
2026-07-07 00:00:00 +01:00
Asim Aslam 5ff3760cd4 Harden agent conformance retry completion (#4191)
Co-authored-by: Codex <codex@openai.com>
2026-07-06 23:10:09 +01:00
Asim Aslam 69ab520360 docs: refresh planner priorities for 4186 (#4187)
Co-authored-by: Codex <codex@openai.com>
2026-07-06 22:38:08 +01:00
Asim Aslam 0c4ea84ee3 harness: dedupe delegated notify paraphrases (#4185)
Co-authored-by: Codex <codex@openai.com>
2026-07-06 22:17:10 +01:00
Asim Aslam e6a6c72038 docs: refresh planner priorities for 4180 (#4181)
Co-authored-by: Codex <codex@openai.com>
2026-07-06 21:59:09 +01:00
Asim Aslam 7c036459cf docs: add micro loop quickstart wayfinding (#4179)
Co-authored-by: Codex <codex@openai.com>
2026-07-06 21:23:10 +01:00
Asim Aslam 83cb4ff1a9 docs: refresh planner priorities for 4174 (#4176)
Co-authored-by: Codex <codex@openai.com>
2026-07-06 20:47:02 +01:00
Asim Aslam 941d43bdf5 harness: dedupe delegated owner notifications (#4173)
Co-authored-by: Codex <codex@openai.com>
2026-07-06 20:16:40 +01:00
Asim Aslam bb3e40ade7 docs: refresh planner priorities for 4168 (#4170)
Co-authored-by: Codex <codex@openai.com>
2026-07-06 19:51:18 +01:00
Asim Aslam dbce523437 agent: cover durable checkpoint resume smoke (#4167)
Co-authored-by: Codex <codex@openai.com>
2026-07-06 19:29:11 +01:00
Asim Aslam 98125cd770 Stabilize AtlasCloud follow-up tool fallback (#4165)
Co-authored-by: Codex <codex@openai.com>
2026-07-06 18:37:42 +01:00
Asim Aslam 3454a08079 docs: refresh planner priorities for 4160 (#4161)
Co-authored-by: Codex <codex@openai.com>
2026-07-06 18:10:32 +01:00
Asim Aslam decfa7c63e Fix AtlasCloud tool schema normalization (#4159)
Co-authored-by: Codex <codex@openai.com>
2026-07-06 16:58:24 +01:00
Asim Aslam b6980e27a9 docs: refresh planner priorities for 4154 (#4155)
Co-authored-by: Codex <codex@openai.com>
2026-07-06 16:17:30 +01:00
Asim Aslam d92d63943c Add no-secret agent debugging smoke (#4153)
Co-authored-by: Codex <codex@openai.com>
2026-07-06 15:08:34 +01:00
Asim Aslam ec1d46526c docs: refresh planner priorities for 4147 (#4149)
Co-authored-by: Codex <codex@openai.com>
2026-07-06 14:28:46 +01:00
Asim Aslam 40308cf779 Preserve delegated notification plan completion (#4146)
Co-authored-by: Codex <codex@openai.com>
2026-07-06 13:03:39 +01:00
Asim Aslam e198810390 docs: refresh planner priorities for 4141 (#4143)
Co-authored-by: Codex <codex@openai.com>
2026-07-06 12:44:39 +01:00
Asim Aslam 3ec50d1a7d Add first-agent tutorial smoke harness (#4140)
Co-authored-by: Codex <codex@openai.com>
2026-07-06 11:06:12 +01:00
Asim Aslam 327f99cd19 docs: refresh coherence changelog (#4135)
Co-authored-by: Codex <codex@openai.com>
2026-07-06 09:40:01 +01:00
Asim Aslam 498aac59f4 Stabilize duplicate plan-delegate notify replays (#4133)
Co-authored-by: Codex <codex@openai.com>
2026-07-06 09:12:58 +01:00
Asim Aslam 6833b3c73c docs: refresh planner priorities for 4127 (#4131)
Co-authored-by: Codex <codex@openai.com>
2026-07-06 08:46:21 +01:00
Asim Aslam ec27ce2e25 Fix first-agent quickstart numbering (#4125)
Co-authored-by: Codex <codex@openai.com>
2026-07-06 07:18:03 +01:00
Asim Aslam 45cf24162b Add first-agent examples CLI wayfinding (#4124)
Co-authored-by: Codex <codex@openai.com>
2026-07-06 07:17:16 +01:00
Asim Aslam 2778472096 docs: refresh planner priorities for 4121 (#4122)
Co-authored-by: Codex <codex@openai.com>
2026-07-06 06:39:18 +01:00
Asim Aslam 9dfb35d85a Guard provider conformance workflow scheduling (#4120)
Co-authored-by: Codex <codex@openai.com>
2026-07-06 04:59:35 +01:00
Asim Aslam ac230b57ee docs: refresh planner priorities for 4114 (#4116)
Co-authored-by: Codex <codex@openai.com>
2026-07-06 04:18:25 +01:00
Asim Aslam 96eea598fc docs: align first-agent inspect command (#4113)
Co-authored-by: Codex <codex@openai.com>
2026-07-06 03:30:28 +01:00
Asim Aslam 97391e9a92 docs: refresh planner priorities for 4109 (#4111)
Co-authored-by: Codex <codex@openai.com>
2026-07-06 02:48:05 +01:00
Asim Aslam 6f2fefc1e1 Make plan-delegate notify replay idempotent (#4108)
Co-authored-by: Codex <codex@openai.com>
2026-07-06 02:22:20 +01:00
Asim Aslam 224446b948 docs: refresh planner priorities for 4103 (#4105)
Co-authored-by: Codex <codex@openai.com>
2026-07-06 01:44:17 +01:00
Asim Aslam eb16370f03 Add zero-to-hero CLI entrypoint (#4102)
Co-authored-by: Codex <codex@openai.com>
2026-07-06 01:02:09 +01:00
Asim Aslam 3262034698 docs: refresh planner priorities for 4096 (#4098)
Co-authored-by: Codex <codex@openai.com>
2026-07-06 00:31:40 +01:00
Asim Aslam 2963ac3fa6 docs: align architecture with agent lifecycle (#4095)
goreleaser / goreleaser (push) Waiting to run
Co-authored-by: Codex <codex@openai.com>
2026-07-05 23:59:15 +01:00
Asim Aslam eaff193569 docs: refresh planner priorities for 4091 (#4093)
Co-authored-by: Codex <codex@openai.com>
2026-07-05 23:35:22 +01:00
Asim Aslam 36fd5b7bcd Promote first-agent doctor recovery (#4090)
Co-authored-by: Codex <codex@openai.com>
2026-07-05 22:59:00 +01:00
Asim Aslam 2e89b01295 docs: refresh planner priorities for 4085 (#4087)
Co-authored-by: Codex <codex@openai.com>
2026-07-05 22:34:11 +01:00
Asim Aslam e95d565502 docs: add install troubleshooting on-ramp (#4084)
Co-authored-by: Codex <codex@openai.com>
2026-07-05 21:59:12 +01:00
Asim Aslam a826e01dd4 docs: refresh planner queue for 4081 (#4082)
Co-authored-by: Codex <codex@openai.com>
2026-07-05 21:33:35 +01:00
Asim Aslam f8619d89b6 docs: align website quickstart on-ramp (#4080)
Co-authored-by: Codex <codex@openai.com>
2026-07-05 21:06:30 +01:00
Asim Aslam 8ddb71143a docs: refresh planner priorities for 4076 (#4078)
Co-authored-by: Codex <codex@openai.com>
2026-07-05 20:35:10 +01:00
Asim Aslam 3699c88e10 Make config close idempotent (#4075)
Co-authored-by: Codex <codex@openai.com>
2026-07-05 20:08:06 +01:00
Asim Aslam a2145cc3a9 docs: refresh planner priorities for 4070 (#4072)
Co-authored-by: Codex <codex@openai.com>
2026-07-05 19:39:21 +01:00
Asim Aslam d0dce12797 test docs wayfinding link targets (#4069)
Co-authored-by: Codex <codex@openai.com>
2026-07-05 19:01:31 +01:00
Asim Aslam 2cfa776a66 docs: refresh planner priorities for 4063 (#4065)
Co-authored-by: Codex <codex@openai.com>
2026-07-05 18:43:42 +01:00
Asim Aslam 24a64aadb0 test examples lifecycle map (#4062)
Co-authored-by: Codex <codex@openai.com>
2026-07-05 18:01:38 +01:00
Asim Aslam 5d3d570c4f docs: refresh planner priorities for 4058 (#4060)
Co-authored-by: Codex <codex@openai.com>
2026-07-05 17:36:44 +01:00
Asim Aslam 304d14331c docs: lead getting started with no-secret path (#4057)
Co-authored-by: Codex <codex@openai.com>
2026-07-05 17:09:01 +01:00
Asim Aslam 5429ff0f08 docs: refresh planner priorities for 4053 (#4055)
Co-authored-by: Codex <codex@openai.com>
2026-07-05 16:39:33 +01:00
Asim Aslam 8c9521cc63 docs: surface agent demo after scaffolding (#4052)
Co-authored-by: Codex <codex@openai.com>
2026-07-05 16:11:07 +01:00
Asim Aslam 621aa68f13 Lead CLI docs with agent demo (#4049)
Co-authored-by: Codex <codex@openai.com>
2026-07-05 15:17:24 +01:00
Asim Aslam 32a337509b docs: refresh planner priorities for 4045 (#4047)
Co-authored-by: Codex <codex@openai.com>
2026-07-05 14:43:29 +01:00
Asim Aslam 4a6ab4016d docs: add agent demo to first-agent on-ramp (#4044)
Co-authored-by: Codex <codex@openai.com>
2026-07-05 14:04:27 +01:00
Asim Aslam ce7cff7409 docs: refresh planner priorities for 4040 (#4042)
Co-authored-by: Codex <codex@openai.com>
2026-07-05 13:40:25 +01:00
Asim Aslam 84e37e413e feat(cli): surface no-secret agent demo (#4039)
Co-authored-by: Codex <codex@openai.com>
2026-07-05 13:08:42 +01:00
Asim Aslam 49dfdffbb7 docs: refresh planner priorities for 4035 (#4037)
Co-authored-by: Codex <codex@openai.com>
2026-07-05 12:43:06 +01:00
Asim Aslam 9cc49f7718 Add first-agent recovery doctor (#4034)
Co-authored-by: Codex <codex@openai.com>
2026-07-05 12:23:30 +01:00
Asim Aslam a18050d910 docs: refresh planner priorities for 4030 (#4032)
Co-authored-by: Codex <codex@openai.com>
2026-07-05 11:55:29 +01:00
Asim Aslam 9db77ac265 docs: route security reports through GitHub advisories (#4029)
Co-authored-by: Codex <codex@openai.com>
2026-07-05 11:41:11 +01:00
Asim Aslam d4bfb4db5a agent: record otel events before ending spans (#4027)
Co-authored-by: Codex <codex@openai.com>
2026-07-05 10:41:35 +01:00
Asim Aslam 75bf15a7d6 docs: refresh planner priorities for 4023 (#4024)
Co-authored-by: Codex <codex@openai.com>
2026-07-05 10:14:52 +01:00
Asim Aslam 153f178db6 docs: refresh coherence changelog (#4021)
Co-authored-by: Codex <codex@openai.com>
2026-07-05 09:10:28 +01:00
Asim Aslam 15af99f587 agent: extend checkpoint plan continuations (#4019)
Co-authored-by: Codex <codex@openai.com>
2026-07-05 08:48:44 +01:00
Asim Aslam f4f0bcc459 docs: refresh planner priorities for 4016 (#4017)
Co-authored-by: Codex <codex@openai.com>
2026-07-05 08:18:35 +01:00
Asim Aslam 5ed66e550d Stabilize AtlasCloud follow-up tool calls (#4015)
Co-authored-by: Codex <codex@openai.com>
2026-07-05 07:05:00 +01:00
Asim Aslam 7f4c7d6771 docs: refresh planner priorities for 4010 (#4011)
Co-authored-by: Codex <codex@openai.com>
2026-07-05 06:31:47 +01:00
Asim Aslam 3f5547e781 ai: add anthropic streaming (#4009)
Co-authored-by: Codex <codex@openai.com>
2026-07-05 04:57:58 +01:00
Asim Aslam 12144d66a6 docs: refresh planner priorities for 4004 (#4005)
Co-authored-by: Codex <codex@openai.com>
2026-07-05 04:16:13 +01:00
Asim Aslam f2096bf0cf Guard plan delegation ordering (#4003)
Co-authored-by: Codex <codex@openai.com>
2026-07-05 03:30:56 +01:00
Asim Aslam f758297265 docs: refresh planner priorities for 3999 (#4000)
Co-authored-by: Codex <codex@openai.com>
2026-07-05 02:50:30 +01:00
Asim Aslam f16b23cf76 agent: run mixed text tool calls after structured calls (#3998)
Co-authored-by: Codex <codex@openai.com>
2026-07-05 02:18:18 +01:00
Asim Aslam 9d4133c666 docs: refresh planner priorities for 3994 (#3995)
Co-authored-by: Codex <codex@openai.com>
2026-07-05 01:49:26 +01:00
Asim Aslam 6ecfcd5cdf cli: surface first-agent next steps (#3993)
Co-authored-by: Codex <codex@openai.com>
2026-07-05 00:59:18 +01:00
Asim Aslam 3ceb23e9cb docs: refresh planner queue for 3987 (#3988)
Co-authored-by: Codex <codex@openai.com>
2026-07-05 00:32:58 +01:00
Asim Aslam af4d81cba3 harness: require notify inside plan delegate flow (#3986)
goreleaser / goreleaser (push) Waiting to run
Co-authored-by: Codex <codex@openai.com>
2026-07-05 00:00:26 +01:00
Asim Aslam 021e3e1bd9 docs: refresh planner priorities for 3982 (#3984)
Co-authored-by: Codex <codex@openai.com>
2026-07-04 23:33:46 +01:00
Asim Aslam 3f17f7b106 Stabilize first-agent broker isolation (#3981)
Co-authored-by: Codex <codex@openai.com>
2026-07-04 23:01:12 +01:00
Asim Aslam 4ed4fca47d docs: align planner queue after 3975 (#3979)
Co-authored-by: Codex <codex@openai.com>
2026-07-04 22:31:56 +01:00
Asim Aslam c2b11a1d31 docs: refresh planner queue for 3974 (#3978)
Co-authored-by: Codex <codex@openai.com>
2026-07-04 22:30:50 +01:00
Asim Aslam f7c2ff0a74 docs: surface first-agent example path (#3975)
Co-authored-by: Codex <codex@openai.com>
2026-07-04 22:22:42 +01:00
Asim Aslam ddf26acc47 docs: refresh planner priorities for 3968 (#3970)
Co-authored-by: Codex <codex@openai.com>
2026-07-04 21:30:07 +01:00
Asim Aslam 54a80bc930 harness: verify first-agent on-ramp (#3967)
Co-authored-by: Codex <codex@openai.com>
2026-07-04 21:05:30 +01:00
Asim Aslam 76f309f253 agent: alias text tool create calls to add (#3964)
Co-authored-by: Codex <codex@openai.com>
2026-07-04 19:59:32 +01:00
Asim Aslam 9a3e6b7e5e docs(priorities): refresh planner queue for 3960 (#3961)
Co-authored-by: Codex <codex@openai.com>
2026-07-04 19:28:25 +01:00
Asim Aslam eb76367b0b Stabilize agent conformance marker retry (#3959)
Co-authored-by: Codex <codex@openai.com>
2026-07-04 19:02:09 +01:00
Asim Aslam 58b8eb3e6b docs(priorities): refresh planner queue for 3954 (#3956)
Co-authored-by: Codex <codex@openai.com>
2026-07-04 18:29:59 +01:00
Asim Aslam f12788bd80 Preserve completed agent plan steps (#3953)
Co-authored-by: Codex <codex@openai.com>
2026-07-04 17:59:30 +01:00
Asim Aslam 47997134af docs(priorities): refresh planner queue for 3949 (#3950)
Co-authored-by: Codex <codex@openai.com>
2026-07-04 17:31:21 +01:00
Asim Aslam f35274af00 agent: harden AtlasCloud delegate conformance prompt (#3948)
Co-authored-by: Codex <codex@openai.com>
2026-07-04 17:01:03 +01:00
Asim Aslam fefe3e5b4a docs(priorities): refresh planner queue for 3943 (#3944)
Co-authored-by: Codex <codex@openai.com>
2026-07-04 16:36:35 +01:00
Asim Aslam b01fd477b5 agent: parse tagged text tool calls (#3942)
Co-authored-by: Codex <codex@openai.com>
2026-07-04 16:13:07 +01:00
Asim Aslam dbca408982 docs(priorities): refresh planner queue for 3938 (#3939)
Co-authored-by: Codex <codex@openai.com>
2026-07-04 15:42:04 +01:00
Asim Aslam fa9806c5a6 agent: retry missing delegate conformance (#3937)
Co-authored-by: Codex <codex@openai.com>
2026-07-04 15:20:36 +01:00
Asim Aslam 95e7c387b2 docs(priorities): refresh planner queue for 3932 (#3933)
Co-authored-by: Codex <codex@openai.com>
2026-07-04 14:36:37 +01:00
Asim Aslam cc54ae988d agent: retry conformance when tool is skipped (#3931)
Co-authored-by: Codex <codex@openai.com>
2026-07-04 14:01:46 +01:00
Asim Aslam 6b86bbb27e docs(priorities): refresh planner queue for 3927 (#3928)
Co-authored-by: Codex <codex@openai.com>
2026-07-04 13:34:42 +01:00
Asim Aslam 45624a25e0 Stabilize plan-delegate notify wait (#3926)
Co-authored-by: Codex <codex@openai.com>
2026-07-04 13:06:43 +01:00
Asim Aslam e71e0a79fb docs(priorities): refresh planner queue for 3921 (#3922)
Co-authored-by: Codex <codex@openai.com>
2026-07-04 12:41:51 +01:00
Asim Aslam ebc315505b examples: add smallest first agent (#3920)
Co-authored-by: Codex <codex@openai.com>
2026-07-04 12:13:08 +01:00
Asim Aslam 100c7e11b9 docs(priorities): refresh planner queue for 3913 (#3915)
Co-authored-by: Codex <codex@openai.com>
2026-07-04 11:41:35 +01:00
Asim Aslam 96ecf67573 agent: surface checkpoint resume hints in inspect (#3912)
Co-authored-by: Codex <codex@openai.com>
2026-07-04 11:26:58 +01:00
Asim Aslam 71f4f6ac05 docs(priorities): refresh planner queue for 3907 (#3909)
Co-authored-by: Codex <codex@openai.com>
2026-07-04 10:51:37 +01:00
Asim Aslam 0dd5ebe789 test(agent): broaden provider conformance scenario (#3906)
Co-authored-by: Codex <codex@openai.com>
2026-07-04 10:32:49 +01:00
Asim Aslam b29c8c95b1 docs(priorities): refresh planner queue for 3900 (#3904)
Co-authored-by: Codex <codex@openai.com>
2026-07-04 10:06:16 +01:00
Asim Aslam 47ff1bc6f5 Add AP2 mandate foundation for A2A (#3899)
Co-authored-by: Codex <codex@openai.com>
2026-07-04 09:35:01 +01:00
Asim Aslam 6c6ce0e2a7 docs: update coherence changelog (#3897)
Co-authored-by: Codex <codex@openai.com>
2026-07-04 09:14:57 +01:00
Asim Aslam d91ac00da9 agent: add operational failure guidance (#3895)
Co-authored-by: Codex <codex@openai.com>
2026-07-04 08:38:33 +01:00
Asim Aslam ff94e8b316 docs(priorities): refresh planner queue for 3890 (#3892)
Co-authored-by: Codex <codex@openai.com>
2026-07-04 08:15:25 +01:00
Asim Aslam ab0bf29c79 feat(loop): add a security role that vets for vulnerabilities (#3818)
Adds an opt-in `security` role to `micro loop` and wires it into go-micro's own
loop. On a schedule it dispatches the agent to audit the codebase for real,
exploitable vulnerabilities and file them.

Security gets a deliberately more conservative policy than the other roles,
encoded in .github/loop/prompts/security.md:
- NEVER auto-merges a security change (fixes stay human-reviewed).
- NEVER publishes exploit detail / PoC in a public issue — novel exploitable
  findings get a concise `security` + `needs-human` issue (class, location,
  impact) routed to private disclosure; only known/public dep CVEs get a
  bump PR (no auto-merge).
- Weekly by default (`--security-cron`, 0 6 * * 1); tunable.

The go-micro prompt targets its real attack surface: MCP/A2A gateways, x402
payments, JWT/wrapper auth, provider BaseURL SSRF + key leakage, the agent
tool loop (prompt injection / guardrail bypass), TLS defaults, the loop's own
PAT, and dependency CVEs via govulncheck.

Note: an agent review is not a gate. The deterministic companion — govulncheck
as a required CI check — is a recommended follow-up so known-vulnerable deps
can't merge at all.


Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

Co-authored-by: Claude <noreply@anthropic.com>
2026-07-04 07:03:08 +01:00
Asim Aslam 96e822d656 Add no-secret debug transcript checkpoint (#3889)
Co-authored-by: Codex <codex@openai.com>
2026-07-04 06:57:18 +01:00
Asim Aslam c60c03d485 docs(priorities): refresh planner queue for 3885 (#3886)
Co-authored-by: Codex <codex@openai.com>
2026-07-04 06:25:38 +01:00
Asim Aslam 7963342999 docs: test first-agent wayfinding (#3884)
Co-authored-by: Codex <codex@openai.com>
2026-07-04 04:55:59 +01:00
Asim Aslam 593846093f docs(priorities): refresh planner queue for 3878 (#3881)
Co-authored-by: Codex <codex@openai.com>
2026-07-04 04:10:29 +01:00
Asim Aslam 5b27c5b239 Fix plan-delegate notify completion race (#3877)
Co-authored-by: Codex <codex@openai.com>
2026-07-04 03:29:05 +01:00
Asim Aslam 0a10655231 docs(priorities): refresh planner queue for 3873 (#3874)
Co-authored-by: Codex <codex@openai.com>
2026-07-04 02:49:04 +01:00
Asim Aslam cc3502d156 Trace agent model streams (#3872)
Co-authored-by: Codex <codex@openai.com>
2026-07-04 02:17:16 +01:00
Asim Aslam 014a6431f2 docs(priorities): refresh planner queue for 3866 (#3868)
Co-authored-by: Codex <codex@openai.com>
2026-07-04 01:46:02 +01:00
Asim Aslam 3725a53bf9 Record streamed agent replies in memory (#3865)
Co-authored-by: Codex <codex@openai.com>
2026-07-04 01:01:04 +01:00
Asim Aslam b24b19f191 docs(priorities): refresh planner queue for 3862 (#3863)
Co-authored-by: Codex <codex@openai.com>
2026-07-04 00:34:46 +01:00
Asim Aslam bc732bb513 docs: surface durable agent example (#3861)
goreleaser / goreleaser (push) Waiting to run
Co-authored-by: Codex <codex@openai.com>
2026-07-04 00:02:40 +01:00
Asim Aslam 522786d21d docs(priorities): refresh planner queue for 3856 (#3858)
Co-authored-by: Codex <codex@openai.com>
2026-07-03 23:25:03 +01:00
Asim Aslam 84cc4c6e8d Trace agent run event kinds (#3855)
Co-authored-by: Codex <codex@openai.com>
2026-07-03 23:00:08 +01:00
Asim Aslam f96b1014a2 docs(priorities): refresh planner queue for 3852 (#3853)
Co-authored-by: Codex <codex@openai.com>
2026-07-03 22:34:49 +01:00
Asim Aslam 3cafff8789 Make agent preflight failures actionable (#3851)
Co-authored-by: Codex <codex@openai.com>
2026-07-03 22:00:02 +01:00
Asim Aslam 69e23eb1f6 docs(priorities): refresh planner queue for 3846 (#3848)
Co-authored-by: Codex <codex@openai.com>
2026-07-03 21:34:55 +01:00
Asim Aslam 1841599980 Ensure canceled agent runs fail after tool calls (#3845)
Co-authored-by: Codex <codex@openai.com>
2026-07-03 21:07:58 +01:00
Asim Aslam 6f9994b3ea docs(priorities): refresh planner queue for 3840 (#3842)
Co-authored-by: Codex <codex@openai.com>
2026-07-03 20:33:13 +01:00
Asim Aslam 55070f1597 Harden A2A fallback stream validation (#3839)
Co-authored-by: Codex <codex@openai.com>
2026-07-03 20:03:40 +01:00
Asim Aslam b3940860b6 docs(priorities): refresh planner queue for 3835 (#3836)
Co-authored-by: Codex <codex@openai.com>
2026-07-03 19:39:51 +01:00
Asim Aslam 5c38a23fe4 Classify plan-delegate timeout side effects (#3834)
Co-authored-by: Codex <codex@openai.com>
2026-07-03 19:07:08 +01:00
Asim Aslam 9e7273dde1 docs(priorities): refresh planner queue for 3829 (#3830)
Co-authored-by: Codex <codex@openai.com>
2026-07-03 18:42:19 +01:00
Asim Aslam 42080b6d6d Stabilize file store suffix expiry test (#3828)
Co-authored-by: Codex <codex@openai.com>
2026-07-03 18:18:26 +01:00
Asim Aslam c3df8b833d docs(priorities): refresh planner queue for 3823 (#3824)
Co-authored-by: Codex <codex@openai.com>
2026-07-03 17:38:33 +01:00
Asim Aslam 8694e3a20c test(store): isolate file store tests (#3822)
Co-authored-by: Codex <codex@openai.com>
2026-07-03 17:18:57 +01:00
Asim Aslam 9def03d4e3 docs(priorities): refresh planner queue for 3817 (#3819)
Co-authored-by: Codex <codex@openai.com>
2026-07-03 16:51:21 +01:00
Asim Aslam bd7625f947 Tighten delegated notify harness prompt (#3816)
Co-authored-by: Codex <codex@openai.com>
2026-07-03 16:25:49 +01:00
Asim Aslam 0a547fbe17 docs(priorities): refresh planner queue for 3812 (#3813)
Co-authored-by: Codex <codex@openai.com>
2026-07-03 15:55:48 +01:00
Asim Aslam 331e3f32bd Fix universe concierge notify handoff (#3811)
Co-authored-by: Codex <codex@openai.com>
2026-07-03 15:31:48 +01:00
Asim Aslam 7db1d986ab docs(priorities): refresh planner queue for 3808 (#3809)
Co-authored-by: Codex <codex@openai.com>
2026-07-03 14:48:47 +01:00
Asim Aslam 6042a6c5f5 Add CLI docs wayfinding (#3807)
Co-authored-by: Codex <codex@openai.com>
2026-07-03 14:21:34 +01:00
Asim Aslam bff916a3ac docs(priorities): refresh planner queue for 3800 (#3802)
Co-authored-by: Codex <codex@openai.com>
2026-07-03 13:42:57 +01:00
Asim Aslam b8c03dafa2 Stabilize plan-delegate notify recovery (#3799)
Co-authored-by: Codex <codex@openai.com>
2026-07-03 13:30:58 +01:00
Asim Aslam 04bcef47ac docs(priorities): refresh planner queue for 3795 (#3796)
Co-authored-by: Codex <codex@openai.com>
2026-07-03 12:58:27 +01:00
Asim Aslam e92978f3eb Add minimax to provider conformance (#3794)
Co-authored-by: Codex <codex@openai.com>
2026-07-03 12:30:56 +01:00
Asim Aslam 695a24432a docs(priorities): refresh planner queue for 3790 (#3791)
Co-authored-by: Codex <codex@openai.com>
2026-07-03 12:00:11 +01:00
Asim Aslam 2889b98dcf store: de-flake TestFileStoreTable timing windows (#3789)
TestFileStoreTable failed intermittently on CI ("Expected 2 items, got 1"):
the same commit passed the Unit Tests job on a PR run and failed on the master
push. Cause: records written with a 100ms expiry are read back immediately and
expected to still be present, but under `-race` on a loaded runner the write
loop + file I/O + read can exceed 100ms, so a record expires before the read.

Widen the expiry/TTL windows (100ms -> 1s) and the paired post-expiry sleeps
(-> 2s). The "read before expiry" reads happen in well under 200ms, so they stay
inside the 1s window on any runner; the "read after expiry" waits comfortably
exceed it. Test-only; the store's expiry behavior is unchanged.

Verified: `go test -race -count=5 -run TestFileStoreTable ./store/` green.


Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

Co-authored-by: Claude <noreply@anthropic.com>
2026-07-03 11:35:56 +01:00
Asim Aslam a356ab36a8 ai/minimax: complete provider surface (matrix, conformance, changelog) (#3784)
* ai/minimax: complete provider surface (matrix, conformance, changelog)

Follow-up after merging the MiniMax provider (#3769), mirroring the Ollama
completeness pass (#3637):

- Add the `minimax` row to the AI provider capability matrix and blank-import
  ai/minimax in provider_capabilities_test.go so the matrix stays enforced
  against the registry.
- Add minimax to the stream-conformance allowlist (+ import) so its streaming
  is actually exercised against the OpenAI-compatible SSE contract, not just
  registered. It passes via the shared ai/internal/openaiapi path.
- Record the provider in CHANGELOG [Unreleased].

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

* ai: update capabilities_test provider assertions for minimax

Adding the minimax blank-import to the shared ai_test binary (for stream
conformance) also registers it for TestRegisteredProviders / TestCapabilityRows
/ TestCapabilityMatrix in capabilities_test.go, which pin the exact provider
set. Update those assertions to include minimax. (Fixes the Unit Tests failure
my scoped `-run TestStreamProviders` check missed — go compiles all _test.go in
a package into one binary.)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-07-03 11:10:29 +01:00
Octopus 2078748e7f feat: add MiniMax provider (#3769)
Co-authored-by: octo-patch <266937838+octo-patch@users.noreply.github.com>
2026-07-03 10:56:12 +01:00
Asim Aslam d283f9b08b Accept order-scoped buyer notifications (#3783)
Co-authored-by: Codex <codex@openai.com>
2026-07-03 10:45:47 +01:00
Asim Aslam af7b4f3d50 docs(priorities): refresh planner queue for 3777 (#3778)
Co-authored-by: Codex <codex@openai.com>
2026-07-03 10:17:04 +01:00
Asim Aslam 954f8fa79e docs: update changelog for coherence audit (#3776)
Co-authored-by: Codex <codex@openai.com>
2026-07-03 09:07:28 +01:00
Asim Aslam cdfe9c0947 Fix plan-delegate timeout completion (#3774)
Co-authored-by: Codex <codex@openai.com>
2026-07-03 08:49:33 +01:00
Asim Aslam c645c5faa7 docs(priorities): refresh planner queue for 3768 (#3770)
Co-authored-by: Codex <codex@openai.com>
2026-07-03 08:18:32 +01:00
Asim Aslam 8bde01bdac docs(priorities): refresh planner queue for 3763 (#3764)
Co-authored-by: Codex <codex@openai.com>
2026-07-03 06:31:05 +01:00
Asim Aslam 1373ceec21 harness: parse multi-event A2A SSE (#3762)
Co-authored-by: Codex <codex@openai.com>
2026-07-03 04:53:40 +01:00
Asim Aslam 838b7f73f8 docs(priorities): refresh planner queue for 3757 (#3758)
Co-authored-by: Codex <codex@openai.com>
2026-07-03 04:20:35 +01:00
Asim Aslam c56423a33c Require harness notification side effects (#3756)
Co-authored-by: Codex <codex@openai.com>
2026-07-03 03:29:12 +01:00
Asim Aslam 6edc0de7bd docs(priorities): refresh planner queue for 3752 (#3753)
Co-authored-by: Codex <codex@openai.com>
2026-07-03 02:46:16 +01:00
Asim Aslam 3d31fe37db fix atlascloud tool-call request diagnostics (#3749)
Co-authored-by: Codex <codex@openai.com>
2026-07-03 02:30:44 +01:00
Asim Aslam 6840ae0fb1 docs(priorities): refresh planner queue for 3745 (#3746)
Co-authored-by: Codex <codex@openai.com>
2026-07-03 01:45:59 +01:00
Asim Aslam af61d6327a atlascloud: fall back to tool results (#3744)
Co-authored-by: Codex <codex@openai.com>
2026-07-03 01:00:20 +01:00
Asim Aslam 79d443839d docs(priorities): refresh planner queue for 3739 (#3740)
Co-authored-by: Codex <codex@openai.com>
2026-07-03 00:33:57 +01:00
Asim Aslam 5770a2f4cb fix atlascloud stream tool fallback (#3738)
goreleaser / goreleaser (push) Waiting to run
Co-authored-by: Codex <codex@openai.com>
2026-07-03 00:06:42 +01:00
Asim Aslam 9f1f0aa191 docs(priorities): refresh planner queue for 3732 (#3733)
Co-authored-by: Codex <codex@openai.com>
2026-07-02 23:28:01 +01:00
Asim Aslam 69ffee329e Detect duplicate plan-delegate notifications (#3731)
Co-authored-by: Codex <codex@openai.com>
2026-07-02 23:03:37 +01:00
Asim Aslam d2c3c5e715 docs(priorities): refresh planner queue for 3727 (#3728)
Co-authored-by: Codex <codex@openai.com>
2026-07-02 22:35:19 +01:00
Asim Aslam 11f81f40fd harness: accept order-scoped buyer notifications (#3726)
Co-authored-by: Codex <codex@openai.com>
2026-07-02 21:59:07 +01:00
Asim Aslam a057df54f5 docs(priorities): refresh planner queue (#3722)
Co-authored-by: Codex <codex@openai.com>
2026-07-02 21:38:35 +01:00
Asim Aslam 0da1c739fb test plan-delegate unknown tool recovery (#3720)
Co-authored-by: Codex <codex@openai.com>
2026-07-02 21:15:09 +01:00
Asim Aslam 9ec9bf906c docs(priorities): refresh planner queue (#3716)
Co-authored-by: Codex <codex@openai.com>
2026-07-02 20:41:47 +01:00
Asim Aslam cf790048ad loop: triage watches Lint + Run Tests too, not just the harness (#3714)
Backstop for the gate: previously loop-triage only fired on Harness (E2E)
failures, so a red lint or test on master (e.g. the misspell that slipped past
because golangci-lint isn't a required check) produced no fix issue. Now triage
watches all the gate workflows.

- micro loop: `--ci-workflow` accepts a comma-separated list of workflow names,
  rendered into the triage workflow_run trigger as a YAML array; the issue names
  the actual failed workflow via github.event.workflow_run.name. (generic CLI)
- go-micro: regenerate loop-triage.yml to watch "Harness (E2E)", "Lint",
  "Run Tests"; generalize the triage prompt beyond the harness (a lint/test
  failure on master is a real regression to fix, not a flake to ignore).
- Docs: update CONTINUOUS_IMPROVEMENT.md triage description.

Note: this is defense-in-depth. The primary fix is making golangci-lint a
required status check so red lint can't merge in the first place — that stays
with the human (branch protection).


Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

Co-authored-by: Claude <noreply@anthropic.com>
2026-07-02 20:21:07 +01:00
Asim Aslam 11d1711619 docs: add no-secret first-agent transcript (#3713)
Co-authored-by: Codex <codex@openai.com>
2026-07-02 20:16:39 +01:00
Asim Aslam 7d464e8a32 docs(priorities): refresh planner queue (#3709)
Co-authored-by: Codex <codex@openai.com>
2026-07-02 19:43:47 +01:00
Asim Aslam 8880168edd agent: continue unfinished plan steps (#3706)
Co-authored-by: Codex <codex@openai.com>
2026-07-02 19:20:52 +01:00
Asim Aslam 33b6ab5eea docs(priorities): refresh planner queue (#3703)
Co-authored-by: Codex <codex@openai.com>
2026-07-02 18:45:41 +01:00
Asim Aslam 32d1683d0b harness: accept buyer alias notifications (#3701)
Co-authored-by: Codex <codex@openai.com>
2026-07-02 18:15:19 +01:00
Asim Aslam 917d60f9f8 docs(priorities): refresh planner queue (#3697)
Co-authored-by: Codex <codex@openai.com>
2026-07-02 17:38:37 +01:00
Asim Aslam e41a80c92f docs: map examples to first-agent path (#3695)
Co-authored-by: Codex <codex@openai.com>
2026-07-02 17:24:27 +01:00
Asim Aslam c25fe16260 docs(priorities): drop completed universe item (#3691)
Co-authored-by: Codex <codex@openai.com>
2026-07-02 17:01:49 +01:00
Asim Aslam d240466d6d Constrain universe notify recipients (#3689)
Co-authored-by: Codex <codex@openai.com>
2026-07-02 16:29:14 +01:00
Asim Aslam 33a4af3984 docs(priorities): refresh planner queue (#3686)
Co-authored-by: Codex <codex@openai.com>
2026-07-02 16:00:17 +01:00
Asim Aslam 274c3b2646 Fail checkpointed runs with unfinished plans (#3684)
Co-authored-by: Codex <codex@openai.com>
2026-07-02 15:27:52 +01:00
Asim Aslam 6b6100340b docs(priorities): refresh planner queue (#3680)
Co-authored-by: Codex <codex@openai.com>
2026-07-02 14:40:53 +01:00
Asim Aslam 35b68b11f9 wrapper/x402: fix misspell lint failure (honour -> honor) (#3678)
golangci-lint's misspell linter fails on master: x402_settle_test.go used
British spellings ("honoured"/"honour"). Switch to US spelling to match the
linter's en_US locale. Introduced by #3676.


Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

Co-authored-by: Claude <noreply@anthropic.com>
2026-07-02 14:39:18 +01:00
Asim Aslam 13d618ba66 test: make universe A2A reachability deterministic (#3677)
Co-authored-by: Codex <codex@openai.com>
2026-07-02 14:20:21 +01:00
Asim Aslam b60952cbfe wrapper/x402: settle payments, CDP auth, and conformance fixes (#3676)
The x402 wrapper could advertise a 402 and verify a payment, but never
settled it (the "exact" scheme needs verify + settle to actually move
funds), and its HTTPFacilitator sent no auth, so it could not use the
Coinbase CDP facilitator — the only one that settles Base mainnet. It
also passed the raw base64 X-PAYMENT string where facilitators expect the
decoded payload object.

- Add an optional Settler interface; HTTPFacilitator now implements
  Verify and Settle (POST /verify then /settle), and Require settles a
  verified payment and emits the settlement reference.
- HTTPFacilitator.Authorize hook + x402.CDP(keyID, secret) constructor:
  mint a short-lived Ed25519 Bearer JWT (stdlib crypto only, no chain
  code, no new dependency) so verify/settle authenticate to CDP.
- Decode the X-PAYMENT payload to the object facilitators expect, with
  passthrough for non-JSON payloads.
- Requirements gains extra (EIP-712 domain) and mimeType; the asset and
  its {name,version} are auto-filled for known networks so clients can
  sign. NormalizeNetwork maps base/base-sepolia to CAIP-2 ids.
- Accept the v2 PAYMENT-SIGNATURE request header and emit both
  X-PAYMENT-RESPONSE and PAYMENT-RESPONSE.

Backward compatible: the default network stays "base", the Facilitator
interface is unchanged (Settler is additive), and gateway/mcp builds and
tests unchanged. Adds tests for settle, CDP JWT, header aliases, extra,
and payload decoding.
2026-07-02 14:18:53 +01:00
Asim Aslam c13ff9fc98 docs(priorities): refresh planner queue (#3672)
Co-authored-by: Codex <codex@openai.com>
2026-07-02 13:52:31 +01:00
Asim Aslam 6e010706ec harness: suppress duplicate universe notifications (#3669)
Co-authored-by: Codex <codex@openai.com>
2026-07-02 13:26:43 +01:00
Asim Aslam 75615e81ca docs(priorities): refresh planner queue (#3666)
Co-authored-by: Codex <codex@openai.com>
2026-07-02 13:02:25 +01:00
Asim Aslam 097a4f6f9f harness: make plan delegate side effects idempotent (#3664)
Co-authored-by: Codex <codex@openai.com>
2026-07-02 12:33:08 +01:00
Asim Aslam 898853d948 docs(priorities): refresh planner queue (#3660)
Co-authored-by: Codex <codex@openai.com>
2026-07-02 11:29:28 +01:00
Asim Aslam 573e043cb1 blog: introduce micro loop (#33) (#3659)
A detailed post on `micro loop` — the autonomous loop that builds Go Micro,
now shippable as a command. Covers the mechanism/policy split (Actions as the
runtime, prompt files as editable policy), the five roles, the quickstart and
the two things the CLI can't do (token + branch protection), the load-bearing
decisions and the gotchas we hit (fresh-issue-per-run, bot-comment gating, the
persist-credentials 403), and the dogfood: Go Micro now runs on it. Sequel to
/blog/31 "How Go Micro Builds Itself".


Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

Co-authored-by: Claude <noreply@anthropic.com>
2026-07-02 11:19:09 +01:00
Asim Aslam 76961d503a feat(loop): go-micro runs on micro loop (dogfood its own tool) (#3657)
* feat(loop): go-micro now runs on `micro loop` (dogfood its own tool)

Replace go-micro's five hand-written loop workflows with ones generated by
`micro loop init --roles all`, making "go-micro builds itself with micro loop"
literally true rather than aspirational.

- Generate loop-planner/builder/triage/coherence/release.yml via the CLI with
  go-micro's cadence and wiring (planner :59, builder :29, coherence 07:00,
  release 23:00; CI gate "Harness (E2E)"; token CODEX_TRIGGER_TOKEN; base master;
  tag prefix v). The old loop-architect.yml and loop-devrel.yml become
  loop-planner.yml and loop-coherence.yml.
- Move the queue to .github/loop/PRIORITIES.md and add .github/loop/NORTH_STAR.md
  (a concise steer pointing to internal/docs/THESIS.md), adopting the loop's
  convention.
- Preserve go-micro's rich instructions as editable policy in
  .github/loop/prompts/{planner,builder,triage,coherence}.md — the architect
  founder-lens + adoption steer, the increment builder, harness-failure triage,
  and the DevRel changelog/blog pass — faithfully ported from the old inline
  prompts. Behavior is preserved; only the mechanism is now generated.
- CLI refinement the migration surfaced: prompts (and NORTH_STAR/PRIORITIES) are
  now write-once — `micro loop init --force` refreshes workflow MECHANICS but
  never clobbers customized POLICY. Added renderKeep + a test.
- Update internal/docs/CONTINUOUS_IMPROVEMENT.md (renamed workflows, moved queue,
  the prompt-file model, and a note that these files are generated by micro loop).

Verified: build, go test ./cmd/micro/loop/..., golangci-lint (0 issues), gofmt;
`micro loop verify` passes; all generated workflows are valid YAML; re-running
init --force is idempotent and preserves policy.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

* loop: strip prompt editorial comments before posting to the agent

Verification of the migration surfaced that a dispatch workflow posted the
prompt file's leading <!-- editorial --> header to the agent, and __ISSUE__
inside it got substituted too (e.g. "Keep 4242 literal"). Harmless (invisible
in rendered markdown) but unclean and mildly confusing. The dispatch and triage
body construction now strips <!-- --> blocks with `sed '/<!--/,/-->/d'` before
substituting runtime tokens. Regenerated go-micro's workflows; added a test.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-07-02 11:14:21 +01:00
Asim Aslam f839ca7427 feat(cli): prompt-file-driven micro loop + coherence & release roles (#3655)
Rework `micro loop` so the workflows are the mechanism and each dispatch role's
instruction is an editable .github/loop/prompts/<role>.md file (the policy).
That split lets any repo — including go-micro itself — customize behavior by
editing prompt files instead of forking the CLI, which is the prerequisite for
go-micro consuming its own tool without losing its richer prompts.

- Add two opt-in roles: `coherence` (README/docs/CHANGELOG alignment) and
  `release` (cut the next patch tag on new commits; bakes in the
  persist-credentials:false fix so the PAT push isn't clobbered by the
  checkout token — the 403 we hit on the live release action).
- `--roles` selects which roles to scaffold (default planner,builder,triage;
  `all` for everything); `--tag-prefix`, `--release-cron`, `--coherence-cron`
  added. Templates keep the << >> delimiters so GHA ${{ }} passes through;
  prompts leave __ISSUE__/__RUNURL__ as runtime tokens the workflow substitutes.
- `micro loop verify` now checks each present role workflow has its prompt.
- README updated with the five roles and a copy-pasteable flag example
  (folds in the readability fix from the now-closed #3651).

Verified: build, `go test ./cmd/micro/loop/...`, vet, golangci-lint (0 issues),
gofmt; and an end-to-end `micro loop init --roles all` whose generated
workflows all parse as valid YAML and pass `micro loop verify`.


Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

Co-authored-by: Claude <noreply@anthropic.com>
2026-07-02 10:47:49 +01:00
Asim Aslam fb1888efb7 docs: connect quickstart to first agent path (#3656)
Co-authored-by: Codex <codex@openai.com>
2026-07-02 10:47:19 +01:00
Asim Aslam 5f3244d09e feat(cli): add micro loop to scaffold a self-improving repo loop (#3649)
`micro loop init` writes an autonomous improvement loop into any repository —
the same planner/builder/triage loop that maintains go-micro, generalized:

- planner (loop-planner.yml): keeps a ranked queue in .github/loop/PRIORITIES.md
- builder (loop-builder.yml): builds the top open item as a single-concern PR,
  auto-merged on green CI
- triage (loop-triage.yml): turns CI failures into scoped fix issues

plus .github/loop/NORTH_STAR.md (direction) and PRIORITIES.md (queue).

The agent adapter is mention-based, not hardcoded to Codex: `--agent @codex`
(or any @mention agent that responds on an issue and can run gh), `--token-secret`,
`--branch`, `--ci-workflow`, and cron flags are the whole config-vs-core boundary.
Templates use << >> delimiters so GitHub Actions' own ${{ }} expressions pass
through untouched. `micro loop verify` checks the wiring and flags the two things
the CLI can't: the token secret and branch protection (the green-CI gate).

Built inside go-micro with the config/core split already drawn, so the workflows
can later be extracted to a standalone reusable-workflows repo without a rewrite.


Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

Co-authored-by: Claude <noreply@anthropic.com>
2026-07-02 10:12:12 +01:00
Asim Aslam 1e932321c8 docs(priorities): refresh architect queue (#3650)
Co-authored-by: Codex <codex@openai.com>
2026-07-02 10:11:01 +01:00
Asim Aslam a24eaad1c9 docs: roll changelog for v6.3.12 (#3646)
Co-authored-by: Codex <codex@openai.com>
2026-07-02 09:16:05 +01:00
Asim Aslam 357fdf2777 docs: surface first agent on-ramp (#3644)
Co-authored-by: Codex <codex@openai.com>
2026-07-02 08:52:09 +01:00
Asim Aslam a66fb4ff2c docs(priorities): refresh architect adoption queue (#3641)
Co-authored-by: Codex <codex@openai.com>
2026-07-02 08:16:31 +01:00
Asim Aslam 8e3ba68d58 loop-release: fix 403 on tag push (checkout token clobbered the PAT) (#3638)
goreleaser / goreleaser (push) Waiting to run
* docs: complete Ollama provider surface (capability matrix, README, example fixes)

Follow-up cleanup after merging the Ollama provider (#3636):

- Add the `ollama` row to the AI provider capability matrix in the provider
  guide, and blank-import `ai/ollama` in provider_capabilities_test.go so the
  matrix stays enforced against the registry (the provider registers a stream
  but wasn't imported in that test, so its row went unchecked).
- README: bump "7 LLM providers" → 8 and list Ollama (local + cloud); add its
  default model (`llama3.2`) to the model table.
- Fix a fictional model name shipped in the example and package doc:
  `gemma4:31b-cloud` → `gpt-oss:120b`. gemma4 doesn't exist, and the `-cloud`
  suffix is for cloud models proxied through a local Ollama, not the direct
  ollama.com/v1 endpoint the example uses.
- Record the provider and the new agent.BaseURL/micro.AgentBaseURL option in
  the CHANGELOG [Unreleased] section.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

* loop-release: don't let checkout's persisted GITHUB_TOKEN clobber the PAT push

The daily release job computed the next tag correctly but the tag push 403'd:
"Permission to micro/go-micro.git denied to github-actions[bot]" (run
28554612450). Cause: actions/checkout persists the default GITHUB_TOKEN as an
http.extraheader Authorization credential for github.com, which git sends on
ALL requests to that host — including our manual
`git push https://x-access-token:${PAT}@github.com/...`. The persisted header
overrides the URL-embedded PAT, so the push authenticates as
github-actions[bot], which can't push tags (the job only grants
contents: read).

Set persist-credentials: false so no extraheader is written and the PAT in the
push URL is the only credential used.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-07-02 07:51:31 +01:00
Asim Aslam 6e04f1afb5 docs: complete Ollama provider surface (capability matrix, README, example fixes) (#3637)
Follow-up cleanup after merging the Ollama provider (#3636):

- Add the `ollama` row to the AI provider capability matrix in the provider
  guide, and blank-import `ai/ollama` in provider_capabilities_test.go so the
  matrix stays enforced against the registry (the provider registers a stream
  but wasn't imported in that test, so its row went unchecked).
- README: bump "7 LLM providers" → 8 and list Ollama (local + cloud); add its
  default model (`llama3.2`) to the model table.
- Fix a fictional model name shipped in the example and package doc:
  `gemma4:31b-cloud` → `gpt-oss:120b`. gemma4 doesn't exist, and the `-cloud`
  suffix is for cloud models proxied through a local Ollama, not the direct
  ollama.com/v1 endpoint the example uses.
- Record the provider and the new agent.BaseURL/micro.AgentBaseURL option in
  the CHANGELOG [Unreleased] section.


Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

Co-authored-by: Claude <noreply@anthropic.com>
2026-07-02 07:44:58 +01:00
YongSoo Park 110cb44d41 feat: add Ollama provider with local and cloud support (#3636)
Add a dedicated Ollama AI provider (ai/ollama/) that auto-detects
local vs cloud mode based on the base URL:

- Local Ollama: native /api/chat endpoint with NDJSON streaming
- Ollama Cloud: OpenAI-compatible /v1/chat/completions with SSE streaming

Both modes support tool calls with a multi-round execution loop.

Add agent.BaseURL option so agents can point at non-default LLM
endpoints (e.g. local Ollama, proxies). Wire it through micro.AgentBaseURL
at the top level.

Include a complete example (examples/agent-ollama/) demonstrating a
knowledge-base service with auto-discovered tools, a custom time tool,
streaming, and env-var configuration for local vs cloud.

Closes #3632
2026-07-02 07:37:36 +01:00
Asim Aslam f06e7467ce ci: smoke test installer first-run CLI (#3635)
Co-authored-by: Codex <codex@openai.com>
2026-07-02 07:00:45 +01:00
Asim Aslam 412491568f docs(priorities): refresh architect adoption queue (#3631)
Co-authored-by: Codex <codex@openai.com>
2026-07-02 06:28:17 +01:00
Asim Aslam d2e1520a14 Verify zero-to-hero reference app in harness (#3628)
Co-authored-by: Codex <codex@openai.com>
2026-07-02 04:56:41 +01:00
Asim Aslam 0a18ac6c15 docs(priorities): refresh architect queue (#3624)
Co-authored-by: Codex <codex@openai.com>
2026-07-02 04:15:41 +01:00
Asim Aslam 45a23a3417 test first-agent walkthrough boundaries (#3621)
Co-authored-by: Codex <codex@openai.com>
2026-07-02 03:31:30 +01:00
Asim Aslam ae239b0102 docs(priorities): refresh architect queue (#3619)
Co-authored-by: Codex <codex@openai.com>
2026-07-02 02:53:21 +01:00
Asim Aslam 3a2d21f1ac agent: dedupe plan delegate tool side effects (#3616)
Co-authored-by: Codex <codex@openai.com>
2026-07-02 02:35:18 +01:00
Asim Aslam 40a559e8db Harden universe notify finalization (#3612)
Co-authored-by: Codex <codex@openai.com>
2026-07-02 01:08:12 +01:00
Asim Aslam 28320fc1d4 cli: add first-agent preflight diagnostics (#3608)
Co-authored-by: Codex <codex@openai.com>
2026-07-02 00:02:53 +01:00
Asim Aslam cbc8fc62c7 docs(priorities): refresh architect adoption queue (#3605)
Co-authored-by: Codex <codex@openai.com>
2026-07-01 23:39:48 +01:00
Asim Aslam 1f93fa8b1b docs: expose zero-to-hero on-ramp (#3602)
Co-authored-by: Codex <codex@openai.com>
2026-07-01 23:09:17 +01:00
Asim Aslam c6f9940ab2 docs(priorities): refresh architect adoption queue (#3599)
Co-authored-by: Codex <codex@openai.com>
2026-07-01 22:42:02 +01:00
Asim Aslam 9c66455d2a docs: add agent debugging guide (#3596)
Co-authored-by: Codex <codex@openai.com>
2026-07-01 22:13:48 +01:00
Asim Aslam 2215065a2e docs(priorities): refresh architect queue (#3593)
Co-authored-by: Codex <codex@openai.com>
2026-07-01 21:45:21 +01:00
Asim Aslam f8b8b90a3b docs: lead guides nav with hands-on path (#3591)
Co-authored-by: Codex <codex@openai.com>
2026-07-01 21:21:39 +01:00
Asim Aslam 1bcf0e1ae9 docs(priorities): drop completed examples task (#3587)
Co-authored-by: Codex <codex@openai.com>
2026-07-01 20:41:31 +01:00
Asim Aslam b49f5072b1 loop: have DevRel maintain CHANGELOG.md and draft a changelog blog post (#3584)
The DevRel pass now keeps the changelog living instead of letting it drift:
each daily run reconciles a Keep-a-Changelog `[Unreleased]` section against the
PRs that actually merged (user-facing entries only; internal loop/CI churn
skipped) and rolls it into a dated version heading whenever loop-release cuts a
new v6.MINOR.PATCH tag. When enough user-facing work has accumulated (roughly a
week's worth, not a near-empty post every day) it also drafts a "what's new"
changelog blog post narrating what shipped.

Autonomy boundary preserved: CHANGELOG.md upkeep is a safe factual change and
rides the auto-merged DevRel PR; the changelog blog post is opened as its own
PR but left for the human to review/merge, since blog voice stays with the human.

Also fix the CHANGELOG preamble: it claimed calendar versions (YYYY.MM) while
tags are semver (v6.MINOR.PATCH). Correct it, add an `[Unreleased]` section
seeded from real recent work, and note the historical 2026.0x headings.


Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

Co-authored-by: Claude <noreply@anthropic.com>
2026-07-01 20:29:53 +01:00
Asim Aslam 63ebe6ab9c docs: surface runnable lifecycle examples (#3585)
Co-authored-by: Codex <codex@openai.com>
2026-07-01 20:25:33 +01:00
Asim Aslam f192c4947c docs(priorities): drop completed install task (#3581)
Co-authored-by: Codex <codex@openai.com>
2026-07-01 19:46:45 +01:00
Asim Aslam 7fd749b475 docs: lead v6 installs with latest (#3579)
Co-authored-by: Codex <codex@openai.com>
2026-07-01 19:24:10 +01:00
Asim Aslam dfe9e436e8 docs(priorities): remove completed first-agent task (#3576)
Co-authored-by: Codex <codex@openai.com>
2026-07-01 18:42:38 +01:00
Asim Aslam 72902ee6fb docs: add your first agent walkthrough (#3574)
Co-authored-by: Codex <codex@openai.com>
2026-07-01 18:27:36 +01:00
Asim Aslam 819403e940 docs(priorities): prioritize adoption on-ramp (#3571)
Co-authored-by: Codex <codex@openai.com>
2026-07-01 17:58:27 +01:00
Asim Aslam 58284c6230 harness: extend live provider deadlines (#3569)
Co-authored-by: Codex <codex@openai.com>
2026-07-01 17:33:29 +01:00
Asim Aslam 66ce68a93f community: add Discord to nav/footer/README/landing; fix stale invite code (#3567)
There was no working, prominent Discord link. Update the stale invite code
(WeMU5AGxD → G8Gk5j3uXr) everywhere it appeared (README, docs, blog, landing,
SECURITY, issue templates, contrib), and add the link prominently: the site
nav and footer includes (so it shows on every landing/docs/blog page), a
Discord badge + a Community line in the README, and a "Join Discord" button on
the landing.

Co-authored-by: Claude <noreply@anthropic.com>
2026-07-01 17:01:29 +01:00
Asim Aslam 4bd181fc21 loop: point the architect at adoption + add a daily release action (#3566)
The framework's depth is strong but the on-ramp is the adoption gap, and the
architect queue had filled entirely with internal hardening. Steer the
architect to weight the developer on-ramp/DX (first-agent tutorial,
discoverable examples, docs wayfinding, install friction, debugging) at least
as highly as internal work — a developer succeeding on their first agent
matters more than another conformance/observability increment. Adoption issues
filed: #3561-#3565.

Also add loop-release.yml: a daily patch release that tags v6.MINOR.PATCH+1
when master has new commits (pushed with the PAT so goreleaser fires), so the
installable framework tracks the loop's daily improvements instead of lapsing.
Minor/major bumps stay with the human.

Co-authored-by: Claude <noreply@anthropic.com>
2026-07-01 16:38:28 +01:00
Asim Aslam 3143767d78 docs(priorities): refresh architect queue (#3557)
goreleaser / goreleaser (push) Waiting to run
Co-authored-by: Codex <codex@openai.com>
2026-07-01 16:05:37 +01:00
Asim Aslam 666fc4b794 ci+docs: name the loop workflows by role (planner/generator/evaluator) (#3556)
Rename the autonomous-loop workflows so the Actions list maps to the
long-running-agent harness pattern (planner → generator → evaluator):
  architecture-review.yml   -> loop-architect.yml   "Loop: Architect (Planner)"
  continuous-improvement.yml -> loop-builder.yml     "Loop: Builder (Generator)"
  devrel-review.yml          -> loop-devrel.yml      "Loop: DevRel"
  harness-triage.yml         -> loop-triage.yml      "Loop: Triage (Evaluator feedback)"
harness.yml stays the shared Evaluator/CI gate (triage still matches it by the
"Harness (E2E)" name). Document the pipeline + role mapping in
CONTINUOUS_IMPROVEMENT.md, and point to it from CONTRIBUTING so the development
process is discoverable. No behavior change — schedules, gates, and required
checks are unaffected.

Co-authored-by: Claude <noreply@anthropic.com>
2026-07-01 15:59:46 +01:00
Asim Aslam 7af73b06d7 ci: auto-triage harness failures into fix issues (hill-climbing loop) (#3549)
Close the loop's feedback path: when the live provider-conformance harness
fails, harness-triage.yml dispatches Codex to triage the failing run — read
logs, root-cause, dedupe against open issues, and file scoped codex/enhancement
issues that the hourly increment loop then fixes and the next harness run
verifies. Transient flakes are ignored; breaking/architectural fixes are
escalated as needs-human rather than auto-built. No human in the middle short
of a genuine judgment call. Documented in CONTINUOUS_IMPROVEMENT.md.

Co-authored-by: Claude <noreply@anthropic.com>
2026-07-01 15:51:55 +01:00
Asim Aslam 0811234f3e agent: execute text tool call fallbacks (#3554)
Co-authored-by: Codex <codex@openai.com>
2026-07-01 15:27:14 +01:00
Asim Aslam b64a7d248d docs(priorities): refresh architect queue (#3551)
Co-authored-by: Codex <codex@openai.com>
2026-07-01 14:55:43 +01:00
Asim Aslam e7b08d914f docs(priorities): refresh architect queue (#3545)
Co-authored-by: Codex <codex@openai.com>
2026-07-01 14:03:04 +01:00
Asim Aslam 3a9455f28c harness: label provider conformance phases (#3542)
Co-authored-by: Codex <codex@openai.com>
2026-07-01 12:46:11 +01:00
Asim Aslam 05e53ec38c ci: run the live provider-conformance harness hourly, not daily (#3540)
Match the real-model conformance cadence to the dev/loop velocity so live
regressions and provider drift surface within the hour instead of up to 24h.
The mock harness already runs on every push/PR; this only changes the live
(credentialed) schedule.

Co-authored-by: Claude <noreply@anthropic.com>
2026-07-01 12:35:36 +01:00
Asim Aslam dbdd0e1d6f atlascloud: run provider conformance on a stronger (env-selectable) model (#3538)
* atlascloud: env-selectable chat model; run conformance on a stronger model

The daily provider-conformance harness fails 4/5 harnesses on Atlas Cloud —
its default chat model answers agent/tool-use conformance prompts
conversationally instead of performing the task. Atlas is currently the only
provider with a key configured, so the whole live run is red.

Make the Atlas Cloud provider honor an ATLASCLOUD_MODEL env override (falling
back to the existing default), and set it in the harness workflow to a
stronger tool-use model (Qwen3, overridable via an Actions variable). No
change to the default for normal use.

* atlascloud: use minimaxai/minimax-m3 for conformance model

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-07-01 12:17:12 +01:00
Asim Aslam 8146e29f7e docs(priorities): refresh architect queue (#3539)
Co-authored-by: Codex <codex@openai.com>
2026-07-01 12:10:17 +01:00
Asim Aslam c110774dc7 Add opt-in retries for agent tool calls (#3535)
Co-authored-by: Codex <codex@openai.com>
2026-07-01 10:57:33 +01:00
Asim Aslam c0a5775fb5 docs(priorities): refresh architect queue (#3533)
Co-authored-by: Codex <codex@openai.com>
2026-07-01 10:12:45 +01:00
Asim Aslam f844a23bb2 docs: align public AI harness facts (#3531)
Co-authored-by: Codex <codex@openai.com>
2026-07-01 09:40:28 +01:00
Asim Aslam 04e8759d41 test agent checkpoint resume after restart (#3529)
Co-authored-by: Codex <codex@openai.com>
2026-07-01 09:06:46 +01:00
Asim Aslam 78725135aa docs(priorities): refresh architect queue (#3527)
Co-authored-by: Codex <codex@openai.com>
2026-07-01 08:33:01 +01:00
Asim Aslam 2ff64ff0b2 Document canonical 0-to-hero reference path (#3522)
Co-authored-by: Codex <codex@openai.com>
2026-07-01 07:12:17 +01:00
Asim Aslam 7a8e7cd9ae docs(priorities): advance queue to 0-to-hero reference (#3520)
Co-authored-by: Codex <codex@openai.com>
2026-07-01 06:37:15 +01:00
Asim Aslam b58eed1698 Add retrieval-backed agent memory (#3518)
Co-authored-by: Codex <codex@openai.com>
2026-07-01 04:59:16 +01:00
Asim Aslam c92c9cc244 docs(priorities): refresh architect queue (#3516)
Co-authored-by: Codex <codex@openai.com>
2026-07-01 04:06:59 +01:00
Asim Aslam a2bf43e9ef test: broaden stream provider conformance (#3512)
Co-authored-by: Codex <codex@openai.com>
2026-07-01 03:37:26 +01:00
Asim Aslam 49bac7e4a8 trace scheduled flow dispatch metadata (#3510)
Co-authored-by: Codex <codex@openai.com>
2026-07-01 02:42:31 +01:00
Asim Aslam 5aac7e3ca0 docs(priorities): refresh architect queue after scheduling (#3507)
Co-authored-by: Codex <codex@openai.com>
2026-07-01 01:51:21 +01:00
Asim Aslam d86585bf5c Add scheduled flow agent harness (#3505)
Co-authored-by: Codex <codex@openai.com>
2026-07-01 01:02:29 +01:00
Asim Aslam 88e2b58711 docs(priorities): refresh architect queue (#3503)
Co-authored-by: Codex <codex@openai.com>
2026-07-01 00:38:51 +01:00
Asim Aslam d259383645 Harden agent terminal failure statuses (#3499)
Co-authored-by: Codex <codex@openai.com>
2026-07-01 00:03:21 +01:00
Asim Aslam 2d7ee300a4 docs(priorities): refresh architect queue after conformance (#3497)
Co-authored-by: Codex <codex@openai.com>
2026-06-30 23:40:19 +01:00
Asim Aslam 57fa4e3b7a Add mock provider conformance target (#3495)
Co-authored-by: Codex <codex@openai.com>
2026-06-30 23:09:19 +01:00
Asim Aslam 0f1917f26b docs(priorities): refresh architect queue after verification (#3493)
Co-authored-by: Codex <codex@openai.com>
2026-06-30 22:40:05 +01:00
Asim Aslam 6e9c5e87e9 Add flow step verification loop (#3489)
Co-authored-by: Codex <codex@openai.com>
2026-06-30 22:18:01 +01:00
Asim Aslam d8bb892425 docs(priorities): refresh architect queue after a2a continuity (#3487)
Co-authored-by: Codex <codex@openai.com>
2026-06-30 21:37:56 +01:00
Asim Aslam 064a112c6b a2a: expose resubscribe and input-required support (#3484)
Co-authored-by: Codex <codex@openai.com>
2026-06-30 21:23:43 +01:00
Asim Aslam 24d103c658 docs(priorities): refresh architect queue after memory (#3482)
Co-authored-by: Codex <codex@openai.com>
2026-06-30 20:47:39 +01:00
Asim Aslam 2d8e3da943 blog: expand /blog/32 into a field guide on agent frameworks (#3478)
* blog+docs: drop the word "bet" from the tRPC-Agent-Go comparison

Reword "two bets" / "opposite bet" / "the bet is" to approaches / premise /
principle across blog/32 and the comparison guide.

* blog: expand /blog/32 into a field guide on agent frameworks

Roughly double the length with deeper context: the first wave (LangChain &
co.), the two layers of a harness (intra-agent vs operational), loop
engineering and the move to scheduled/looping/work-performing agents, a
survey of where the frameworks are going (LangGraph, CrewAI, AutoGen, ADK,
tRPC-Agent-Go), then Go Micro's "an agent is a service" position, the honest
tRPC-Agent-Go contrast, and MCP/A2A interop. Drops the word "bet" throughout.

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-30 20:20:14 +01:00
Asim Aslam 3081dab246 Add agent memory summarizer hook (#3479)
Co-authored-by: Codex <codex@openai.com>
2026-06-30 20:18:23 +01:00
Asim Aslam fdc422c16e blog+docs: position go-micro vs tRPC-Agent-Go (agent = service) (#3475)
Add a fair, honest positioning piece on the architectural fork with
tRPC-Agent-Go (an agent SDK alongside your services / graph DSL) vs Go Micro
(one runtime where an agent is a service, every endpoint a tool, durable
flows not a graph DSL). New blog post /blog/32 + a parallel section in the
existing comparison guide; honest about where tRPC-Agent-Go is ahead
(eval, self-evolution, RAG) and that they interoperate over MCP/A2A.

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-30 19:45:52 +01:00
Asim Aslam 5e3f8db193 docs(priorities): refresh architect queue for memory (#3476)
Co-authored-by: Codex <codex@openai.com>
2026-06-30 19:41:17 +01:00
Asim Aslam f5bf5f7987 Wire A2A streaming through agent StreamAsk (#3471)
Co-authored-by: Codex <codex@openai.com>
2026-06-30 19:18:23 +01:00
Asim Aslam 3ec12b7c72 Trace agent checkpoint resume events (#3468)
Co-authored-by: Codex <codex@openai.com>
2026-06-30 18:22:00 +01:00
Asim Aslam fa4d4b7f6a docs(priorities): refresh architect queue after failure hardening (#3466)
Co-authored-by: Codex <codex@openai.com>
2026-06-30 17:50:23 +01:00
Asim Aslam 43beaafab5 flow: classify workflow failure kinds (#3464)
Co-authored-by: Codex <codex@openai.com>
2026-06-30 17:30:45 +01:00
Asim Aslam 21a20005cb docs(priorities): refresh architect queue (#3462)
Co-authored-by: Codex <codex@openai.com>
2026-06-30 16:51:07 +01:00
Asim Aslam e1b3c587aa Add configurable provider conformance dispatch (#3459)
Co-authored-by: Codex <codex@openai.com>
2026-06-30 16:31:49 +01:00
Asim Aslam da2bbab80c docs(priorities): refresh architect queue (#3457)
Co-authored-by: Codex <codex@openai.com>
2026-06-30 15:55:52 +01:00
Asim Aslam 5a59e1ece4 agent: verify durable resume example (#3452)
Co-authored-by: Codex <codex@openai.com>
2026-06-30 15:26:32 +01:00
Asim Aslam aea03ba9e7 priorities: queue the flow verification/grader loop (#3435) (#3436)
Add the verification loop as a ranked priority — the one missing layer from
the four-loop framing (agent / verification / event-driven / hill-climbing):
flow.Verify + flow.LLMGrader to grade a step's output against a rubric and
retry with feedback. The architect will re-rank on its next pass.

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-30 15:17:18 +01:00
Asim Aslam 54bc05e48f docs(priorities): advance agent durability queue (#3450)
Co-authored-by: Codex <codex@openai.com>
2026-06-30 14:40:14 +01:00
Asim Aslam 3ef0d98a16 flow: analyze run traces for optimization (#3447)
Co-authored-by: Codex <codex@openai.com>
2026-06-30 14:25:15 +01:00
Asim Aslam 5a6c8d8b30 docs(priorities): advance architect queue (#3445)
Co-authored-by: Codex <codex@openai.com>
2026-06-30 13:41:58 +01:00
Asim Aslam 1cd918c2b9 flow: add verification grader loop (#3443)
Co-authored-by: Codex <codex@openai.com>
2026-06-30 13:28:53 +01:00
Asim Aslam e96d4a67bc docs(priorities): refresh architect queue (#3441)
Co-authored-by: Codex <codex@openai.com>
2026-06-30 13:09:37 +01:00
Asim Aslam 8994fd03f6 Add A2A fallback provider conformance harness (#3438)
Co-authored-by: Codex <codex@openai.com>
2026-06-30 12:37:40 +01:00
Asim Aslam 0595130f16 run: surface MCP tools in the micro run banner by default (#3434)
The gateway already serves /mcp/tools on :8080 unconditionally (every
endpoint is an AI-callable tool), but the startup banner only printed an MCP
line when --mcp-address was set — so the live `micro run` experience hid the
harness's signature feature even though it was running, and didn't match the
README. Always advertise MCP Tools on the gateway address; keep the optional
standalone MCP-protocol server (--mcp-address) as a clearly separate line.
No behavior change — banner output only.

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-30 11:21:26 +01:00
Asim Aslam 37eccc425e docs(priorities): advance provider conformance queue (#3433)
Co-authored-by: Codex <codex@openai.com>
2026-06-30 11:14:39 +01:00
Asim Aslam 010e0fe57c Classify agent run failure summaries (#3430)
Co-authored-by: Codex <codex@openai.com>
2026-06-30 10:55:14 +01:00
Asim Aslam 113f268268 docs: align DevRel public surface facts (#3428)
Co-authored-by: Codex <codex@openai.com>
2026-06-30 09:26:20 +01:00
Asim Aslam c10697f08d docs(priorities): advance resilience queue (#3427)
Co-authored-by: Codex <codex@openai.com>
2026-06-30 09:25:32 +01:00
Asim Aslam f61f3dc04d test: add AI stream provider conformance (#3423)
Co-authored-by: Codex <codex@openai.com>
2026-06-30 08:56:12 +01:00
Asim Aslam d9e6c68938 docs(priorities): refresh architect queue (#3421)
Co-authored-by: Codex <codex@openai.com>
2026-06-30 07:40:48 +01:00
Asim Aslam 8847668c83 Improve agent telemetry error classification (#3418)
Co-authored-by: Codex <codex@openai.com>
2026-06-30 07:06:38 +01:00
Asim Aslam e45bf3d114 docs(priorities): remove completed durable resume item (#3416)
Co-authored-by: Codex <codex@openai.com>
2026-06-30 05:50:51 +01:00
Asim Aslam 98d1f58cd6 Add durable agent resume example (#3414)
Co-authored-by: Codex <codex@openai.com>
2026-06-30 04:56:14 +01:00
Asim Aslam 51158ed2a7 docs(priorities): refresh architect queue (#3412)
Co-authored-by: Codex <codex@openai.com>
2026-06-30 04:04:11 +01:00
Asim Aslam 09bf82d4f6 fix a2a stream fallback (#3410)
Co-authored-by: Codex <codex@openai.com>
2026-06-30 03:26:42 +01:00
Asim Aslam 7d77f31ae2 docs(priorities): advance architect queue (#3408)
Co-authored-by: Codex <codex@openai.com>
2026-06-30 02:47:16 +01:00
Asim Aslam 2dbf70d0ed Guard terminal agent checkpoints on resume (#3406)
Co-authored-by: Codex <codex@openai.com>
2026-06-30 02:34:43 +01:00
Asim Aslam 136c24ad5f docs(priorities): advance architect queue (#3404)
Co-authored-by: Codex <codex@openai.com>
2026-06-30 01:28:16 +01:00
Asim Aslam dc93addb10 ci: consolidate developer flow harness (#3399)
Co-authored-by: Codex <codex@openai.com>
2026-06-30 00:59:24 +01:00
Asim Aslam 09b4b8cc85 docs(priorities): drop shipped reliability item (#3397)
Co-authored-by: Codex <codex@openai.com>
2026-06-30 00:29:11 +01:00
Asim Aslam 7b8139ca3c Harden agent tool execution timeouts (#3395)
Co-authored-by: Codex <codex@openai.com>
2026-06-29 23:55:43 +01:00
Asim Aslam ea6f7f6976 docs(priorities): refresh architect queue (#3393)
Co-authored-by: Codex <codex@openai.com>
2026-06-29 23:32:10 +01:00
Asim Aslam b25a9171c5 ci: fold agent checks into provider conformance (#3389)
Co-authored-by: Codex <codex@openai.com>
2026-06-29 23:08:09 +01:00
Asim Aslam 2fe4eb71d1 docs(priorities): refresh architect queue (#3387)
Co-authored-by: Codex <codex@openai.com>
2026-06-29 22:37:54 +01:00
Asim Aslam c4e110c77f Add deploy dry-run harness checkpoint (#3384)
Co-authored-by: Codex <codex@openai.com>
2026-06-29 22:14:28 +01:00
Asim Aslam e4bb9d6bc7 docs(priorities): refresh architect queue (#3382)
Co-authored-by: Codex <codex@openai.com>
2026-06-29 21:43:53 +01:00
Asim Aslam 562deb0557 docs(examples): maintain zero-to-hero support path (#3379)
Co-authored-by: Codex <codex@openai.com>
2026-06-29 21:24:45 +01:00
Asim Aslam 551beb0858 docs(priorities): remove completed A2A skill item (#3377)
Co-authored-by: Codex <codex@openai.com>
2026-06-29 20:44:39 +01:00
Asim Aslam d831ba2c45 Add typed A2A skill endpoints (#3375)
Co-authored-by: Codex <codex@openai.com>
2026-06-29 20:21:41 +01:00
Asim Aslam a14633b9e8 docs(priorities): remove completed human-input item (#3373)
Co-authored-by: Codex <codex@openai.com>
2026-06-29 19:45:54 +01:00
Asim Aslam 4cc1ebb315 Document canceled human-input resumes (#3371)
Co-authored-by: Codex <codex@openai.com>
2026-06-29 19:24:26 +01:00
Asim Aslam 38ff084756 docs(priorities): refresh architect queue (#3369)
Co-authored-by: Codex <codex@openai.com>
2026-06-29 19:07:01 +01:00
Asim Aslam 585dd789a4 Redact agent run inputs from traces (#3366)
Co-authored-by: Codex <codex@openai.com>
2026-06-29 18:31:20 +01:00
Asim Aslam 971bfdb954 agent: reuse tools instance in setupWithToolHandler (fix StreamAsk tool resolution) (#3365)
goreleaser / goreleaser (push) Waiting to run
2026-06-29 18:24:21 +01:00
Asim Aslam 57873cc5a5 docs(priorities): refresh architect queue (#3363)
Co-authored-by: Codex <codex@openai.com>
2026-06-29 18:04:52 +01:00
Asim Aslam 86bfced452 Wire getting-started harness into make (#3360)
Co-authored-by: Codex <codex@openai.com>
2026-06-29 16:58:29 +01:00
Asim Aslam 8863d27623 events: WithStore option for a durable, replayable stream (#3357)
goreleaser / goreleaser (push) Waiting to run
* events: add WithStore option for a durable stream

* events: honor injected store in NewStream
2026-06-29 15:25:14 +01:00
Asim Aslam efb4b3d191 docs(priorities): refresh architect queue (#3355)
Co-authored-by: Codex <codex@openai.com>
2026-06-29 14:27:42 +01:00
Asim Aslam b83b8d164f Add stream resume for agent checkpoints (#3352)
Co-authored-by: Codex <codex@openai.com>
2026-06-29 13:19:17 +01:00
Asim Aslam 11ff58fec7 docs(priorities): refresh architect queue (#3350)
Co-authored-by: Codex <codex@openai.com>
2026-06-29 12:41:44 +01:00
Asim Aslam f1504507a3 agent: add tool-aware stream ask (#3347)
Co-authored-by: Codex <codex@openai.com>
2026-06-29 11:13:52 +01:00
Asim Aslam a2a7ee17e0 docs(priorities): drop shipped memory item (#3345)
Co-authored-by: Codex <codex@openai.com>
2026-06-29 10:38:20 +01:00
Asim Aslam e704b0e61b docs(priorities): seed streaming-tools (#3341) and multi-skill a2a (#3342) (#3343)
Queue the Next-phase agent streaming item and the a2a multi-skill gap that
block a real consumer from retiring its bespoke planner / A2A handler. The
architecture-review pass re-ranks from here.
2026-06-29 10:26:14 +01:00
Asim Aslam 317bb300ae agent: harden compacted memory resume (#3339)
Co-authored-by: Codex <codex@openai.com>
2026-06-29 09:25:59 +01:00
Asim Aslam ca82b85955 Update architecture priorities after tracing (#3337)
Co-authored-by: Codex <codex@openai.com>
2026-06-29 08:44:29 +01:00
Asim Aslam a99c776880 gateway/mcp: configurable initialize (serverInfo, protocol version) + named not-found (#3335)
goreleaser / goreleaser (push) Waiting to run
* gateway/mcp: configurable initialize + named not-found

NewHandler takes HandlerOptions: WithServerInfo(name, version) and WithProtocolVersion set the initialize response so a product can brand the endpoint instead of advertising go-micro-mcp/2024-11-05. ManualResolver's not-found error now includes the tool name.

* gateway/mcp: configurable initialize + named not-found

NewHandler takes HandlerOptions: WithServerInfo(name, version) and WithProtocolVersion set the initialize response so a product can brand the endpoint instead of advertising go-micro-mcp/2024-11-05. ManualResolver's not-found error now includes the tool name.
2026-06-29 07:22:07 +01:00
Asim Aslam b8ca921ae8 gateway/mcp: richer resolver Call (CallResult/isError, coded errors) + notifications (#3334)
goreleaser / goreleaser (push) Waiting to run
* gateway/mcp: richer resolver Call + spec-correct HTTP handler

Resolver.Call now returns (*CallResult, error): a tool that ran but failed sets CallResult.IsError (returned as a tools/call result with isError:true, per the MCP spec), while a protocol/pre-check failure returns an error -- an *RPCError carries a specific JSON-RPC code. The HTTP handler also answers notifications/* (and id-less requests) with 204 and no body.

* gateway/mcp: richer resolver Call + spec-correct HTTP handler

Resolver.Call now returns (*CallResult, error): a tool that ran but failed sets CallResult.IsError (returned as a tools/call result with isError:true, per the MCP spec), while a protocol/pre-check failure returns an error -- an *RPCError carries a specific JSON-RPC code. The HTTP handler also answers notifications/* (and id-less requests) with 204 and no body.

* gateway/mcp: richer resolver Call + spec-correct HTTP handler

Resolver.Call now returns (*CallResult, error): a tool that ran but failed sets CallResult.IsError (returned as a tools/call result with isError:true, per the MCP spec), while a protocol/pre-check failure returns an error -- an *RPCError carries a specific JSON-RPC code. The HTTP handler also answers notifications/* (and id-less requests) with 204 and no body.
2026-06-29 07:19:39 +01:00
Asim Aslam 159963ab39 agent: trace model attempt metadata (#3333)
Co-authored-by: Codex <codex@openai.com>
2026-06-29 07:16:19 +01:00
Asim Aslam 59397834b4 gateway/mcp: swappable Resolver + mountable JSON-RPC HTTP handler (#3331)
goreleaser / goreleaser (push) Waiting to run
* gateway/mcp: swappable Resolver + mountable JSON-RPC HTTP handler

Adds a Resolver interface (Manual/Registry) so the tool source is
pluggable, and NewHandler(resolver) serving standard MCP JSON-RPC over
HTTP as an http.Handler you can mount on your own server. Neither
resolver exposes the internal store/broker tools. Additive — the
existing Serve() path is unchanged.

* gateway/mcp: swappable Resolver + mountable JSON-RPC HTTP handler

Adds a Resolver interface (Manual/Registry) so the tool source is
pluggable, and NewHandler(resolver) serving standard MCP JSON-RPC over
HTTP as an http.Handler you can mount on your own server. Neither
resolver exposes the internal store/broker tools. Additive — the
existing Serve() path is unchanged.

* gateway/mcp: swappable Resolver + mountable JSON-RPC HTTP handler

Adds a Resolver interface (Manual/Registry) so the tool source is
pluggable, and NewHandler(resolver) serving standard MCP JSON-RPC over
HTTP as an http.Handler you can mount on your own server. Neither
resolver exposes the internal store/broker tools. Additive — the
existing Serve() path is unchanged.
2026-06-29 07:03:23 +01:00
Asim Aslam ee996afd39 Update architecture priorities after streaming (#3330)
Co-authored-by: Codex <codex@openai.com>
2026-06-29 06:36:13 +01:00
Asim Aslam 236c5851c2 Add OpenAI-compatible streaming providers (#3327)
Co-authored-by: Codex <codex@openai.com>
2026-06-29 05:01:51 +01:00
Asim Aslam 5ee3a5224f ai/atlascloud: replace stale Stream_NotImplemented test (#3324)
goreleaser / goreleaser (push) Waiting to run
Streaming is implemented now (v6.3.3); the old test expected
ErrStreamingUnsupported and failed. Replace it with a real SSE streaming
test (httptest) that also asserts stream_options.include_usage and the
final usage chunk.
2026-06-29 03:36:39 +01:00
Asim Aslam c9f1ac921f Update architect priorities after agent resume (#3322)
Harness (E2E) / Harnesses (mock LLM) (push) Waiting to run
Harness (E2E) / Provider harnesses (live LLM conformance) (push) Waiting to run
Lint / golangci-lint (push) Waiting to run
Run Tests / Unit Tests (push) Waiting to run
Run Tests / Etcd Integration Tests (push) Waiting to run
Co-authored-by: Codex <codex@openai.com>
2026-06-29 02:49:27 +01:00
Asim Aslam c395010565 Expose durable agent resume APIs (#3319)
Co-authored-by: Codex <codex@openai.com>
2026-06-29 02:36:07 +01:00
Asim Aslam dca263f301 Update architect priorities after CLI inspection (#3317)
Co-authored-by: Codex <codex@openai.com>
2026-06-29 01:27:51 +01:00
Asim Aslam 3540bf5a50 Add CLI inspect command for run history (#3313)
Co-authored-by: Codex <codex@openai.com>
2026-06-29 00:57:40 +01:00
Asim Aslam 0d86fd5bcd Update architect priorities after failure hardening (#3311)
Co-authored-by: Codex <codex@openai.com>
2026-06-29 00:33:17 +01:00
Asim Aslam 205d6a55a3 Respect provider retry-after backoff hints (#3309)
Co-authored-by: Codex <codex@openai.com>
2026-06-28 23:57:17 +01:00
Asim Aslam 7588a427cc Update architect priorities (#3307)
Co-authored-by: Codex <codex@openai.com>
2026-06-28 23:28:55 +01:00
Asim Aslam 7b9937068d ai: surface token usage on streaming responses (#3304)
goreleaser / goreleaser (push) Waiting to run
* ai/atlascloud: surface token usage on streams

Request stream_options.include_usage and return the final usage chunk
as a Response with Usage set, so streaming callers can record usage.

* ai/openai: surface token usage on streams

Request stream_options.include_usage and return the final usage chunk
as a Response with Usage set, so streaming callers can record usage.
2026-06-28 23:13:25 +01:00
Asim Aslam f8d8cb39a7 Document provider conformance scheduling (#3303)
Co-authored-by: Codex <codex@openai.com>
2026-06-28 22:55:49 +01:00
Asim Aslam 87a0c0c93b ai/atlascloud: implement streaming (#3301)
goreleaser / goreleaser (push) Waiting to run
Atlas exposes an OpenAI-compatible SSE chat endpoint; emit content
deltas as they arrive instead of returning ErrStreamingUnsupported.
2026-06-28 22:42:03 +01:00
Copilot f31a7acf0b fix: gofmt formatting in ai/anthropic/anthropic.go (#3299)
* Initial plan

* fix: remove extra blank line in ai/anthropic/anthropic.go (gofmt)

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
2026-06-28 22:38:32 +01:00
Asim Aslam 4279a5eed3 ai: add WithMaxTokens option (#3300)
goreleaser / goreleaser (push) Waiting to run
* ai: add WithMaxTokens option

Let callers cap response length; providers send max_tokens when set
(anthropic keeps its 8192 default otherwise).

* ai: add WithMaxTokens option

Let callers cap response length; providers send max_tokens when set
(anthropic keeps its 8192 default otherwise).

* ai: add WithMaxTokens option

Let callers cap response length; providers send max_tokens when set
(anthropic keeps its 8192 default otherwise).

* ai: add WithMaxTokens option

Let callers cap response length; providers send max_tokens when set
(anthropic keeps its 8192 default otherwise).
2026-06-28 22:37:50 +01:00
Asim Aslam c39a846d3b Update architecture priorities (#3298)
Co-authored-by: Codex <codex@openai.com>
2026-06-28 22:31:33 +01:00
Asim Aslam b707c7e305 ai: thread Request.Messages into provider requests (#3293)
goreleaser / goreleaser (push) Waiting to run
* ai/atlascloud: thread Request.Messages into the request

Fold conversation history (req.Messages) between the system prompt and
the final user prompt so multi-turn context reaches the model.

Refs #3292

* ai/openai: thread Request.Messages into the request

Fold conversation history (req.Messages) between the system prompt and
the final user prompt so multi-turn context reaches the model.

Refs #3292

* ai/anthropic: thread Request.Messages into the request

Fold conversation history (req.Messages) between the system prompt and
the final user prompt so multi-turn context reaches the model.

Refs #3292
2026-06-28 22:19:59 +01:00
Asim Aslam 5bfc37708d Add support example smoke test (#3291)
Co-authored-by: Codex <codex@openai.com>
2026-06-28 21:58:56 +01:00
Asim Aslam 4d852c5e36 Update architect priorities after deploy contract (#3289)
Co-authored-by: Codex <codex@openai.com>
2026-06-28 21:32:15 +01:00
Asim Aslam f7a3e8461e test deploy inner-loop contract (#3287)
Co-authored-by: Codex <codex@openai.com>
2026-06-28 21:07:20 +01:00
Asim Aslam 87eb540a04 Update architect priorities for DX gaps (#3285)
Co-authored-by: Codex <codex@openai.com>
2026-06-28 20:35:29 +01:00
Asim Aslam 48e05385c7 Add agent human input pause resume (#3281)
Co-authored-by: Codex <codex@openai.com>
2026-06-28 20:04:25 +01:00
Asim Aslam cb10149f54 Update architect priorities after memory work (#3279)
Co-authored-by: Codex <codex@openai.com>
2026-06-28 19:24:54 +01:00
Asim Aslam 66438697b3 Improve compacting memory recall ranking (#3276)
Co-authored-by: Codex <codex@openai.com>
2026-06-28 19:03:39 +01:00
Asim Aslam 6e1c11ca74 Update architect priorities after A2A handoffs (#3274)
Co-authored-by: Codex <codex@openai.com>
2026-06-28 18:33:59 +01:00
Asim Aslam 44c08a6bd2 Add A2A resubscribe and input-required handoffs (#3271)
Co-authored-by: Codex <codex@openai.com>
2026-06-28 17:59:49 +01:00
Asim Aslam 9c01202599 Update architect priorities after OTel spans (#3269)
Co-authored-by: Codex <codex@openai.com>
2026-06-28 17:32:36 +01:00
Asim Aslam b4cfe51115 Emit agent run events on OTel spans (#3267)
Co-authored-by: Codex <codex@openai.com>
2026-06-28 17:04:26 +01:00
Asim Aslam 2221834707 Update architect priorities after streaming conformance (#3265)
Co-authored-by: Codex <codex@openai.com>
2026-06-28 16:33:06 +01:00
Asim Aslam 5813f53117 test ai streaming conformance (#3263)
Co-authored-by: Codex <codex@openai.com>
2026-06-28 16:17:23 +01:00
Asim Aslam 72e6161b02 Update architect priorities after agent checkpointing (#3261)
Co-authored-by: Codex <codex@openai.com>
2026-06-28 15:41:44 +01:00
Asim Aslam 1789819c39 Add agent tool checkpoint replay protection (#3259)
Co-authored-by: Codex <codex@openai.com>
2026-06-28 15:22:11 +01:00
Asim Aslam 8676dcacf2 Update architect priority queue after 0-to-hero (#3257)
Co-authored-by: Codex <codex@openai.com>
2026-06-28 14:38:08 +01:00
Asim Aslam 22b3b9ca22 Add zero-to-hero CI reference scenario (#3252)
Co-authored-by: Codex <codex@openai.com>
2026-06-28 14:09:17 +01:00
Asim Aslam 4ca8948ba4 Update architect priorities after 0-to-1 verification (#3250)
Co-authored-by: Codex <codex@openai.com>
2026-06-28 13:34:18 +01:00
Asim Aslam 28cbf0be7e test: verify scaffolded service run and call contract (#3248)
Co-authored-by: Codex <codex@openai.com>
2026-06-28 13:14:22 +01:00
Asim Aslam e8e6cb1210 Update architect priorities after conformance (#3246)
Co-authored-by: Codex <codex@openai.com>
2026-06-28 12:40:00 +01:00
Asim Aslam 2a06a043bd ci: run live agent provider conformance (#3244)
Co-authored-by: Codex <codex@openai.com>
2026-06-28 12:23:04 +01:00
Asim Aslam 6eef58f815 Update architect priorities (#3242)
Co-authored-by: Codex <codex@openai.com>
2026-06-28 11:13:36 +01:00
Asim Aslam 6da799d64f Classify AI retry failures (#3238)
Co-authored-by: Codex <codex@openai.com>
2026-06-28 10:42:37 +01:00
Asim Aslam 220b370641 Update architect priorities (#3236)
Co-authored-by: Codex <codex@openai.com>
2026-06-28 10:08:20 +01:00
Asim Aslam ac2163ef49 docs: align public TLS and A2A status (#3231)
Co-authored-by: Codex <codex@openai.com>
2026-06-28 09:20:26 +01:00
Asim Aslam 9d6814f5ae docs: refresh roadmap after A2A task support (#3229)
Co-authored-by: Codex <codex@openai.com>
2026-06-28 08:55:36 +01:00
Asim Aslam 929cd1ab1d Add A2A task continuation and push callbacks (#3226)
Co-authored-by: Codex <codex@openai.com>
2026-06-28 07:09:03 +01:00
Asim Aslam fe651b4d01 Update architect priorities after x402 (#3224)
Co-authored-by: Codex <codex@openai.com>
2026-06-28 06:35:10 +01:00
Asim Aslam 05ee980bf5 Harden x402 spend caps (#3222)
Co-authored-by: Codex <codex@openai.com>
2026-06-28 04:54:15 +01:00
Asim Aslam e1d19c4cb5 Update architect priorities after memory and HITL (#3220)
Co-authored-by: Codex <codex@openai.com>
2026-06-28 04:08:37 +01:00
Asim Aslam 61f873174c Add durable approval pause for agents (#3218)
Co-authored-by: Codex <codex@openai.com>
2026-06-28 03:37:50 +01:00
Asim Aslam 71581e9a61 Add agent memory compaction controls (#3216)
Co-authored-by: Codex <codex@openai.com>
2026-06-28 02:39:06 +01:00
Asim Aslam 892b4f185d Update architect priority queue after lifecycle hooks (#3213)
Co-authored-by: Codex <codex@openai.com>
2026-06-28 01:30:09 +01:00
Asim Aslam 30f53e42a7 Expose model retry attempt metadata (#3207)
Co-authored-by: Codex <codex@openai.com>
2026-06-28 00:56:21 +01:00
Asim Aslam 016eb82a32 Update architect priorities after streaming (#3205)
Co-authored-by: Codex <codex@openai.com>
2026-06-28 00:29:03 +01:00
Asim Aslam a576f65b08 Improve A2A streaming task lifecycle (#3203)
Co-authored-by: Codex <codex@openai.com>
2026-06-27 23:57:24 +01:00
Asim Aslam 07f0d30aea Update architect priority queue after observability (#3201)
Co-authored-by: Codex <codex@openai.com>
2026-06-27 23:26:33 +01:00
Asim Aslam 3db9617f43 Add agent trace provider helper (#3198)
Co-authored-by: Codex <codex@openai.com>
2026-06-27 23:02:09 +01:00
Asim Aslam c19e4829ba Update architect priority queue (#3196)
Co-authored-by: Codex <codex@openai.com>
2026-06-27 22:28:28 +01:00
Asim Aslam f37ed42bf3 Add registry service readiness check (#3194)
Co-authored-by: Codex <codex@openai.com>
2026-06-27 21:56:22 +01:00
Asim Aslam 114cd7e19e Update architect priorities after conformance (#3192)
Co-authored-by: Codex <codex@openai.com>
2026-06-27 21:30:21 +01:00
Asim Aslam 28fc2ea340 Add agent provider conformance matrix (#3190)
Co-authored-by: Codex <codex@openai.com>
2026-06-27 21:08:04 +01:00
Asim Aslam 38f5c13e65 Update architect priority queue (#3188)
Co-authored-by: Codex <codex@openai.com>
2026-06-27 20:37:32 +01:00
Asim Aslam 27f5e2be52 Add OpenAI streaming path (#3185)
Co-authored-by: Codex <codex@openai.com>
2026-06-27 20:01:45 +01:00
Asim Aslam 1fa7584be8 Update architect priority queue (#3183)
Co-authored-by: Codex <codex@openai.com>
2026-06-27 19:34:11 +01:00
Asim Aslam e8c632456a Add checkpointed agent run resume (#3180)
Co-authored-by: Codex <codex@openai.com>
2026-06-27 19:00:18 +01:00
Asim Aslam 9a410cbe8b Update architect priority queue (#3176)
Co-authored-by: Codex <codex@openai.com>
2026-06-27 17:46:45 +01:00
Asim Aslam 620374ef22 Add zero-to-hero harness test contract (#3174)
Co-authored-by: Codex <codex@openai.com>
2026-06-27 17:08:04 +01:00
Asim Aslam 31556b310e loop: continuous architect + lead the North Star with the mission/canon (#3172)
* ci: run the architect continuously as the founder lens

Make the architect a continuous overseer (hourly at :59, just before the :29
increment) instead of an every-few-days check-in. Each run it tracks live state
(what merged, what's in flight), keeps the roadmap priorities live, and judges
cohesion across harness/framework/dev-UX plus missing pieces and realignment —
re-ranking internal/docs/PRIORITIES.md to match reality. It only opens a PR when
the ranking actually changes (otherwise it just posts an assessment and closes
its issue), to avoid churn.

* thesis: lead the North Star with the mission, grounded in the canon

Instill the years of context the loop was missing: the vision lives in the
corpus (blog, README, website), not a single doc. Lead THESIS.md with an
explicit Mission — "what problem we solve" (make building an agent as easy as
building a service, on one runtime, because an agent is a distributed system),
distilled from the corpus — and name the blog/README/website as the canon the
North Star is a distillation of and must stay faithful to. Wire the architect to
judge every priority against the mission and re-derive alignment from the canon,
flagging drift in either direction (work vs mission, or thesis vs the blog).

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-27 16:58:24 +01:00
Asim Aslam 0e67971c53 ci: couple architect and increment loop through a ranked priority queue (#3171)
The architect now prioritizes the roadmap + an internal scan into a single
ranked, issue-linked queue in internal/docs/PRIORITIES.md (re-ranked each run),
and the hourly increment loop works the top open item from that queue instead
of independently guessing each hour — falling back to its own judgment only
when the queue is empty. So work is roadmap-driven by default and the human can
redirect by reordering the file or its issues.

- New internal/docs/PRIORITIES.md (seeded from the roadmap + open issues).
- architecture-review.yml: architect owns/re-ranks PRIORITIES.md and keeps each
  top item backed by a scoped issue.
- continuous-improvement.yml: pick the top open queue item; close both the
  priority issue and the run tracker.
- CONTINUOUS_IMPROVEMENT.md: document the architect → queue → increment pipeline.

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-27 16:18:03 +01:00
Asim Aslam 2af5e6ae8f Record A2A agent replies in task history (#3170)
Co-authored-by: Codex <codex@openai.com>
2026-06-27 16:09:30 +01:00
Asim Aslam 656c4ea1e7 flow: tag single-step run info as flow (#3168)
Co-authored-by: Codex <codex@openai.com>
2026-06-27 15:16:38 +01:00
Asim Aslam 4a09b4469a Add flow execution timeout option (#3164)
Co-authored-by: Codex <codex@openai.com>
2026-06-27 14:04:58 +01:00
Alexander Serheyev 25d66f737d fix: retract phantom modules for cmd paths (#3154)
* fix: retract phantom modules for cmd and cmd/micro

* fix: remove temporary go.mod files to restore build
2026-06-27 13:19:53 +01:00
Asim Aslam 45d68c932e Track parent run IDs for durable flows (#3162)
Co-authored-by: Codex <codex@openai.com>
2026-06-27 13:07:18 +01:00
Asim Aslam c5c08e24d8 test: cover micro new no-mcp contract (#3160)
Co-authored-by: Codex <codex@openai.com>
2026-06-27 12:17:19 +01:00
Asim Aslam 8a0f4a7636 Add flow step context to run info (#3158)
Co-authored-by: Codex <codex@openai.com>
2026-06-27 11:22:23 +01:00
Asim Aslam bcf2c92931 Add A2A completed-task streaming (#3156)
Co-authored-by: Codex <codex@openai.com>
2026-06-27 10:29:01 +01:00
Asim Aslam 57ca94a88b docs: align public x402 flag examples (#3153)
Co-authored-by: Codex <codex@openai.com>
2026-06-27 09:08:38 +01:00
Asim Aslam ba231efe71 Update README.md 2026-06-27 07:08:08 +01:00
Asim Aslam f755eadd47 Propagate flow checkpoint failures (#3150)
Co-authored-by: Codex <codex@openai.com>
2026-06-27 06:55:56 +01:00
Asim Aslam 467c937873 Improve flow run history validation (#3148)
Co-authored-by: Codex <codex@openai.com>
2026-06-27 04:55:49 +01:00
Asim Aslam 3f45771840 Publish provider conformance summaries (#3146)
Co-authored-by: Codex <codex@openai.com>
2026-06-27 03:29:12 +01:00
Asim Aslam c9e045961d Add flow run stage filtering (#3144)
Co-authored-by: Codex <codex@openai.com>
2026-06-27 02:28:39 +01:00
Asim Aslam 590aacb518 docs: keep AI provider capability matrix verified (#3142)
Co-authored-by: Codex <codex@openai.com>
2026-06-27 00:58:39 +01:00
Asim Aslam 87eb5ce665 Add filters for flow run history (#3140)
Co-authored-by: Codex <codex@openai.com>
2026-06-27 00:00:58 +01:00
Asim Aslam ed904aa6ad Propagate flow run lineage to agent chats (#3138)
Co-authored-by: Codex <codex@openai.com>
2026-06-26 23:04:18 +01:00
Asim Aslam 59d028b8e1 test ai retry policy semantics (#3136)
Co-authored-by: Codex <codex@openai.com>
2026-06-26 22:16:59 +01:00
Asim Aslam 19818ad638 Expose streaming in provider capabilities (#3134)
Co-authored-by: Codex <codex@openai.com>
2026-06-26 21:18:38 +01:00
Asim Aslam 993ce668b2 Add provider capability markdown export (#3132)
Co-authored-by: Codex <codex@openai.com>
2026-06-26 20:20:08 +01:00
Asim Aslam 1d412fa6f5 Trigger test workflow on PR updates (#3130)
Co-authored-by: Codex <codex@openai.com>
2026-06-26 19:14:39 +01:00
Asim Aslam 271c27c44f Validate durable flow step names (#3128)
Co-authored-by: Codex <codex@openai.com>
2026-06-26 18:18:06 +01:00
Asim Aslam cefc9438c4 Add JSON output for AI provider capabilities (#3126)
Co-authored-by: Codex <codex@openai.com>
2026-06-26 17:31:18 +01:00
Asim Aslam af39aac297 Add provider conformance JSON summary (#3124)
Co-authored-by: Codex <codex@openai.com>
2026-06-26 16:31:25 +01:00
Asim Aslam 41717aaa9a ci: run 0-to-1 scaffold contract in harness (#3122)
Co-authored-by: Codex <codex@openai.com>
2026-06-26 15:26:25 +01:00
Asim Aslam 5d1137d8f9 docs: add provider conformance matrix (#3106)
Co-authored-by: Codex <codex@openai.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
2026-06-26 14:30:51 +01:00
Asim Aslam a14b3e79e2 docs: add provider conformance matrix (#3120)
Co-authored-by: Codex <codex@openai.com>
2026-06-26 14:23:56 +01:00
Asim Aslam 130022e544 Record full agent timelines without tracing (#3118)
Co-authored-by: Codex <codex@openai.com>
2026-06-26 13:27:08 +01:00
Asim Aslam 0d3f3f2be5 Record agent run timelines without tracing (#3116)
Co-authored-by: Codex <codex@openai.com>
2026-06-26 12:35:03 +01:00
Asim Aslam ae91863343 Add trace filter for agent runs (#3114)
Co-authored-by: Codex <codex@openai.com>
2026-06-26 10:50:49 +01:00
Asim Aslam 72f8067e57 docs: finish constructor example cleanup (#3112)
Co-authored-by: Codex <codex@openai.com>
2026-06-26 09:30:58 +01:00
Asim Aslam 8533306e64 docs: align service constructor examples (#3111)
Co-authored-by: Codex <codex@openai.com>
2026-06-26 09:29:36 +01:00
Asim Aslam 384987da9f docs: align service constructor examples (#3110)
Co-authored-by: Codex <codex@openai.com>
2026-06-26 09:26:40 +01:00
Asim Aslam ddde9472fc Expose agent chat run identifiers (#3108)
Co-authored-by: Codex <codex@openai.com>
2026-06-26 08:53:33 +01:00
Asim Aslam d7a74735c8 Add AI provider capability command (#3104)
Co-authored-by: Codex <codex@openai.com>
2026-06-26 04:55:16 +01:00
Asim Aslam 581b2120a3 Verify zero-to-hero harness via workflow (#3102)
Co-authored-by: Codex <codex@openai.com>
2026-06-26 03:29:00 +01:00
Asim Aslam 871af7e6d3 Add pending filter for flow run history (#3100)
Co-authored-by: Codex <codex@openai.com>
2026-06-26 02:35:50 +01:00
Asim Aslam 9d39ed3292 Add OpenTelemetry spans for stepped flows (#3098)
Co-authored-by: Codex <codex@openai.com>
2026-06-26 01:10:11 +01:00
Asim Aslam d8f711431f agent: stop canceled tool execution (#3096)
Co-authored-by: Codex <codex@openai.com>
2026-06-26 00:07:26 +01:00
Asim Aslam 5d22cd4a5b Correlate agent trace spans (#3094)
Co-authored-by: Codex <codex@openai.com>
2026-06-25 23:09:39 +01:00
Asim Aslam f1f987cb8d provider conformance: print capability matrix (#3092)
Co-authored-by: Codex <codex@openai.com>
2026-06-25 22:18:34 +01:00
Asim Aslam 7b9c583dcf blog: "How Go Micro Builds Itself" — the autonomous Codex loop (#3090)
A post on how the framework is increasingly built by an autonomous loop of
two AI agents (Codex implementing scoped increments, Claude Code
orchestrating, the human setting direction): the dispatch→build→auto-merge
mechanism, the three altitudes (architect/increment/DevRel), the failure
modes we hit wiring it up, and the concrete increments it produces.


Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-25 21:59:00 +01:00
Asim Aslam b7f1ac6d6d Add flow run correlation to step contexts (#3089)
Co-authored-by: Codex <codex@openai.com>
2026-06-25 21:20:38 +01:00
Asim Aslam fb14ccbc17 Add deterministic AI capability rows (#3087)
Co-authored-by: Codex <codex@openai.com>
2026-06-25 20:21:00 +01:00
Asim Aslam 5f40cae7af ci: add DevRel + Architect overseer passes to the loop (#3085)
The hourly loop ships increments but nothing watches the whole. Add two
periodic high-altitude passes, same dispatch mechanism (fresh issue → @codex):

- devrel-review.yml (daily): audits README, website, docs, blog for coherence
  with the North Star, README crispness, and blog-worthy material. Safe
  alignment/crispness fixes auto-merge; brand/positioning copy and blog drafts
  are surfaced in a report for the human, never auto-merged.
- architecture-review.yml (every ~3 days): reviews the framework/harness against
  the thesis and files scoped follow-up issues that feed the increment loop. It
  does not make breaking/architectural changes itself.

Documented both in CONTINUOUS_IMPROVEMENT.md (Overseer passes).


Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-25 19:42:58 +01:00
Asim Aslam 496d5b7644 Show parent agent runs in CLI history (#3084)
Co-authored-by: Codex <codex@openai.com>
2026-06-25 19:28:32 +01:00
Asim Aslam 44e62f5e8b flow: honor canceled checkpoint contexts (#3082)
Co-authored-by: Codex <codex@openai.com>
2026-06-25 18:24:35 +01:00
Asim Aslam 18ae00dad0 Harden agent harness contracts (#3080)
Co-authored-by: Codex <codex@openai.com>
2026-06-25 17:36:36 +01:00
Asim Aslam 6f9adfd375 ai: expose unsupported streaming sentinel (#3078)
Co-authored-by: Codex <codex@openai.com>
2026-06-25 16:38:14 +01:00
Asim Aslam 8fc4f58a17 Add AI provider capability matrix (#3076)
Co-authored-by: Codex <codex@openai.com>
2026-06-25 15:26:49 +01:00
Asim Aslam 19ad28e04b Propagate A2A request cancellation (#3074)
Co-authored-by: Codex <codex@openai.com>
2026-06-25 14:32:06 +01:00
Asim Aslam 319ff1972b ci: require live provider conformance keys (#3072)
Co-authored-by: Codex <codex@openai.com>
2026-06-25 13:28:57 +01:00
Asim Aslam 03791759ef Add filtered agent run summaries (#3070)
Co-authored-by: Codex <codex@openai.com>
2026-06-25 12:35:39 +01:00
Asim Aslam 5e3cef7cd9 Add agent run summary status and duration (#3068)
Co-authored-by: Codex <codex@openai.com>
2026-06-25 10:50:49 +01:00
Asim Aslam 751530aaec website: refresh Developer Experience copy for the harness DX (#3066)
The section only mentioned micro run (services) and micro deploy. Update it
to the current lifecycle DX: micro new scaffolds a service or agent (every
endpoint an MCP tool), micro run starts everything with hot reload + gateway
+ console, and micro chat talks to agents and services. Drops micro deploy.


Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-25 10:33:34 +01:00
Asim Aslam 3a9f45750b docs + website: loop mechanics doc; landing "Features" + subtitle trim (#3065)
* ci: self-merge Codex PRs via native auto-merge; retire the sweep

With branch protection + "Allow auto-merge" now enabled on master, Codex
enables GitHub auto-merge on its own PR (gh pr merge --squash --auto) right
after opening it, so the PR lands the moment the required CI checks pass —
no polling sweep, and the green-CI gate is enforced by GitHub instead of by
gh pr checks in a cron. Removes auto-merge-codex.yml and updates the dispatch
and AGENTS.md accordingly.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

* docs: document the durable loop mechanics (stub→gh, branch, auto-merge)

Capture the hard-won wiring of the autonomous loop so it isn't re-derived:
fresh issue per increment, user-PAT dispatch (Codex ignores the bot), Codex
opening the PR via gh (make_pr is a no-op stub), unique codex/ branch + label,
and native auto-merge gated by branch protection with 0 approvals. Adds a
"do-not-break" list (don't re-add approvals, don't reuse one tracker issue,
don't use make_pr, don't re-implement during the summary→PR lag).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

* website: rename section to "Features"; trim subtitle

Rename the feature-grid heading from "The Runtime Around the Agent" to
"Features", and drop "once they leave the demo." from the subtitle.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-25 10:22:51 +01:00
Asim Aslam 2def581408 ci: self-merge Codex PRs via native auto-merge; retire the sweep (#3064)
With branch protection + "Allow auto-merge" now enabled on master, Codex
enables GitHub auto-merge on its own PR (gh pr merge --squash --auto) right
after opening it, so the PR lands the moment the required CI checks pass —
no polling sweep, and the green-CI gate is enforced by GitHub instead of by
gh pr checks in a cron. Removes auto-merge-codex.yml and updates the dispatch
and AGENTS.md accordingly.


Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-25 10:13:24 +01:00
Asim Aslam 95ee402c8b ci: pin Codex PRs to a unique codex/ branch + codex label (#3063)
Codex was pushing to a generic branch (e.g. "work"), which the auto-merge
sweep ignores (it only matches codex/* branches with the codex label) and
which collides across runs. The dispatch and AGENTS.md now instruct Codex to
create a unique codex/increment-<issue> branch and pass --label codex to
gh pr create, so every increment is isolated and actually swept.


Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-25 09:48:25 +01:00
Asim Aslam 8aeba56839 Harden provider conformance selection (#3061)
Co-authored-by: Codex <codex@openai.com>
2026-06-25 09:47:55 +01:00
Asim Aslam 42fdad439c docs: AGENTS.md — open PRs via gh, not the make_pr stub (#3062)
The initial AGENTS.md instructed Codex tasks to use the make_pr tool and
said a shell GitHub token "is not a substitute" — but make_pr in the Codex
sandbox is a no-op stub that only records metadata and never opens a PR, so
that guidance steers every run back into the broken path. Replace it with
the working flow: push the branch and open the PR with the gh CLI
(git push + gh pr create), which is what actually creates PRs now.


Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-25 09:32:50 +01:00
Asim Aslam b45c94e201 ci: instruct Codex to open the PR via gh, not the make_pr stub (#3059)
Codex's make_pr tool in the Cloud sandbox is a no-op stub — it records the
PR title/body and returns them "for downstream consumption" (the manual
"Create PR" click), but never pushes a branch or calls the GitHub API. That
is why "make_pr called, nothing happened": the tool literally cannot open a
PR. With the gh CLI now installed in the Codex setup and origin pointed at
the repo, the dispatch tells Codex to push and open the PR itself
(git push + gh pr create) instead of relying on make_pr.


Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-25 08:02:23 +01:00
Asim Aslam 23051459d8 docs: require Codex PR creation step (#3058) 2026-06-25 07:35:06 +01:00
Asim Aslam 4c7e6e96eb agent: correlate run timelines with traces (#3057) 2026-06-25 07:20:11 +01:00
Asim Aslam ef21ac6494 Add JSON output for agent run inspection (#3055) 2026-06-25 06:51:06 +01:00
Asim Aslam 53193fbbe7 agent: mark successful run timelines complete (#3054) 2026-06-25 06:50:51 +01:00
Asim Aslam 105cc9d2fb Add flow retry backoff (#3053) 2026-06-25 06:50:36 +01:00
Asim Aslam d369cf290c Improve agent run index summaries (#3049) 2026-06-25 01:31:08 +01:00
Asim Aslam 949542fa65 flow: add pending run resume helper (#3048) 2026-06-25 01:30:29 +01:00
Asim Aslam 1421ccbea6 Improve flow run inspection (#3047) 2026-06-25 01:30:01 +01:00
Asim Aslam 7a0ca65b68 Expose agent run IDs on responses (#3044) 2026-06-24 23:10:45 +01:00
Asim Aslam 28433f2db8 docs: align continuous improvement scheduler notes (#3043) 2026-06-24 23:09:49 +01:00
Asim Aslam cb61ccb9d7 Make flow checkpoint listing deterministic (#3040) 2026-06-24 21:51:18 +01:00
Asim Aslam fbb5fd46ae ci: open a fresh issue per increment so Codex opens a new PR each run (#3039)
Codex derives its PR branch name from the triggering issue's context, so
re-commenting on a single tracker issue (#3024) every hour collapsed every
increment onto one branch name. The first increment opened a PR; the rest
collided on the occupied branch and silently failed to open one — which is
why repeated runs produced "make_pr called, nothing happened."

Open a unique issue per run and dispatch Codex there, so each increment gets
its own branch and a clean PR. The dispatch asks Codex to "Closes #<issue>"
so each tracking issue auto-closes when its PR merges. The explicit
branch-name request (which Codex ignored in favor of the issue-derived name)
is dropped.


Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-24 21:46:44 +01:00
Asim Aslam ff6af5d46b Make agent run timelines deterministic (#3038) 2026-06-24 20:42:38 +01:00
Asim Aslam 89ae0a10eb website: h1 → "An Agent Harness for Go" (#3037)
Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-24 20:29:41 +01:00
Asim Aslam 666e1f765e ci: give each Codex dispatch a unique branch to avoid collisions (#3036)
* fix: harden flow step execution against nil Run and cancellation

A step with no Run function panicked the run; it now returns a clear
configuration error. The retry loop also kept retrying after the run's
context was canceled or its deadline passed — it now stops immediately
and surfaces the context error, preserving cancellation/deadline
semantics for durable workflow runs. Adds regression coverage for both.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

* ci: give each Codex dispatch a unique branch to avoid collisions

Codex derives its PR branch name from the dispatch text. The hourly loop
posted an identical generic prompt every run, so every increment resolved
to the same branch name — the previous increment's branch (until auto-
merged and deleted) blocked the next PR from opening. Include the run
number in the prompt and explicitly request a fresh
codex/improvement-<run_number> branch, so each increment is isolated.
auto-merge-codex.yml still matches (codex/* prefix) and deletes on merge.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-24 20:26:29 +01:00
Asim Aslam 5a0df7991e fix: harden flow step execution against nil Run and cancellation (#3034)
A step with no Run function panicked the run; it now returns a clear
configuration error. The retry loop also kept retrying after the run's
context was canceled or its deadline passed — it now stops immediately
and surfaces the context error, preserving cancellation/deadline
semantics for durable workflow runs. Adds regression coverage for both.


Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-24 18:49:32 +01:00
Asim Aslam 631c58cb75 ci: gate Codex dispatch on CODEX_TRIGGER_TOKEN secret (#3033)
goreleaser / goreleaser (push) Waiting to run
* thesis: position Go Micro as complementary to LangChain, not competing

Add a 'Where we fit' section: 'harness' has two layers — the intra-agent
harness (single-model runtime: prompts, tools, context, sandbox, the Ralph
loop) that LangChain/LangGraph/deepagents/Claude Code own and we do NOT
compete with, and the operational harness (the distributed substrate agents
operate inside: services-as-tools, discovery, durable runs, observability,
interop, the services->agents->workflows lifecycle) which is our focus. They
stack and interoperate via MCP/A2A; we make those agents better neighbours,
not obsolete.

* ci: gate Codex dispatch on CODEX_TRIGGER_TOKEN secret

Codex ignores @codex comments authored by the github-actions bot, so the
hourly dispatch was producing no PRs while still posting to the tracker
issue. Gate the comment step on the presence of CODEX_TRIGGER_TOKEN: the
workflow now no-ops until a PAT for a Codex-followed account is set, then
activates automatically with no further change.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-24 17:39:44 +01:00
Asim Aslam 57e83ca9a0 thesis: position Go Micro as complementary to LangChain, not competing (#3032)
Add a 'Where we fit' section: 'harness' has two layers — the intra-agent
harness (single-model runtime: prompts, tools, context, sandbox, the Ralph
loop) that LangChain/LangGraph/deepagents/Claude Code own and we do NOT
compete with, and the operational harness (the distributed substrate agents
operate inside: services-as-tools, discovery, durable runs, observability,
interop, the services->agents->workflows lifecycle) which is our focus. They
stack and interoperate via MCP/A2A; we make those agents better neighbours,
not obsolete.

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-24 15:54:56 +01:00
Asim Aslam 8d59779465 website: fix mobile horizontal overflow on the landing page (#3031)
Grid items defaulted to min-width:auto, so the wide <pre> blocks (install
command, the 'micro run' sample) forced their row past the viewport —
clipped by overflow-x:hidden, so no scroll but not fitting either. Let
grid items shrink (.two-col > * { min-width:0 }) and wrap the code blocks
on mobile (white-space:pre-wrap; overflow-wrap:anywhere) so every section
fits the screen with no overflow or scroll.

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-24 15:48:35 +01:00
Asim Aslam 3d0c5237f0 docs: burger (☰) sidebar toggle on the left on mobile (#3030)
Replace the docs header 'Menu' button with a ☰ burger icon and move it to the
left next to the wordmark (where the logo used to be), grouped in a .nav-left
container. Keeps id=menuToggle so the existing sidebar-toggle JS still works;
desktop is unchanged (toggle hidden).

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-24 15:31:52 +01:00
Asim Aslam cf1f42d15b website: text-only 'Go Micro' brand, drop the nav logo (#3029)
Remove the logo image from the nav-brand in the marketing nav include and the
docs and blog layouts; the brand is now just the 'Go Micro' wordmark.

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-24 15:27:47 +01:00
Asim Aslam 728ea5eae7 loop: add the thesis / North Star and make the loop align to it (#3028)
Add internal/docs/THESIS.md — the vision the autonomous loop steers by: a
holistic agent harness AND service framework encapsulating the lifecycle of
services -> agents -> workflows (workloads come after agents; the value is in
composing it into systems that do real work, on schedules and in loops).

Wire it in as the alignment criterion: the continuous-improvement charter and
the Codex dispatch prompt now require every increment to advance the North Star,
so improvements compound toward the thesis instead of drifting locally.

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-24 15:23:01 +01:00
Asim Aslam 5e9accfd45 Add agent OpenTelemetry run observability (#3027) 2026-06-24 14:57:25 +01:00
Asim Aslam 0adb4f0aac loop: hourly Codex dispatch + auto-merge green Codex PRs (#3026)
- continuous-improvement: cadence 12h -> hourly.
- add auto-merge-codex workflow: every 15 min, merge open PRs that are
  codex-labelled AND from a codex/* branch once all checks are green
  (gh pr checks). CI (build/test/lint/harnesses) is the only gate — no
  human involvement. Scoped tightly so nothing else auto-merges.

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-24 14:26:31 +01:00
Asim Aslam ee44926191 loop: drive the scheduled backbone via Codex, not an Anthropic key (#3025)
A Claude Max subscription exposes no API key for CI, and Atlas Cloud models
can't run a coding agent — so the durable scheduler triggers Codex instead:
on a cadence it posts an @codex instruction on the tracker issue (#3024) to
run one improvement increment. Prefers a CODEX_TRIGGER_TOKEN PAT if set
(in case Codex ignores the Actions bot), else the default token.

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-24 14:15:41 +01:00
Asim Aslam 09cf00b5ec docs: mark harness Resilience as shipped (#3023)
* loop: establish the continuous-improvement charter + scheduled backbone

Define the autonomous improvement loop (internal/docs/CONTINUOUS_IMPROVEMENT.md):
full autonomy with correctness (build/test/lint) as the only gate, work sourced
from roadmap + issues + an improvement radar + dogfooding, Claude Code driving
and Codex executing scoped tasks, with brand/positioning and breaking API kept
with the human.

Add a durable scheduled GitHub Action (.github/workflows/continuous-improvement.yml)
as the session-independent backbone — a safe no-op until an ANTHROPIC_API_KEY
secret is added.

* docs: mark harness Resilience as shipped

Resilience (per-call timeout + context propagation + opt-in retry/backoff)
landed in #3017/#3021; update the agent-harness status table from
'In progress' to 'Shipped'.

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-24 13:58:02 +01:00
Asim Aslam da5fa1f27c loop: establish the continuous-improvement charter + scheduled backbone (#3022)
Define the autonomous improvement loop (internal/docs/CONTINUOUS_IMPROVEMENT.md):
full autonomy with correctness (build/test/lint) as the only gate, work sourced
from roadmap + issues + an improvement radar + dogfooding, Claude Code driving
and Codex executing scoped tasks, with brand/positioning and breaking API kept
with the human.

Add a durable scheduled GitHub Action (.github/workflows/continuous-improvement.yml)
as the session-independent backbone — a safe no-op until an ANTHROPIC_API_KEY
secret is added.

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-24 13:56:38 +01:00
Asim Aslam a8ea60120e agent: make model retries opt-in and harden retry backoff (#3021)
Follow-up to #3017. A Generate runs the whole tool-execution turn, so
auto-retrying it re-runs already-executed (possibly side-effecting) tool
calls. Default ModelMaxAttempts 3 -> 1: retries are now opt-in via
ModelRetry. The timeout stays as a safety net.

Also harden ai.GenerateWithRetry: always back off between retries
(exponential, capped at 30s, default 200ms if unset) so an opt-in retry
can't busy-loop the provider even with Backoff=0.

Verified: go build, go test -race ./agent/... ./ai/, golangci-lint.

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-24 12:42:15 +01:00
Asim Aslam d7050e9cc2 website: size hero image to 600px (#3020)
Co-authored-by: Claude <noreply@anthropic.com>
2026-06-24 12:39:22 +01:00
Asim Aslam 536806119e website: tighten hero — drop 'in Go', simpler tagline, image in-hero at 800px (#3019)
- h1: 'An Agent Harness and Service Framework' (drop 'in Go')
- tagline: 'Build agents, services, and workflows on one runtime'
- move the hero image into the hero block (between tagline and the install
  line), capped at 800px to fit the hero column, and remove the separate
  full-width image section

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-24 12:33:58 +01:00
Asim Aslam ab2c092693 Add agent model retry and timeout resilience (#3017) 2026-06-24 12:30:58 +01:00
Asim Aslam 7144cddc00 website: new hero image + reframe landing as harness AND service framework (#3018)
- Regenerate the hero image (text-free, via the framework's own Atlas Cloud
  image model) — an agent orchestrating service nodes. The old one had baked-in
  'AI native microservices framework' text that contradicts the positioning;
  text-free so copy changes can't invalidate it again.
- h1 -> 'An Agent Harness and Service Framework in Go' (both, not harness-only).
- Tagline reframed around agents, services, and flows on one runtime.
- Drop the 'moved from a service framework to an agent harness' line — it's
  additive (both in one), not a pivot away from services.

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-24 12:27:09 +01:00
Asim Aslam 9f28cc4c86 docs: bake cross-agent coordination rules into CLAUDE.md and CODEX.md (#3016)
Add matching 'Coordination' sections so Claude Code and Codex self-coordinate:
lane/branch ownership (claude/* vs codex/*, never share a branch), base PRs
on master (don't stack on an in-flight branch — the #3007 orphan lesson),
one concern per PR, cross-review before merge, the @codex dispatch
conventions (review reserved, serial, fix-in-place), and CI as the gate.

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-24 12:13:21 +01:00
Asim Aslam 8a19dc2d7c docs/blog: anchor the agent-harness positioning (#3015)
- Add the canonical concept doc 'The Agent Harness' (docs/guides/agent-harness.md)
  + nav entry: what the harness is, each piece mapped to a feature, honest
  about shipped vs in-progress.
- Add blog post /blog/30 'Go Micro is an Agent Harness' (the public articulation;
  precise about what ships today vs the Now/Next roadmap).
- Align the ROADMAP.md opening line to the agent-harness framing.


Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-24 11:59:42 +01:00
Asim Aslam daacd4830f harness/new: make conformance timeout honest and contract test cheaper (#3008)
Follow-up to #3006:

- provider-conformance: build each harness to a temp binary and run that
  instead of 'go run'. 'go run' launches the harness as a child it doesn't
  kill on context cancellation, so a timed-out harness (which starts local
  services) could be orphaned and outlive the run. Running the built binary
  makes the per-run timeout actually terminate the work.
- contract test: skip under -short, and use 'go build ./...' instead of
  'go test ./...' (the contract is that the generated service builds). This
  keeps the default unit-test suite from shelling out to the toolchain and
  the network on every run.


Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-24 11:48:40 +01:00
Asim Aslam 844ab4a14b Add provider-conformance harness, contract test, and reframe docs to 'agent harness' (#3006)
* docs: reposition go micro as agent harness

* ci: rename universe workflow to harness
2026-06-24 11:37:43 +01:00
Asim Aslam 156b051191 docs: fix service quickstart snippets (#3005) 2026-06-24 08:21:38 +01:00
Asim Aslam 21a6746d86 docs: add codex maintainer playbook (#3004) 2026-06-24 07:58:48 +01:00
Asim Aslam 2c04f61331 blog: announce OpenAI Codex for Open Source grant (/blog/29) (#3003)
Add a blog post for the OpenAI Codex for Open Source grant, list it on
the blog index, and repoint the OpenAI sponsor logo (README + landing) to
the post — matching how the Anthropic (/blog/3) and Atlas Cloud (/blog/8)
sponsor logos link to their posts.

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-23 18:35:51 +01:00
Asim Aslam 634fc9bced sponsors: add OpenAI (Codex for Open Source) (#3002)
Go Micro received an OpenAI Codex for Open Source grant. Add the OpenAI
logo to the README and landing-page sponsors, alongside Anthropic and
Atlas Cloud.

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-23 18:21:35 +01:00
Asim Aslam a503628ef1 flow: add Loop — run a step until done, with a guaranteed ceiling (#3001)
Adds the agentic 'loop' to flows: flow.Loop(body, opts...) is a StepFunc
that runs a body step repeatedly, carrying State across passes, until a
stop condition fires or a hard iteration cap is reached.

- Stop modes: flow.Until (code-defined predicate) and flow.UntilLLM (the
  model judges the goal met after each pass — the supervised 'Ralph'
  loop). Either firing stops the loop.
- flow.LoopMax is the guardrail: the body never runs more than n times, so
  the loop always terminates and can't run up an unbounded bill. Hitting
  the cap returns the latest state rather than erroring.
- flow.OnIteration reports per-pass progress.
- Composes as a normal flow step (checkpointed by the step engine).
- Exposed at the top level as micro.FlowLoop / FlowUntil / FlowUntilLLM /
  FlowLoopMax / FlowOnIteration, symmetric with the other Flow* helpers.

Includes tests, an offline runnable example (examples/flow-loop), an
'Agent Loops' guide, and a CHANGELOG entry.


Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-23 12:39:17 +01:00
Asim Aslam 3f40028a7f website: deduplicate header/footer via Jekyll includes (#3000)
Extract the nav and footer link lists into _includes/nav-links.html and
_includes/footer-links.html, and the full marketing nav/footer into
_includes/marketing-nav.html and _includes/marketing-footer.html.

- index.html and support.html now pull their nav/footer from the shared
  marketing includes (and gain Liquid front matter so includes resolve).
- The docs and blog layouts pull the same link lists, so a nav/footer
  link lives in exactly one place site-wide. This also adds the missing
  Support link to the blog nav and fixes the blog footer's Support link
  (it still pointed at the question template).
- Active nav state is driven by a per-page nav_active flag.

Verified with a local jekyll build: landing, support, docs, and blog
pages all render the shared nav/footer correctly.

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-23 05:45:09 +01:00
Asim Aslam b9665ad196 website: add Support to top nav (landing + docs layout) (#2999)
* website: add Support to top nav (landing + docs layout)

Link /docs/support.html from the nav bar on the landing page and the
shared docs layout, and point the docs-layout footer Support link there
too (was the question issue template).

* website: add a dedicated marketing /support page

New top-level /support.html styled like the landing site (hero, tier
cards, community links, CTAs) — separate from the docs reference at
/docs/support.html. Repoint the site nav, footer, landing 'Commercial
support' button, and the FUNDING button to it.

* website: serve the support page at a clean /support URL

Add 'permalink: /support' to support.html (same mechanism the blog uses)
and point all nav/footer/CTA/FUNDING links at /support instead of
/support.html.

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-22 22:42:10 +01:00
Asim Aslam 053103fb7f website: trim landing tagline and use 'workflows' (#2998)
Drop the 'Every service is an MCP tool; every agent speaks A2A' sentence
and use 'workflows' (clearer than 'flows') in the one-liner.

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-22 19:54:35 +01:00
Asim Aslam 0ba2253357 website: trim landing tagline to the one-liner (#2997)
Drop the 'Every service is an MCP tool; every agent speaks A2A' sentence.

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-22 19:52:05 +01:00
Asim Aslam 2339155ff2 Enforce blocking golangci-lint in CI and clear lint backlog (#2996)
goreleaser / goreleaser (push) Waiting to run
* lint: clear the golangci-lint backlog and enforce a blocking lint in CI

Fixes #2988. Brings 'golangci-lint run ./...' to zero issues (was ~373):

- errcheck: explicitly ignore fire-and-forget calls with '_ =' (and a small
  errcheck.exclude-functions list for response writes — json Encoder.Encode,
  http ResponseWriter.Write, fmt.Fprint*); genuine cases handled.
- unused: remove dead code (unexported decls and dead test helpers) and the
  imports they orphaned.
- staticcheck: ST1005 error strings, ST1016 receiver names, S1000/S1017/S1019/
  S1023 simplifications, SA4004/SA4006/SA4010 dead code, SA1021 net.IP.Equal,
  SA6002 (store *[]byte in sync.Pool).
- govet: fix a context leak (lostcancel) in internal/util/mdns and move
  t.Fatal/Fatalf out of goroutines (testinggoroutine) in tests.
- ineffassign, unconvert: mechanical fixes.

CI: the Lint workflow now runs a blocking full-tree 'golangci-lint run' on
pushes and PRs (dropped only-new-issues now that the tree is clean).

Verified: go build, go vet, test compilation, and unit tests for the
behaviourally-touched packages all pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

* website: emit go-source meta for /vN paths

pkg.go.dev uses go-source to link to the right files and lines. The /vN
go-get response now returns go-source alongside go-import. Does not affect
go install resolution.

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-22 19:48:09 +01:00
Asim Aslam 3e885308a0 lint: clear the golangci-lint backlog and enforce a blocking lint in CI (#2995)
Fixes #2988. Brings 'golangci-lint run ./...' to zero issues (was ~373):

- errcheck: explicitly ignore fire-and-forget calls with '_ =' (and a small
  errcheck.exclude-functions list for response writes — json Encoder.Encode,
  http ResponseWriter.Write, fmt.Fprint*); genuine cases handled.
- unused: remove dead code (unexported decls and dead test helpers) and the
  imports they orphaned.
- staticcheck: ST1005 error strings, ST1016 receiver names, S1000/S1017/S1019/
  S1023 simplifications, SA4004/SA4006/SA4010 dead code, SA1021 net.IP.Equal,
  SA6002 (store *[]byte in sync.Pool).
- govet: fix a context leak (lostcancel) in internal/util/mdns and move
  t.Fatal/Fatalf out of goroutines (testinggoroutine) in tests.
- ineffassign, unconvert: mechanical fixes.

CI: the Lint workflow now runs a blocking full-tree 'golangci-lint run' on
pushes and PRs (dropped only-new-issues now that the tree is clean).

Verified: go build, go vet, test compilation, and unit tests for the
behaviourally-touched packages all pass.


Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-22 18:51:30 +01:00
Asim Aslam 4311b73361 Enhance ADK vs Go Micro comparison and apply lint fixes (#2994)
* docs: compare Go Micro with Google ADK in the comparison guide

Adds a 'vs Agent Frameworks (Google ADK)' section: ADK builds an agent,
Go Micro builds the distributed system the agent lives in (agents are
services in the mesh). Covers the category difference, a feature table,
when to choose each, and MCP/A2A interoperability.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

* docs: replace ADK comparison slogan with concrete explanation

State plainly what each tool provides (ADK builds an agent process; Go Micro
builds the surrounding service mesh) instead of marketing phrasing.

* lint: apply golangci-lint autofixes; exclude ST1003 and demo errcheck

Mechanical, behaviour-preserving fixes applied by 'golangci-lint run --fix':
gofmt, misspell (US spelling), usestdlibvars (http.Method*/Status*), unconvert,
and the auto-fixable staticcheck simplifications (QF*, S1017/S1019/S1023/S1039).

Config: exclude ST1003 (remaining offenders are exported API renames, e.g.
web.Id, which would break compatibility) and skip errcheck for examples/ and
internal/harness/ (demo code where fire-and-forget is intentional).

Build and test compilation verified.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

* lint: WIP cleanup checkpoint (errcheck config + partial fixes)

Checkpoint of an in-progress golangci-lint cleanup (background pass). Builds
cleanly; lint is not yet zero. Follow-up commit will complete the cleanup and
switch CI to a blocking full-tree lint.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-22 17:21:47 +01:00
Asim Aslam c3542127dd Enhance comparison guide for Go Micro and Google ADK (#2993)
* docs: compare Go Micro with Google ADK in the comparison guide

Adds a 'vs Agent Frameworks (Google ADK)' section: ADK builds an agent,
Go Micro builds the distributed system the agent lives in (agents are
services in the mesh). Covers the category difference, a feature table,
when to choose each, and MCP/A2A interoperability.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

* docs: replace ADK comparison slogan with concrete explanation

State plainly what each tool provides (ADK builds an agent process; Go Micro
builds the surrounding service mesh) instead of marketing phrasing.

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-22 17:07:45 +01:00
Asim Aslam 06659032a9 docs: install the CLI with @v6 instead of @latest (#2991)
Plain 'go install go-micro.dev/v6/cmd/micro@latest' fails on the public
module proxy with a version-constraints conflict: the proxy has cached the
sub-paths go-micro.dev/v6/cmd and .../cmd/micro as standalone v0/v1 modules
(from old github.com/micro/go-micro tags, surfaced during an earlier vanity
meta bug), so @latest resolves to v1.18.0 with a mismatched module path.

A version-prefix query (@v6) sidesteps it: those cached sub-path modules
have no v6.x.x versions, so Go falls back to the go-micro.dev/v6 root
module and builds correctly. Verified against proxy.golang.org.


Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-22 16:39:04 +01:00
Asim Aslam 8cad95cc29 website: add commercial support to the landing page (#2990)
The Sponsors section now also points production users to commercial
support & consulting, and the footer Support link routes to the support
page (community + commercial) instead of the question issue template.


Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-22 15:50:23 +01:00
Asim Aslam 2cbd6264d7 support: advertise commercial support, consulting, and sponsorship (#2989)
* support: advertise commercial support, consulting, and sponsorship

Adds a clear path to fund the project and pay for help, surfaced where
people look:
- SUPPORT.md + website /docs/support.html with a tier ladder (community,
  sponsor, support retainer, consulting)
- Commercial Support / Consulting issue template (the GitHub inbound funnel)
  and an issue-chooser config linking Sponsors and docs
- FUNDING.yml custom link to the support page; README section + nav entry

Community support stays free via issues; paid support and consulting are
scoped per engagement.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

* ci: migrate golangci-lint to v2 config and enforce in CI (#2988)

- Rewrite .golangci.yaml for the v2 schema: start from the standard linter
  set (errcheck, govet, ineffassign, staticcheck, unused) plus bodyclose,
  misspell, unconvert, usestdlibvars. Sensible exclusions: generated code,
  built-in presets, looser tests, SA1019 deprecations (coordinated migration
  is separate), and the ported protoc-gen-micro generator for unused.
- Add a Lint workflow running golangci/golangci-lint-action with
  only-new-issues, so linting is enforced on new/changed code without a
  flag-day cleanup of the existing backlog.

The pre-existing backlog (errcheck/unused/naming and a few real bugs the
linter surfaces) is left for a dedicated follow-up so it can be reviewed on
its own rather than buried in this wiring change.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-22 14:39:28 +01:00
Asim Aslam aa7cd6dc3b Enhance support agent example and fix protoless service scaffolding (#2986)
goreleaser / goreleaser (push) Waiting to run
* examples: support desk agent + blog walkthrough

A real-world, runnable example (examples/support): customers/tickets/notify
services become the agent's tools, a flow turns a ticket.created event into
the agent's work, and an approval gate guards the one action that touches a
customer. Runs with no API key (mock model) or against a live provider.

Adds blog/28 'Building a Support Agent in Go' and indexes both.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

* fix(new): protoless services by default; fix @latest install (#2985)

micro new now scaffolds a reflection-based service by default — plain Go
types registered via service.Handle, no .proto, no Makefile proto target.
The generated project builds and runs with 'go run .' and zero external
tooling. Protocol Buffers move behind --proto (the crud/pubsub/api
templates imply it). When the proto workflow is used and protoc /
protoc-gen-go / protoc-gen-micro are missing, print exact install
instructions instead of failing with a cryptic plugin error.

Also fixes the 'go install go-micro.dev/v6/cmd/micro@latest' version
constraint conflict: the vanity go-import meta still advertised /v5, so Go
fell back to the bare module and resolved an ancient v1.x tag. Advertise
/v6 (keeping /v5 for existing users) and add a version-pin fallback note to
the install docs.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

* fix(new,install): pin generated go.mod to current go-micro; lead install with prebuilt binary (#2985)

- micro new now requires the exact go-micro version the CLI was built from
  (via build info), falling back to 'latest' for dev builds. An explicit
  require is also more robust than a bare import: 'go mod tidy' reliably
  resolves it, where a requireless go.mod could fail vanity discovery.
- Make the precompiled binary (curl install.sh) the recommended install in
  the docs; demote 'go install' to a from-source option with the version-pin
  fallback note.
- Sync the stale internal/scripts/install.sh to the working website script
  (it expected an old micro-OS-ARCH asset name; releases ship
  micro_OS_ARCH.tar.gz).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

* website: add corrected nginx vanity-import config (#2985)

The live go-micro.dev handler echoed the full request path into the
go-import prefix ($host$1), so go install go-micro.dev/v6/cmd/micro@latest
got prefix go-micro.dev/v6/cmd/micro — a package, not the module root — and
Go fell back to the ancient v1.x tags (version constraints conflict).

Add a dedicated /vN location that emits the module root (go-micro.dev/vN)
for any sub-path, and make the catch-all advertise the current module roots
instead of echoing arbitrary paths.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-22 10:22:25 +01:00
Asim Aslam 456ff18176 examples: support desk agent + blog walkthrough (#2984)
A real-world, runnable example (examples/support): customers/tickets/notify
services become the agent's tools, a flow turns a ticket.created event into
the agent's work, and an approval gate guards the one action that touches a
customer. Runs with no API key (mock model) or against a live provider.

Adds blog/28 'Building a Support Agent in Go' and indexes both.


Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-20 10:23:24 +01:00
Asim Aslam cdc6ee9aa1 examples: support desk agent + blog walkthrough (#2983)
A real-world, runnable example (examples/support): customers/tickets/notify
services become the agent's tools, a flow turns a ticket.created event into
the agent's work, and an approval gate guards the one action that touches a
customer. Runs with no API key (mock model) or against a live provider.

Adds blog/28 'Building a Support Agent in Go' and indexes both.


Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-19 21:55:50 +01:00
Asim Aslam e5bf72abd8 docs: consolidate to a single agentic/DX roadmap (#2982)s
Replace the drifted, contradictory roadmap set (two public roadmaps, the
AI-native-era business-model doc, stale status snapshots) with one
canonical roadmap focused on agentic development and developer experience.

- internal/website/docs/roadmap.md — the single source of truth: where we
  are (v6), the principles (build into what people run; CLI-first; the
  0->1 and 0->hero getting-started contract; interaction; battle-tested),
  and prioritized work (cross-provider conformance + resilience now;
  durable agent loop, streaming, observability next).
- ROADMAP.md — concise, points to the canonical.
- roadmap-2026 + the internal ROADMAP_2026/STATUS docs — collapsed to
  pointers (keeps blog/CLAUDE links alive, removes drift).
- CLAUDE.md — references the single roadmap + CHANGELOG for status.

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-19 20:11:02 +01:00
Asim Aslam 232126476a Revise acknowledgment for sponsorship and Discord invite
Updated the acknowledgment section to reflect sponsorship and invite discussion.
2026-06-19 19:27:13 +01:00
Asim Aslam 358b2ffd27 Update blog post to refine 'Flows' definition
Clarified the definition of 'Flows' to include agents and corrected minor wording issues.
2026-06-19 17:53:44 +01:00
Asim Aslam 45346337e2 Update V3 description for clarity and accuracy
Clarified the description of V3 and its market reception.
2026-06-19 17:50:21 +01:00
Asim Aslam 4b8b4d7bab Fix typo in blog post about Go Micro development 2026-06-19 17:35:57 +01:00
Asim Aslam 97f932a2e7 Revise blog post on Go Micro's revival and evolution
Updated the blog post to reflect the journey of Go Micro, including its revival and the integration of agents into the framework. Enhanced clarity and structure throughout the text.
2026-06-19 17:23:15 +01:00
Asim Aslam ca87efef2f feat(agent): expose run metadata + structured guardrail reasons to tool wrappers (#2981)
goreleaser / goreleaser (push) Waiting to run
Closes the remaining ask in #2980 without adding a parallel callback API.
ToolResult.Refused tags a guardrail block with a reason (ai.RefusedLoop /
RefusedMaxSteps / RefusedApproval) so a wrapper can switch on it instead of
parsing the message. ai.RunInfo (RunID, ParentID, Agent) rides on the
context passed to the tool handler, giving wrappers run correlation and
delegation lineage. Before/after/retry/failure were already covered by
AgentWrapTool; this adds the metadata. Docs + tests included.

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-19 08:09:22 +01:00
Asim Aslam d54cfab1bd blog: Bringing an Open Source Project Back from the Dead (#27) (#2979)
A first-person journey of Go Micro from January 2015 through the
VC/company era, the platform pivot, the quiet years, and the revival via
the Claude Code grant — into v6 and the services/agents/flows model.

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-18 19:41:08 +01:00
Asim Aslam 46c56ef7df test(natsjs): fix flaky TempDir cleanup race + vet-unsafe Fatalf (#2978)
TestSingleEvent intermittently failed on cleanup with 'directory not
empty': the embedded NATS JetStream server was still releasing files when
t.TempDir's RemoveAll ran at test end. Own the store dir (os.MkdirTemp)
and remove it only after server.Shutdown()+WaitForShutdown(). Also report
setup errors with Errorf instead of Fatalf/require, which are unsafe from
the non-test goroutine (go vet).

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-18 12:06:19 +01:00
Asim Aslam c7657f73f4 Refactor agent plan storage, update docs, and release v6 (#2977)
goreleaser / goreleaser (push) Waiting to run
* test(harness): read agent plan from the scoped store

The store-scoping change moved an agent's plan from the default table
key agent/{name}/plan to its own table (database "agent", table {name},
key "plan"). The plan-delegate harness tests still read the old key and
failed with 'not found'; read through store.Scope(mem, "agent", name)
like the agent does.

* docs: orient agents-first across README, landing, and docs overview

Lead with agents (then services and flows), surface MCP + A2A as the
interop story, and frame agents as services. Landing hero and feature
grid reordered agents-first with an A2A gateway card.

* v6: module path go-micro.dev/v6, TLS secure by default, NewService

Cut v6. Three breaking changes, bundled so the major bump is paid once:

- Module path go-micro.dev/v5 -> go-micro.dev/v6 across all imports + go.mod.
- TLS verification on by default (was off). MICRO_TLS_SECURE removed;
  MICRO_TLS_INSECURE=true opts out for self-signed/dev.
- micro.NewService(name, opts...) is the canonical service constructor,
  symmetric with NewAgent/NewFlow; micro.New kept as a deprecated alias;
  the old name-less NewService(opts...) removed. Generators emit NewService.

Also ports the JWT auth token provider in-module (go-micro.dev/v6/auth/jwt/token
on golang-jwt/jwt/v5), dropping the v5-pinned github.com/micro/plugins/v5/auth/jwt
and the deprecated dgrijalva/jwt-go.

Docs/README/landing updated to v6 and @latest; v5->v6 migration guide added;
CHANGELOG cut as [6.0.0]. Blog posts left at their historical versions.

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-18 11:55:35 +01:00
Asim Aslam b9586f920b test(harness): read agent plan from the scoped store (#2976)
The store-scoping change moved an agent's plan from the default table
key agent/{name}/plan to its own table (database "agent", table {name},
key "plan"). The plan-delegate harness tests still read the old key and
failed with 'not found'; read through store.Scope(mem, "agent", name)
like the agent does.

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-18 11:04:14 +01:00
Asim Aslam f42c9d1d69 feat(a2a): agents can serve A2A directly, no gateway required (#2975)
Refactor the A2A handler into a reusable dispatcher + Invoke seam and
expose NewAgentHandler(card, invoke) + Card(). An agent now serves its
own A2A endpoint with AgentA2A(addr) / WithA2A — handling tasks
in-process (no RPC hop, no separate gateway). The gateway and embedded
agent share the same handler; the only difference is RPC vs in-process
invocation. Docs, README, and changelog cover both deployment modes.

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-18 10:57:38 +01:00
Asim Aslam 307b94aab7 Implement A2A protocol gateway and update documentation (#2974)
goreleaser / goreleaser (push) Waiting to run
* feat(a2a): Agent2Agent protocol gateway

Add gateway/a2a — exposes registered agents over the open A2A protocol so
agents on other frameworks can discover and call them. Agent Cards are
generated from registry metadata (the same way the MCP gateway derives
tools from service endpoints); incoming A2A tasks translate to the
agent's existing Agent.Chat RPC, so there's no per-agent code.

v1 is the synchronous JSON-RPC binding: message/send returns a completed
Task, tasks/get retrieves it, and Agent Cards are served for discovery;
streaming and push notifications are advertised as unsupported. Run with
'micro a2a serve' (cmd/micro/a2a). Tests cover card generation,
message/send, tasks/get, listing, and unknown-method errors.

* docs: A2A guide, README contents + A2A section, universe A2A check

- Add a Contents table of contents at the top of the README and an A2A
  subsection under Building Agents.
- Add the Agent2Agent (A2A) guide and register it in the docs nav.
- Exercise the A2A gateway in the universe harness: the concierge agent
  is reached over A2A (message/send -> Agent.Chat -> completed task).

* feat(a2a): outbound client — call external A2A agents

Add a2a.Client (Send/Card) so a Go Micro agent or flow can call an agent
on any framework by URL — the outbound counterpart to the gateway. Wired
in two places: flow.A2A(url) as a workflow step (the cross-framework
Dispatch), and agent delegate to an http(s) URL routes over A2A. The
universe harness now drives the gateway through the client, exercising
both directions. Tests cover client send/card and the round trip.

* docs: A2A both-directions — guide, README, changelog, blog #26

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-17 20:33:20 +01:00
Asim Aslam 7ee32e8721 Update changelog and enhance retrospective blog on agentic features (#2973)
* docs: changelog catch-up + retrospective blog (agentic development)

Add the headline agentic features that shipped this quarter but were
never logged (agents, plan/delegate, guardrails, workflows, x402) to the
changelog, and add blog #25 — a three-month progress reflection on Go
Micro becoming a framework for agentic development.

* docs: tighten retrospective post — cut slogans, triads, and filler

* docs: tighten retrospective intro, bridge, and conclusion for a single through-line

* docs: frame Go Micro as how you build a distributed system, not run one

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-17 12:29:25 +01:00
Asim Aslam 9fdcc24cce Implement durable execution and scoped state management for flows (#2972)
* docs: design note for flow steps + Checkpoint durable execution

* docs: fold in durable-execution decisions (State struct, single Step, run retention, retry)

* docs: rename State.Payload to State.Data

* feat(flow): ordered steps + Checkpoint durable execution

A flow can now be an ordered list of steps (a task with stages) instead
of a single LLM turn. State carries typed Data plus a Stage marker; each
step is checkpointed before and after via a pluggable Checkpoint
(store-backed by default), so a run survives a crash and resumes where it
stopped without re-running completed steps. Flow-level Retry with a
per-step override; runs retained for audit unless DeleteOnSuccess.

Step actions: Call (RPC), LLM (augmented turn), Dispatch (to an agent),
or any StepFunc. Single-step and agent-dispatch flows are unchanged.

* feat(flow): top-level re-exports + durable flow example

Expose the step/checkpoint API from the micro package (FlowSteps,
FlowStep, FlowState, FlowRetry, FlowWithCheckpoint, FlowCall/LLM/Dispatch,
Checkpoint, StoreCheckpoint) and add a runnable, key-free example
demonstrating crash + resume.

* docs: document durable flow steps (guide, README, CLI help)

* docs: blog post + changelog for durable workflows

* fix(flow): scope checkpoint keys by flow name (flow/{name}/runs/{id})

Run keys were flow/runs/{id} — a single global keyspace shared by every
flow on the default store. Namespace them by flow name so each flow's
state is kept apart. StoreCheckpoint now takes a scope argument (the flow
passes its name by default).

* feat(store): Scope handle; scope agent and flow state by name

Add store.Scope(s, database, table) — a store handle that confines every
operation to a database/table without mutating the shared store, so
co-located components don't clobber each other's table (the failure mode
of the global Init(Table(...)) approach).

Use it to keep each agent's memory and plan in its own table
(agent/{name}) and each flow's runs in its own (flow/{name}), instead of
one global table partitioned only by key prefix. Services already scope
by service name.

* feat: consistent state model — service store scoping, flow registry, list/history CLI

- service: scope store via store.Scope (database service / table name),
  retiring the Init(store.Table(name)) global-mutation hack; bridge the
  default store so handlers using store.DefaultStore stay isolated.
- flow: register in the registry as type=flow while running (with trigger
  and step count), deregister on Stop. Live discovery, like agents.
- cli: micro flow list (registry), micro flow runs <name> (durable store),
  micro agent history <name> (durable store). list = running, runs/history
  = durable, mirroring the service model.

* test: mini-universe end-to-end harness + scheduled GitHub Action

internal/harness/universe boots a small but real go-micro world — four
services, a durable checkout flow that crashes at payment and resumes,
and a guardrailed agent with a tool wrapper reached over RPC — drives the
scenario, asserts the end state (10 checks), and shuts down. Everything
is real except the LLM (mocked), so it's deterministic and needs no key;
-provider anthropic runs it live. Exits non-zero on failure, so it's an
end-to-end test, not just a demo.

Adds .github/workflows/universe.yml (push/PR/daily/dispatch) running the
universe + existing harnesses on the mock provider, plus an opt-in job
that runs live when ANTHROPIC_API_KEY is set. 'make harness' runs them
locally.

* ci: run the live universe job against AtlasCloud (ATLASCLOUD_API_KEY)

* ci: run the live universe job only on schedule or manual dispatch

The deterministic mock job still runs on push/PR/daily; the live
(AtlasCloud) job runs daily and on manual workflow_dispatch only, so
changes don't burn API credits on every PR but can still be checked
against a real model on demand.

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-17 12:02:47 +01:00
Asim Aslam 6b4ce55a7c Implement tool-execution wrappers and update documentation (#2971)
* feat(agent): tool-execution wrappers via WrapTool

Restructure ai.ToolHandler to the structured, ctx-carrying shape that
mirrors a go-micro RPC handler:

    func(ctx context.Context, call ai.ToolCall) ai.ToolResult

This reuses the existing ToolCall (with its correlation ID) and
ToolResult types instead of the flat (name, input)->(any, string)
signature, and adds ToolCall.Scan for typed argument access.

Add ai.ToolWrapper and the agent option WrapTool / micro.AgentWrapTool —
the tool-side analogue of client.CallWrapper and server.HandlerWrapper.
Reframe the built-in guardrails (MaxSteps, LoopLimit, ApproveTool) as
composed wrappers around a base handler; developer wrappers compose
outermost, so they observe every call and result, including refusals.

Update all provider call sites, the MCP server and chat handlers, the
integration harnesses, and docs to the new signature.

* examples: add agent-wrap-tool showing AgentWrapTool

A runnable example of tool-execution middleware: an observe wrapper that
times calls and records per-tool metrics (correlated by call ID), and a
retry wrapper that recovers a flaky service call before the model sees
it. Demonstrates outermost-first composition and the wrapper/guardrail
interaction (retries are seen by loop detection).

* docs: note AgentWrapTool in README capabilities and CHANGELOG

* fix(generate): pin scaffolded go.mod to one version constant

The two generators pinned different, stale go-micro versions (v5.24.0
for services, v5.25.0 for agents). Centralize on a single
goMicroVersion constant (v5.29.0) so generated services and agents stay
in sync with the framework and there's one place to bump on release.

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-17 09:52:27 +01:00
Asim Aslam ce0741a80c Implement tool-execution wrappers and restructure ToolHandler (#2970)
* feat(agent): tool-execution wrappers via WrapTool

Restructure ai.ToolHandler to the structured, ctx-carrying shape that
mirrors a go-micro RPC handler:

    func(ctx context.Context, call ai.ToolCall) ai.ToolResult

This reuses the existing ToolCall (with its correlation ID) and
ToolResult types instead of the flat (name, input)->(any, string)
signature, and adds ToolCall.Scan for typed argument access.

Add ai.ToolWrapper and the agent option WrapTool / micro.AgentWrapTool —
the tool-side analogue of client.CallWrapper and server.HandlerWrapper.
Reframe the built-in guardrails (MaxSteps, LoopLimit, ApproveTool) as
composed wrappers around a base handler; developer wrappers compose
outermost, so they observe every call and result, including refusals.

Update all provider call sites, the MCP server and chat handlers, the
integration harnesses, and docs to the new signature.

* examples: add agent-wrap-tool showing AgentWrapTool

A runnable example of tool-execution middleware: an observe wrapper that
times calls and records per-tool metrics (correlated by call ID), and a
retry wrapper that recovers a flaky service call before the model sees
it. Demonstrates outermost-first composition and the wrapper/guardrail
interaction (retries are seen by loop detection).

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-16 17:26:30 +01:00
Asim Aslam 5e5d253abd feat(agent): tool-execution wrappers via WrapTool (#2969)
Restructure ai.ToolHandler to the structured, ctx-carrying shape that
mirrors a go-micro RPC handler:

    func(ctx context.Context, call ai.ToolCall) ai.ToolResult

This reuses the existing ToolCall (with its correlation ID) and
ToolResult types instead of the flat (name, input)->(any, string)
signature, and adds ToolCall.Scan for typed argument access.

Add ai.ToolWrapper and the agent option WrapTool / micro.AgentWrapTool —
the tool-side analogue of client.CallWrapper and server.HandlerWrapper.
Reframe the built-in guardrails (MaxSteps, LoopLimit, ApproveTool) as
composed wrappers around a base handler; developer wrappers compose
outermost, so they observe every call and result, including refusals.

Update all provider call sites, the MCP server and chat handlers, the
integration harnesses, and docs to the new signature.

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-16 16:26:56 +01:00
Asim Aslam e079e083da feat(agent): loop detection guardrail + document/blog agent guardrails (#2968)
Add LoopLimit: refuse a tool call repeated with identical arguments in
one Ask, with a self-heal message so the model changes approach. Catches
the no-progress loop that MaxSteps (count) and the gateway circuit
breaker (failures) miss. Enforced at the same tool-handler choke point as
MaxSteps/ApproveTool; on by default (lenient 3); AgentLoopLimit(0) to
disable. Tests cover repeats, distinct calls, disabled, and default-on.

Docs: new Agent Guardrails guide (MaxSteps/LoopLimit/ApproveTool, the
ApproveTool integration seam for external policy engines, and the
gateway's RateLimit/CircuitBreaker), nav + README + AGENT_DESIGN updates,
and blog/23 'Agent Guardrails'.

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-16 14:40:05 +01:00
Asim Aslam a1a57799c3 Add payment requirements to tool catalog and implement x402 client (#2966)
* feat(mcp): advertise x402 payment requirements in the tool catalog

/mcp/tools now includes each priced tool's payment requirements (amount,
network, asset, payTo) when payments are enabled, so an agent can see the
cost before calling and choose by price — a shoppable catalog, the
foundation for a tool marketplace. Free tools carry no payment block; the
shared Tool struct is copied when pricing so it isn't mutated. Tests cover
priced/free tools and payments-disabled. Documented in the payments guide.

* feat(x402): consumer client with a spend budget (pay-and-retry)

Add x402.Client, the consumer counterpart to Middleware: it settles 402
challenges automatically via a pluggable Payer, up to a spend Budget. A
call that would exceed the budget is refused before any payment is made,
and spend accumulates across calls — the spend cap that keeps an
autonomous, paying caller in bounds. Tests cover pay-within-budget,
refuse-over-budget, budget accumulation, and free endpoints, end to end
against the server Middleware with a mock facilitator and payer. Guide
documents the consumer side; agent-level AgentMaxSpend is the next step.

* chore: gofmt gateway/mcp/benchmark_test.go (trailing newline)

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-15 21:12:29 +01:00
Asim Aslam e4d2a41c32 refactor(x402): Amount/Amounts naming + per-tool amounts + docs (#2965)
goreleaser / goreleaser (push) Waiting to run
Follow-up to the merged x402 integration (#2964). Drop the commerce-y
'price' vocabulary for the protocol's own 'amount', and add per-tool
pricing as an operator concern (the way scopes/rate-limits are set at the
gateway).

- x402.Config: Price -> Amount (default), plus Amounts map for per-tool
  overrides; AmountFor(tool) resolves per-tool -> default. Add a Require
  primitive (per-request enforcement) and LoadConfig for an operator
  config file.
- MCP gateway: enforce payment per-tool inside /mcp/call (where scopes
  are enforced) using AmountFor, instead of a flat path-based middleware.
- CLI: --x402-price -> --x402-amount; add --x402-config (per-tool file)
  to micro mcp serve and micro-mcp-gateway.
- docs: new Payments (x402) guide + nav + README section; blog/22
  updated to Amount/Amounts and the config-file model.

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-15 17:04:34 +01:00
Asim Aslam 9deac487cb feat(x402): opt-in agent-native payments for tools (#2964)
Integrate the x402 payment protocol (HTTP 402) so a tool can require a
stablecoin payment and an agent can settle it — the next step after
autonomous agents (blog 21): agents that act, and pay.

- wrapper/x402: HTTP middleware enforcing the 402 challenge/verify flow,
  with a pluggable Facilitator interface. Go Micro carries no chain or
  crypto code — verification/settlement is delegated to a facilitator
  (Coinbase CDP, Alchemy, self-hosted), so Base and Solana are just
  different facilitators behind one interface. HTTPFacilitator default;
  tests cover challenge / accept / reject via a mock facilitator.
- MCP gateway: optional Options.Payment gates /mcp/call (listing tools
  and health stay free); off unless configured.
- micro mcp serve and micro-mcp-gateway: opt-in --x402-pay-to/-price/
  -network/-facilitator flags (env vars on the standalone binary).
- blog/22 'Integrating x402: Payments for Agents'; README feature row.

Pricing is flat per call for now; richer models and an agent-side spend
cap (next to MaxSteps/ApproveTool) are follow-ups.

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-15 16:41:25 +01:00
Asim Aslam 6eec83a045 blog: 'When the Event Is the Prompt' (#21) + autonomous agent-flow harness (#2962)
The autonomy direction: agents that run on events, not human prompts.

- internal/harness/agent-flow: a runnable, deterministic demo — a
  user.created broker event drives a Flow that hands off to a registered
  agent (FlowAgent), which creates a workspace and sends a welcome over
  real RPC. Only the LLM is mocked; passes under -race.
- blog/21: 'When the Event Is the Prompt' — the shift from agents you
  talk to, to agents that act on their own; where microagents become
  real; and the honest bar autonomy raises (guardrails, observability,
  durable/resumable execution — the next things to build).

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-15 12:16:08 +01:00
Asim Aslam 9dae4e34b7 Enhance README with sponsorship CTA and improve agent architecture (#2961)
* docs: add 'become a sponsor' call-to-action linking to Discord

Now that there are a couple of sponsors, invite more: a short CTA under
the Sponsors section in the README and on the landing page, pointing to
the Discord to get in touch.

* fix(health): remove duplicate RegistryCheck declaration

Two PRs (#2957 and #2958) each added a RegistryCheck to the health
package, leaving the package uncompilable on master (RegistryCheck
redeclared: health/registry.go vs health/health.go). Keep the
health.go implementation — it honors the check's context timeout so a
hung registry (e.g. an unreachable etcd) reports down instead of
blocking the probe — and remove the duplicate registry.go and its test.
registry_check_test.go already covers healthy/down/nil/timeout/not-ready.

* feat(agent): pluggable memory and custom tools

Make agents compose the way services do — pluggable pieces with working
defaults — by adding the two abstractions an agent needs beyond the model:

- Memory: a pluggable interface for conversation memory. The default is
  store-backed and durable across restarts (the previous hardcoded
  behavior, now behind an interface); supply your own with WithMemory
  (in-memory, database, semantic store). NewMemory / NewInMemory provided.
- Custom tools: WithTool registers any function as a tool the agent can
  call, so agents are no longer limited to orchestrating RPC services.

Both exposed at the micro package (AgentMemory, AgentTool, NewMemory,
NewInMemory). Behavior-preserving refactor of the agent's history into
the default Memory; tests cover persistence, in-memory, clear, custom
tool dispatch and errors. README + AGENT_DESIGN document the pluggable
composition (model / memory / tools / guardrails).

* blog: 'Doubling Down on Agents' (#20)

The vision post for making agents a first-class framework the way
services were: opinionated, batteries-included, pluggable. Frames an
agent as a composition of model + memory + tools + guardrails with
working defaults; introduces the new pluggable memory and custom tools;
makes the microagents argument (an agent for everything, distributed
like microservices); and lays out the three primitives — services,
agents, workflows — as one substrate, with an honest list of the gaps
still to fill (knowledge/retrieval, streaming, explicit loop).

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-10 11:04:23 +01:00
Asim Aslam b41dfa02f2 docs: add 'become a sponsor' call-to-action linking to Discord (#2960)
Now that there are a couple of sponsors, invite more: a short CTA under
the Sponsors section in the README and on the landing page, pointing to
the Discord to get in touch.

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-10 10:30:10 +01:00
Copilot 0b41c71681 feat(health): add RegistryCheck for registry connectivity health checks (#2957)
goreleaser / goreleaser (push) Waiting to run
* Initial plan

* feat(health): add RegistryCheck for registry connectivity health checks

Add a RegistryCheck function to the health package that creates a health
check verifying connectivity to the service registry. This enables
Kubernetes readiness probes to detect when a service loses its connection
to the registry (e.g. etcd).

Usage:
  health.Register("registry", health.RegistryCheck(reg))

* fix(health): simplify error assertion in registry check test

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
2026-06-10 08:25:23 +01:00
Asim Aslam 550033dcce Optimize image formats and fix lease re-registration issue (#2959)
* perf: convert generated PNGs to optimized JPEGs (12MB -> 1.5MB)

The landing and docs loaded 18 AI-generated PNGs at 0.5-1MB each. They're
1200x800 RGB illustrations with no transparency, so they recompress ~8x
as progressive JPEG (quality 82) with no visible loss. Convert all,
update every reference (.png -> .jpg), and drop the originals (including
the unused hero.png). Generated images: 12.3MB -> 1.5MB.

* fix(registry/etcd): re-register when a lease silently expires (#2956)

The keepalive rework (long-lived KeepAlive instead of KeepAliveOnce)
moved lease renewal entirely onto the keepalive goroutine; the 30s
periodic Register now skips on the 'unchanged' check. The goroutine only
reacted to the keepalive channel closing, so a lease that expired
server-side without a prompt channel close (e.g. a partition that
outlasted the 90s TTL) left the node de-registered from etcd while the
cache still believed it was registered — and nothing re-registered it.
That is the hidden-failure mode reported in #2956.

React to a non-positive TTL keepalive response the same as a channel
close: drop the cached lease/hash so the next Register performs a full
re-registration. Extract the loop into keepAliveLoop and unit-test the
TTL-expired, channel-closed, and healthy paths (no etcd required).

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-10 08:24:49 +01:00
Asim Aslam 584a9f2132 feat(health): add RegistryCheck for registry connectivity (#2956) (#2958)
A go-micro service can keep running while it has silently lost its
connection to the registry (etcd, Consul, …) — the process looks healthy
but other services can no longer discover it, and Kubernetes sees the
pod as fine. health.RegistryCheck(reg) probes connectivity via
ListServices and, registered as a critical check, makes /health/ready
report not-ready so a readiness probe can pull the pod from rotation.

- Works with any registry implementation (no interface change).
- Honors the check timeout: an unreachable/hung registry is reported
  down rather than blocking the probe.
- Tests cover healthy, down, timeout, nil, and the not-ready integration.
- Documented in the health guide with the Kubernetes readiness example.

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-10 08:18:00 +01:00
Asim Aslam 6488d8402d Organize README features, enhance testing, and update docs (#2955)
* docs: group README features by section (AI / Framework / DX)

The features table repeated 'AI' down the Category column. Split into
three grouped tables — AI, Framework, Developer experience & deployment —
dropping the repetitive column. Adds a Guardrails row (MaxSteps,
ApproveTool).

* test: flow-to-agent end-to-end in the harness

Proves 'Flow triggers, Agent reasons': a workflow with FlowAgent hands an
event to the registered conductor agent over RPC, which plans, creates
tasks, and delegates to comms — the whole chain over real RPC with only
the LLM mocked. Deterministic (shared in-memory registry, no sleeps),
passes under -race.

* blog: 'The Evolution of Microservices' (#19)

A technical history of distributed-systems eras — the monolith's
coordination cost, the distributed-systems tax, containers and
declarative orchestration, the service mesh, and the modular-monolith
correction — establishing the durable unit (named, typed, discoverable,
independently deployable) that every runtime wave required. Then the
technical argument for agents: an LLM tool call needs exactly a service
interface, so the caller shifts from deterministic code to a reasoner
that composes typed capabilities from intent, with the honest caveats
(non-determinism, cost, guardrails). Not a product pitch.

* docs: bump install version to v5.27.0

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-08 10:16:05 +01:00
Asim Aslam d3be610367 Refactor README features and add end-to-end flow testing (#2954)
goreleaser / goreleaser (push) Waiting to run
* docs: group README features by section (AI / Framework / DX)

The features table repeated 'AI' down the Category column. Split into
three grouped tables — AI, Framework, Developer experience & deployment —
dropping the repetitive column. Adds a Guardrails row (MaxSteps,
ApproveTool).

* test: flow-to-agent end-to-end in the harness

Proves 'Flow triggers, Agent reasons': a workflow with FlowAgent hands an
event to the registered conductor agent over RPC, which plans, creates
tasks, and delegates to comms — the whole chain over real RPC with only
the LLM mocked. Deterministic (shared in-memory registry, no sleeps),
passes under -race.

* blog: 'The Evolution of Microservices' (#19)

A technical history of distributed-systems eras — the monolith's
coordination cost, the distributed-systems tax, containers and
declarative orchestration, the service mesh, and the modular-monolith
correction — establishing the durable unit (named, typed, discoverable,
independently deployable) that every runtime wave required. Then the
technical argument for agents: an LLM tool call needs exactly a service
interface, so the caller shifts from deterministic code to a reasoner
that composes typed capabilities from intent, with the honest caveats
(non-determinism, cost, guardrails). Not a product pitch.

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-08 09:09:48 +01:00
Asim Aslam 35bc58e5d2 Enhance onboarding experience and clarify workflows vs agents (#2953)
* blog: 'Not Everything Should Be an Agent' (#18) on workflows

The workflow counterpart to the plan/delegate post: when the path is
known, use a deterministic Flow, not an autonomous agent. Frames flow vs
agent as two modes of the same building blocks, covers flow-triggers-
agent dispatch and the agent guardrails, and gives the simplest-first
guidance (single call -> workflow -> agent). Continues the arc from
blog 14/16/17; references Building Effective Agents in passing.

* docs: fix new-user onboarding friction

- README: lead Quick Start with a no-key 30-second path (micro new ->
  micro run -> curl), then the AI --prompt path with an explicit
  'export ANTHROPIC_API_KEY' so the headline command no longer fails
  silently for users without a key.
- Unify all install versions to v5.26.0 (README + docs were split across
  v5.16.0 / v5.25.0).
- Refresh the docs landing overview from the old 'microservices
  framework' framing to 'services and agents', matching the README.
- getting-started: add Prerequisites (Go 1.21+, and that a provider key
  is only needed for AI features).
- README features: Flows -> Workflows wording.

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-08 08:52:11 +01:00
Asim Aslam e416ea4a75 Enhance agent workflows with guardrails and documentation updates (#2952)
* docs: map go-micro onto Anthropic's workflows-vs-agents taxonomy

- new guide 'Agents and Workflows': adopts Anthropic's Building Effective
  Agents vocabulary — workflow (predefined path) = flow, agent (dynamic
  self-direction) = agent — maps the augmented-LLM building block and the
  five workflow patterns onto go-micro, and shows routing (chat router)
  and orchestrator-workers (conductor + plan/delegate) are already native.
- flow package doc reframed as a workflow (predefined path) per the same
  taxonomy, with guidance on flow vs agent.
- nav + README link the new guide.

* feat: agent guardrails — step limit and tool approval hook

Anthropic's Building Effective Agents stresses stopping conditions and
human-in-the-loop checkpoints for autonomous agents. Add both as plain
options enforced at the tool-handler choke point — no provider changes,
no new abstraction:

- MaxSteps(n): bound tool executions per Ask; beyond the limit, actions
  are refused and the model is told to stop and summarize.
- ApproveTool(fn): gate each action before it runs; returning false
  blocks it and surfaces the reason to the model. The internal plan tool
  is never gated.

Exposed at the micro package (AgentMaxSteps, AgentApproveTool, ApproveFunc).
Tests cover the limit, blocking, and that plan is not gated. Guardrails
section of the agents-and-workflows guide updated from 'active work' to
documented options.

* feat: flow can dispatch to an agent (flow triggers, agent reasons)

Unify the engine without collapsing the workflow/agent distinction. A
Flow with Agent set hands each event's rendered prompt to a named
registered agent over RPC (Agent.Chat) instead of running its own LLM
step — so the workflow stays the deterministic trigger and the agent is
the reasoning engine, with its plan, delegate, memory, and guardrails.
A plain flow is unchanged (single augmented-LLM step).

- flow.Agent(name) / micro.FlowAgent(name); flow stores the client and
  skips model setup when dispatching.
- test: dispatch routes to comms.Agent.Chat with the rendered prompt and
  records the reply.
- guide: 'Flow triggers, Agent reasons' section.

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-08 08:32:32 +01:00
Asim Aslam 830c8d84c2 Claude/loving meitner 3 etoi (#2951)
* rename coordinator agent to conductor in example and docs

* add plan & delegate integration harness

Runs the real go-micro stack end to end — services, registry, RPC, the
agent loop, store, and delegate-first routing — with only the LLM mocked
by a deterministic provider. Proves discovery, tool execution, plan
persistence, and agent-to-agent delegation over RPC work without an API
key; swap the provider to run the same flow against a live model.

* test: deterministic CI integration test + provider flag for harness

- main_test.go: TestPlanDelegateEndToEnd drives the full real stack
  (services, RPC, agent loop, store, delegate-first routing) over a
  shared in-memory registry — no mDNS, no sleeps. Asserts 3 tasks
  created via RPC, plan persisted to the store, and delegation reaching
  the comms agent (notify called once). Passes under -race, ~0.03s.
- main.go: add -provider flag (defaults to mock) and key detection so the
  same harness runs against a live model with no code change.

* chore: gitignore built harness/example binaries

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-07 19:28:24 +01:00
Asim Aslam 6a73608e9c rename coordinator agent to conductor in example and docs (#2950)
Co-authored-by: Claude <noreply@anthropic.com>
2026-06-07 18:33:04 +01:00
Asim Aslam cb33decd97 Add built-in plan and delegate tools for agents with examples (#2949)
* feat: add plan and delegate as built-in agent tools

Give agents two self-capabilities, expressed as plain tools wired into
the existing tool handler — no harness or graph, consistent with
"services are the only abstraction":

- plan: record/update an ordered plan, persisted to store-backed memory
  and surfaced in the system prompt on later turns (externalized
  planning).
- delegate: hand a self-contained subtask to another agent.
  Delegate-first — if the target names a registered agent it is called
  via RPC; otherwise a focused ephemeral sub-agent is created with
  agent.New + Ask in a fresh, isolated context (loads/persists no
  history, no built-in tools, so it cannot re-delegate).

Both are added automatically to any non-ephemeral agent, so existing
micro.NewAgent services and micro chat routing get them for free.
Tests are hermetic (memory store + memory registry).

* feat: add agent-plan-delegate example and document plan/delegate

- examples/agent-plan-delegate: coordinator that plans multi-step work,
  creates tasks with its own tools, and delegates notification to a
  separate registered comms agent over RPC.
- integration tests driving the full Ask loop through a fake provider:
  plan tool exposure + persistence, ephemeral delegation with isolated
  context, delegate-first RPC routing to a registered agent.
- docs: README (Building Agents + features + examples), AGENT_DESIGN
  (Built-in Capabilities), agent-patterns guide (Pattern 9), CLAUDE.md.

* docs: blog post and guide for plan & delegate

- blog/17: "Plan & Delegate: Deep Agents in Go" — what the feature is,
  how plan and delegate work, and a runnable getting-started path.
- guides/plan-delegate: reference guide with the smallest-agent snippet,
  plan/delegate semantics, and the multi-agent example; linked in nav.
- example: auto-detect provider/key from common env vars (ANTHROPIC_API_KEY,
  OPENAI_API_KEY, ...) so 'export KEY && go run main.go' just works.
- onboarding: getting-started paths now include go mod init / go get and a
  clone-and-run path, so a reader can actually run it from a cold start.

* refactor: reframe plan/delegate blog and clean up sub-agent construction

- blog/17 retitled "Agents That Plan and Delegate" and reframed around
  intent (plan = state intent, delegate = direct it), positioned as the
  next beat after blog 15/16 and tied to the existing store + agent RPC
  rather than re-announcing them. "Deep agents" now a single in-passing
  nod, matching how blog 14 references LangChain.
- agent: add unexported newEphemeral constructor for sub-agents instead
  of type-asserting the public Agent interface to set an internal field;
  matches the options-only construction idiom used elsewhere.

* feat: expose plan & delegate in the micro chat fallback

Add agent.Builtins(opts...) — returns the built-in tools plus a handler,
so the plan/delegate capabilities can be wired into a tool loop that
isn't a running Agent. micro chat's direct-service fallback now reuses
it (single source of truth, no duplicated handler logic), so planning
and delegation are available there too, not just for registered agents.
Adds a test for the accessor; notes CLI availability in the guide.

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-07 10:55:34 +01:00
Asim Aslam 9bed04ced0 Enhance micro run with interactive console and image compression (#2948)
Run Tests / Unit Tests (push) Waiting to run
Run Tests / Etcd Integration Tests (push) Waiting to run
goreleaser / goreleaser (push) Waiting to run
* perf: compress hero image — 1.4MB to 80KB

Resized from 1536px to 1200px, converted to JPEG at quality 80.
80KB loads instantly vs 1.4MB stalling on slower connections.

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

* docs: micro run drops into interactive console

One command does everything — generate, start, and chat. No
separate micro chat step. The landing page shows micro run
dropping straight into the > prompt.

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

* feat: interactive console in micro run, -d for detached mode

micro run now drops into an interactive chat console after services
start. The console discovers services, exposes them as tools, and
lets you talk to them through an LLM — same as micro chat but
built into the run experience.

- Detects MICRO_AI_PROVIDER and MICRO_AI_API_KEY from environment
- Falls back to provider-specific env vars (ANTHROPIC_API_KEY, etc.)
- If no API key, prints hint and blocks on Ctrl-C (no console)
- -d / --detach flag skips the console (background mode)
- Ctrl-C always shuts everything down

Removed adopters section from README.

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-05 20:49:25 +01:00
Asim Aslam 2e89961386 perf: compress hero image — 1.4MB to 80KB (#2947)
Resized from 1536px to 1200px, converted to JPEG at quality 80.
80KB loads instantly vs 1.4MB stalling on slower connections.

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-05 14:38:02 +01:00
Asim Aslam 39e8dc7311 Reposition hero section and optimize hero image for landing page (#2946)
* docs: reposition hero — framework for services and agents

Landing page: "Build Services and Agents in Go" — positions as a
framework, not a code generator. Tagline: "A framework for
microservices that AI agents can discover, use, and manage."

Hero command reverts to go get (the framework) instead of
micro run --prompt (a feature).

README matches: "framework for building services and agents in Go."

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

* perf: compress hero image — 1.4MB to 80KB

Resized from 1536px to 1200px, converted to JPEG at quality 80.
80KB loads instantly vs 1.4MB stalling on slower connections.

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-05 14:32:35 +01:00
Asim Aslam c93bcdf4d3 Update landing page documentation and fix flow CLI import (#2945)
* docs: remove code references from landing page feature grid

Landing page describes concepts, not APIs. Removed micro.NewAgent()
and micro.NewFlow() code references. Features described in plain
language — what they do, not how to code them.

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

* fix: update micro flow CLI to import from go-micro.dev/v5/flow

The flow package moved to top-level but the CLI still imported
from the old ai/flow path. Fixed to use go-micro.dev/v5/flow.

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-05 11:20:40 +01:00
Asim Aslam cd760a29f1 Update landing page content and fix CLI import path (#2944)
* docs: remove code references from landing page feature grid

Landing page describes concepts, not APIs. Removed micro.NewAgent()
and micro.NewFlow() code references. Features described in plain
language — what they do, not how to code them.

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

* fix: update micro flow CLI to import from go-micro.dev/v5/flow

The flow package moved to top-level but the CLI still imported
from the old ai/flow path. Fixed to use go-micro.dev/v5/flow.

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-05 11:12:00 +01:00
Asim Aslam e45d3df0ad docs: remove code references from landing page feature grid (#2943)
Landing page describes concepts, not APIs. Removed micro.NewAgent()
and micro.NewFlow() code references. Features described in plain
language — what they do, not how to code them.

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-05 11:08:17 +01:00
Asim Aslam 6731ee2f0c Update documentation and blogs for RPC-based agent architecture (#2942)
* docs: update blog posts 15 and 16 to reflect RPC-based agents

Blog 15: replaced broker-based agent communication with RPC —
agents are services, they communicate via standard RPC, no pub/sub
hacks. Updated the framework mapping section.

Blog 16: added proto definition, micro call example, and explanation
that agents are real services with proto-defined endpoints. Updated
Ask() method name.

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

* docs: update agent design doc and blog posts for RPC-based agents

Rewrote AGENT_DESIGN.md — agents are services with proto-defined
Agent.Chat endpoints, communicate via RPC, no broker dependency.
Includes proto definition, CLI examples, generation output.

Blog 15: replaced broker references with RPC.
Blog 16: added proto definition and micro call example.

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

* docs: purge all stale broker-based agent references

Updated across all surfaces:
- README: agents described as services with RPC, Ask() not Chat(),
  micro call example instead of micro agent chat
- Blog 15: replaced broker communication with RPC description
- Blog 16: replaced "coordinate through the broker" with RPC
- Getting started: agent is a service with proto endpoint, Ask()
  not Chat(), added micro flow CLI commands (run/exec), expanded
  CLI workflow table

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-05 11:02:45 +01:00
Asim Aslam f7c042ef26 docs: update blog posts 15 and 16 to reflect RPC-based agents (#2941)
Blog 15: replaced broker-based agent communication with RPC —
agents are services, they communicate via standard RPC, no pub/sub
hacks. Updated the framework mapping section.

Blog 16: added proto definition, micro call example, and explanation
that agents are real services with proto-defined endpoints. Updated
Ask() method name.

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-05 10:31:02 +01:00
Asim Aslam 1bc886fa82 Introduce Agent abstraction and integrate with chat router (#2939)
* docs: Agent interface design sketch

Proposes Agent as a top-level abstraction alongside Service in the
micro package. Agent manages services — scoped tools, system prompt,
conversation memory, registry-discoverable.

Design only, no implementation.

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

* feat: Agent as a first-class abstraction

Introduce micro.NewAgent() alongside micro.New() — Agent is to
intelligence what Service is to capability.

Agent interface:
- Chat(ctx, message) (*Response, error) — core interaction method
- Run() — registers in registry, subscribes to broker, blocks
- Stop() — graceful shutdown
- Scoped tools — only sees endpoints of its assigned services
- Persistent memory — conversation history stored in store
- Agent-to-agent — communication via broker topics

Top-level API:
  agent := micro.NewAgent("task-mgr",
      micro.AgentServices("task"),
      micro.AgentPrompt("You manage tasks."),
      micro.AgentProvider("anthropic"),
  )
  agent.Run()

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

* feat: wire agents into chat router, add micro agent CLI, expose Flow

Three top-level abstractions:
  micro.New("task")              — Service (capability)
  micro.NewAgent("task-mgr")     — Agent (intelligence)
  micro.NewFlow("onboard-user")  — Flow (event-driven orchestration)

micro chat as router:
- Discovers agents from registry on startup
- Single agent: routes directly
- Multiple agents: LLM classifies intent, dispatches to right agent
  via route_to_agent tool
- No agents: falls back to current direct-service behaviour
- Banner shows discovered agents

micro agent CLI:
- micro agent list — shows registered agents and their services
- micro agent describe <name> — shows agent details from registry

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

* feat: move flow to top level, update docs for three abstractions

Package structure now consistent:
  service/   — Service (capability)
  agent/     — Agent (intelligence)
  flow/      — Flow (event-driven orchestration)

ai/flow/ kept as backward-compatible re-export.

Updated across all surfaces:
- CLAUDE.md: added agent/ and flow/ to project structure
- README: added "Building Agents" section with NewAgent() examples,
  updated features table (Agents, Flows, Chat router), CLI table
  (agent list, agent describe), docs links
- Website: features grid shows Services, Agents, Flows as the three
  pillars alongside generation, MCP, and pluggable architecture
- micro.go: Flow imported from top-level flow/ package

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

* docs: rewrite getting-started, fix ai-integration import paths

Getting started now covers all three abstractions:
- Service (write handlers, micro run, templates)
- Agent (micro.NewAgent, scoped tools, memory, CLI)
- Flow (event-driven LLM orchestration)
Leads with prompt-based generation, then manual service creation.

ai-integration.md: fixed flow import path from go-micro.dev/v5/ai/flow
to go-micro.dev/v5/flow, updated stack diagram to show agent/flow/chat.

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

* blog: Introducing micro.NewAgent()

Post 16 — announces Agent as a first-class abstraction. Shows the
API (NewAgent, AgentServices, AgentPrompt, AgentProvider), scoped
tools, persistent memory, multi-service agents, multi-agent systems,
and the three-abstraction comparison table (Service/Agent/Flow).

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

* feat: fix agent registration, blog post 16

Agent registration:
- Add node with address so mDNS can discover agents
- Store type and services in node metadata (mDNS requirement)
- Connect broker before subscribing, non-fatal if broker unavailable
- Print registration confirmation on Run()

Agent/chat discovery:
- Check both service-level and node-level metadata for type=agent
  (mDNS stores metadata on nodes, not services)

Blog post 16: "Introducing micro.NewAgent()" — announces the Agent
abstraction with code examples, comparison table, multi-agent patterns.

Tested end-to-end: micro run → micro agent list discovers the agent →
micro chat routes to it → agent calls service endpoints.

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

* feat: agents are proper services with RPC Chat endpoint

Refactored agent to use server.Server instead of fake registry entries.
An agent now:
- Creates a real RPC server with server.Name(agentName)
- Registers an Agent.Chat handler callable via standard RPC
- Sets server metadata type=agent, services=x,y for discovery
- No more fake addresses or broker hacks

micro chat calls agents via RPC (client.Call) instead of creating
local agent instances. The registry stays clean — agents are real
services with real endpoints.

Removed broker dependency from agent options. Agent-to-agent
communication is just RPC like everything else.

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

* feat: agent uses proto-defined RPC interface

Added agent/proto/agent.proto with Agent service definition:
  rpc Chat(ChatRequest) returns (ChatResponse)

Agent now implements the generated AgentHandler interface and
registers via pb.RegisterAgentHandler. The Chat endpoint is a
standard proto-based RPC callable by any go-micro client.

Renamed the programmatic API from Chat() to Ask() to avoid
collision with the proto handler method name.

micro chat calls agents via standard RPC with JSON-encoded
request/response — no special types needed on the caller side.

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

* feat: generate agent alongside services, update all docs

micro run --prompt now generates an agent binary that manages all
the generated services. The agent reads MICRO_AI_PROVIDER and
MICRO_AI_API_KEY from the environment. micro run propagates these
when started with --prompt.

Run banner shows services and agents separately.

Updated README, getting-started guide, and landing page to show
the complete flow: generate → services + agent start → micro chat
routes to agent → agent orchestrates services.

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-05 10:25:14 +01:00
Asim Aslam 844ac5bc52 Revamp landing hero and introduce agent-based microservices model (#2938)
* docs: update landing hero — describe it, run it, talk to it

Lead with the AI-first experience instead of "write services in Go."
The entry point is now describing what you need, not writing code.

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

* blog: Agents for Services — a new model for microservices

Post 15 — explores the concept of distributed agents managing
services. Each service has an agent assigned to it (not embedded
in it). Agents are the intelligence layer; services are the
capability layer. Multi-service agents span domain boundaries.
Agent-to-agent communication through the broker.

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-04 20:05:45 +01:00
Asim Aslam bc570d674f docs: update landing hero — describe it, run it, talk to it (#2937)
Lead with the AI-first experience instead of "write services in Go."
The entry point is now describing what you need, not writing code.

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-04 18:51:41 +01:00
Asim Aslam e59d056f97 Update Discord invite link and enhance landing hero description (#2936)
* chore: update Discord invite link everywhere

Replace discord.gg/jwTYuUVAGh and discord.gg/go-micro with
discord.gg/WeMU5AGxD across all docs, blog posts, issue templates,
security policy, and contrib READMEs.

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

* docs: update landing hero — describe it, run it, talk to it

Lead with the AI-first experience instead of "write services in Go."
The entry point is now describing what you need, not writing code.

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-04 17:50:11 +01:00
Asim Aslam e13ef7eed5 chore: update Discord invite link everywhere (#2935)
Replace discord.gg/jwTYuUVAGh and discord.gg/go-micro with
discord.gg/WeMU5AGxD across all docs, blog posts, issue templates,
security policy, and contrib READMEs.

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-04 13:46:30 +01:00
Asim Aslam 23f682181c Update section title from 'The Bet' to 'The next step' 2026-06-04 11:53:31 +01:00
Asim Aslam bc1092b18a Restructure README for AI experience and framework clarity (#2934)
* docs: restructure README — AI story completes before manual code

Quick Start now flows through the full AI experience: generate →
review → run → chat → grow (mid-conversation service generation).
The reader sees the complete prompt-to-production story without
interruption.

"Writing Services" is a separate section below for developers who
want to understand the framework underneath. Shows Go code, doc
comments, @example tags, micro run, and scaffolding templates.

Features table and CLI table reordered: AI first, then framework.

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

* blog: Going All In on AI

Post 14 — the strategic case for making AI the primary direction.
Covers the evolution from microservices framework to AI-native
platform, why the timing is right (tool calling works, MCP is real,
sponsors align), and what's not changing (framework still works,
no agent framework complexity).

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-04 11:52:48 +01:00
Asim Aslam 16918669ca docs: restructure README — AI story completes before manual code (#2933)
Quick Start now flows through the full AI experience: generate →
review → run → chat → grow (mid-conversation service generation).
The reader sees the complete prompt-to-production story without
interruption.

"Writing Services" is a separate section below for developers who
want to understand the framework underneath. Shows Go code, doc
comments, @example tags, micro run, and scaffolding templates.

Features table and CLI table reordered: AI first, then framework.

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-04 11:35:57 +01:00
Asim Aslam a357d1870d Update README and landing page with new AI-native hero image (#2932)
* docs: add binary install option to README quick start

Show curl install.sh first (no Go required), go install second.
Uses the existing install script at go-micro.dev/install.sh which
downloads pre-built binaries from GitHub releases.

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

* docs: regenerate hero image for new AI-native positioning

New hero shows terminal running micro run with service generation,
an AI agent orchestrating, and task/shipping/category service nodes.
Matches the "Microservices That AI Agents Can Use" headline.

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

* fix: replace video with hero image on landing page

The old video autoplayed and covered the new hero image. Replace
the video element with a static img tag showing the new AI-native
hero graphic.

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-04 11:27:21 +01:00
Asim Aslam 91a545c6f2 Enhance README with binary install option and update hero image (#2931)
* docs: add binary install option to README quick start

Show curl install.sh first (no Go required), go install second.
Uses the existing install script at go-micro.dev/install.sh which
downloads pre-built binaries from GitHub releases.

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

* docs: regenerate hero image for new AI-native positioning

New hero shows terminal running micro run with service generation,
an AI agent orchestrating, and task/shipping/category service nodes.
Matches the "Microservices That AI Agents Can Use" headline.

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-04 11:21:47 +01:00
Asim Aslam 00392aa1f2 docs: add binary install option to README quick start (#2930)
Show curl install.sh first (no Go required), go install second.
Uses the existing install script at go-micro.dev/install.sh which
downloads pre-built binaries from GitHub releases.

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-04 11:15:40 +01:00
Asim Aslam b54507710d Revise README with new install command and examples
Updated installation command and added usage examples.
2026-06-04 11:14:40 +01:00
Asim Aslam d541625e32 docs: unify README and website around one story (#2929)
Both surfaces now lead with the same line: "Go Micro is a framework
for building microservices that AI agents can use."

README:
- Leads with prompt generation + chat (the differentiator)
- Features as a compact table instead of paragraph-per-feature
- CLI workflow table
- Removed redundant sections, tightened to ~150 lines

Website:
- Hero: "Microservices That AI Agents Can Use"
- Hero command: micro run --prompt instead of go get
- Features grid reordered: AI tools, orchestration, generation first
- First two-col section: describe/generate/run/chat story
- Architecture and DX sections follow

Both tell the same story in the same order:
1. What it is (microservices framework)
2. What makes it different (every service is an AI tool)
3. How you use it (prompt → run → chat)
4. What's underneath (registry, RPC, store — all pluggable)

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-04 11:13:03 +01:00
Asim Aslam 7662b26b07 syntax highlighting (#2928)
* docs: add blog post 13 to blog index

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

* docs: add syntax highlighting to blog post 13 code blocks

Add language tags (bash, go, text) to all fenced code blocks so
Rouge highlights them correctly.

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-04 08:19:52 +01:00
Asim Aslam 397010a82a docs: add blog post 13 to blog index (#2927)
https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-03 22:16:06 +01:00
Asim Aslam d3c4981326 Enhance AI service generation with prompt-based architecture and logic (#2926)
goreleaser / goreleaser (push) Waiting to run
* feat: add micro new --prompt and micro run --prompt

Add AI-powered service generation: describe a system in natural
language and get real go-micro services with proto definitions,
handlers, doc comments, and MCP support.

micro new --prompt "a contact book with notes and tags" \
  --provider anthropic

Generates:
  contacts/ — CRUD service with name, email, phone fields
  notes/    — notes linked to contacts
  tags/     — tagging system

Each service gets:
  proto/{name}.proto   — domain model + CRUD endpoints
  handler/{name}.go    — in-memory store, @example tags for MCP
  main.go              — MCP-enabled, proper imports
  go.mod + Makefile     — compiles with go mod tidy + make proto

micro run --prompt does the same then starts all services.

The LLM designs the architecture (service names, fields, endpoints,
descriptions) and returns structured JSON. Code generation uses
the existing template patterns — the output is standard go-micro
code that compiles, runs, and is immediately callable via MCP
and micro chat. No AI dependency at runtime.

* feat: LLM generates real business logic with compile-fix loop

Rebuild the generate package so the LLM writes actual handler
code with business logic, not just CRUD scaffolding.

The flow is now:
1. LLM designs architecture (service names, fields, endpoints)
   → returns structured JSON
2. Proto, main.go, go.mod, Makefile generated deterministically
   from the design (guaranteed to be correct)
3. go mod tidy + make proto compiles the protos
4. LLM generates handler code with REAL business logic
   → given the proto, endpoint descriptions, and go-micro patterns
5. go build — does it compile?
6. If no: feed errors back to LLM, get fixed code (up to 3 attempts)
7. If yes: service is ready

The handler prompt instructs the LLM to:
- Use sync.RWMutex for thread-safe in-memory state
- Include validation, edge cases, meaningful errors
- Write doc comments with @example tags for MCP
- Implement actual domain logic, not just map operations

Proto generation still uses deterministic templates (CRUD +
custom endpoints from the design spec) to guarantee correctness.
The compile-fix loop catches LLM mistakes automatically.

Both micro new --prompt and micro run --prompt use this flow.

* fix: handle edge cases in prompt-based generation

- Fix PATH for protoc-gen-micro in child processes
- Handle existing directories: skip structural files (main.go,
  go.mod, Makefile) if dir exists, always regenerate proto,
  only write placeholder handler if none exists
- Allow re-running micro new --prompt on same directory to
  iterate on business logic without clobbering user edits

Tested end-to-end: "a simple todo list with tasks and categories"
generates 2 services (task-service, category-service) with real
business logic (validation, toggle complete, etc.), compiles
after 1 fix iteration, and runs with 6 MCP tools discovered.

* feat: auto-detect modified handlers on regeneration

Instead of requiring a --keep-handlers flag, the generate package now
tracks a SHA-256 hash of each generated handler in a .micro metadata
file. On re-run, if the user has edited the handler since generation,
it's left untouched. Unmodified handlers are regenerated normally.

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

* feat: add tests, fix go.mod, gitignore, proto tracking, spinner

- Add 12 tests covering helpers, proto generation, hash tracking
- Fix go.mod: write minimal module file, let go mod tidy resolve deps
- Add .gitignore to prompt-generated services
- Protect user-edited proto files (same hash tracking as handlers)
- Add spinner during LLM calls so it doesn't look hung

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

* feat: signal handling, existing service discovery, help text

- Ctrl+C during generation now cancels LLM calls immediately via
  signal-aware context; re-run picks up where it left off
- Design() scans for existing services in the working directory and
  includes their proto definitions in the prompt, so the LLM extends
  the system rather than redesigning from scratch
- Updated --prompt help text with usage examples on both new and run
- Listed all supported providers in flag descriptions
- Added discoverExisting test

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

* feat: show endpoints in run --prompt output, add micro chat hint

Print endpoint names and descriptions when designing services so users
see what was built. Add a micro chat hint to the run banner so users
know how to interact with their services after startup.

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

* fix: generated go.mod uses go 1.24 with explicit go-micro require

go 1.22 with no explicit require caused Go to resolve sub-packages
(gateway/mcp, client, server) as separate modules, hitting stale v1.18
tags. Pin to go 1.24 + require go-micro.dev/v5 v5.24.0 so go mod tidy
resolves all sub-packages from the root module correctly.

Tested end-to-end: 4 services generated and compiled successfully.

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

* fix: skip handler regeneration when proto unchanged

Compare proto hash before and after structure generation. If the proto
didn't change and the handler wasn't edited by the user, skip go mod
tidy, make proto, LLM handler generation, and compile-fix entirely.
Prints "(unchanged)" instead.

Reduces re-run of 4-service project from ~2 minutes to ~10 seconds.

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

* feat: confirm design before generating code

Show the service design (names, endpoints) and prompt "Generate? [Y/n]"
before spending LLM time on handler generation. Applies to both
micro new --prompt and micro run --prompt. Default is yes (enter).

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

* fix: use port :0 for MCP in generated multi-service projects

Each generated service had mcp.WithMCP(":3001") hardcoded, causing
port conflicts when running multiple services. Use :0 to auto-assign
a free port. micro run's central gateway handles unified MCP access.

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

* feat: truncation detection, tool result display in chat

- Detect truncated LLM responses (unbalanced braces, doesn't end
  with '}') and retry with a conciseness hint before falling through
  to compile-fix
- Show tool call results in micro chat output (← for success, ✗ for
  errors) so users can see what the LLM did
- Add Result/Error fields to ToolCall, populated by Anthropic provider
  after tool execution
- Add isTruncated tests

Tested end-to-end with Anthropic: services generate, compile, start,
register, respond to RPC calls, and micro chat discovers and calls
tools correctly.

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

* fix: Anthropic tool loop, service naming, chat tool results

Anthropic provider:
- Fix tool execution loop to properly iterate (was re-processing all
  tool calls instead of only new ones each round)
- Clean assistant content blocks before sending back (strip 'id' from
  text blocks that Anthropic rejects on input)
- Include tools in follow-up requests so model can make additional calls
- Loop up to 10 rounds until model responds with text only

Service naming:
- Strip '-service' suffix from micro.New() name so services register
  as 'task', 'category' instead of 'taskservice', 'categoryservice'

Chat:
- Show tool results (← for success) and errors (✗) in chat output

Tested end-to-end: create task → list tasks works as multi-step
orchestration through micro chat with Anthropic Claude.

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

* feat: blog post 13 — from prompt to production

Covers the full micro run --prompt flow: design, generate, compile-fix,
run, and chat orchestration. Positions agent-as-orchestrator as the
answer to service coordination.

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

* fix: timeouts, max_tokens, TTY detection, smaller services

- Add 60s timeout on design, 90s on handler generation, 60s on
  compile-fix LLM calls so hung providers don't block forever
- Bump Anthropic max_tokens from 4096 to 8192 to reduce truncation
- Add TTY detection: spinner prints static message in non-TTY (CI/pipes)
  instead of ANSI escape codes
- Tighten prompts: max 200 lines per handler, 2-4 services, 5-8 fields,
  explicit "services don't call each other" rule

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

* feat: chat suggests creating services when capabilities are missing

Update system prompt with the list of available services. When the user
asks for something no existing service can handle, the agent explains
what's available and suggests the exact micro new --prompt command to
create the missing service.

This is the natural evolution path: start with a few services, talk to
them via chat, and when the domain grows, the agent tells you what to
add. Each service stays small and focused.

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

* feat: chat generates and starts services inline, drop -service suffix

Chat agent now has a micro_generate_service tool. When the user asks
for a capability that doesn't exist, the agent generates the service,
compiles it, starts it as a background process, waits for registration,
re-discovers tools, and uses the new endpoints immediately — all within
the conversation.

Service naming: design prompt now instructs LLM to return names without
'-service' suffix (e.g. 'task' not 'task-service'). buildMain keeps
TrimSuffix as safety net for backward compatibility.

Spawned processes are cleaned up when chat exits.

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

* docs: rewrite blog post 13 with inline service generation

Updated to reflect the full UX: services generate and start within
the chat conversation. Added the shipping example showing the agent
creating a service mid-conversation. Removed -service suffix from
all examples. Tightened the narrative around agent-as-orchestrator.

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

* feat: persistent storage, README quickstart, auto-detect new services

Storage: generated handlers now use go-micro's store package instead
of in-memory maps. Data persists across restarts. The handler prompt
includes store API examples so the LLM generates correct store usage.

README: added "Generate From a Prompt" section with micro run --prompt
and micro chat examples, linking to blog post 13.

Watcher: micro run now scans for new service directories every 5s. When
micro chat generates a service, micro run detects the new directory,
builds it, starts it, and adds it to the watcher — fully automatic.
Added AddDir/Dirs methods to the watcher.

Blog: updated post 13 with persistent storage example and watcher note.

https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-03 20:31:01 +01:00
Asim Aslam 96280678ee Expose framework primitives via API gateway and MCP with auth control (#2925)
* feat: expose framework primitives via API gateway and MCP

Add registry, store, and broker as both HTTP routes and MCP tools
so AI agents and HTTP clients can inspect and operate the framework.

API gateway (/micro/* namespace):
  GET  /micro/registry         List registered services
  GET  /micro/registry/{name}  Describe a service
  GET  /micro/store            List store keys
  GET  /micro/store/{key}      Read a record
  POST /micro/store/{key}      Write a record
  POST /micro/broker/{topic}   Publish a message

MCP gateway (micro_* tool prefix):
  micro_registry_list    List services
  micro_registry_get     Describe a service
  micro_store_list       List keys
  micro_store_read       Read a record
  micro_store_write      Write a record
  micro_broker_publish   Publish a message

Framework tools use a Handler field on the MCP Tool struct for
direct dispatch (no RPC). Service tools continue to use RPC.
Rate limiters and circuit breakers are applied to framework
tools the same as service tools.

* fix: make framework internals opt-in on API and MCP gateways

Framework primitives (registry, broker, store) are now only
exposed when explicitly enabled:

API gateway:  micro api --internal
MCP gateway:  Options{Internal: true}

Off by default — user services are always exposed, framework
internals require the flag. Banner output only shows framework
routes when enabled.

* fix: always expose framework internals, gate by auth in production

Revert the --internal flag approach. Framework primitives (registry,
broker, store) are now always exposed:

- micro api: /micro/* routes always available (dev tool)
- MCP gateway: micro_* tools always registered. When Auth is
  configured (production), they require micro:admin scope.
  Without Auth (dev), they're open — same as all other tools.

This follows the existing pattern: micro run/api = dev (open),
micro server = production (auth + scopes). Framework internals
follow the same security model as user services.

Remove the Internal option from MCP Options. Remove --internal
flag from micro api.

Note: scope persistence depends on the store backend. The default
in-memory store does not survive restarts. Use MICRO_STORE=file
for persistent scopes in production.

* fix: correct DefaultStore comment — it's file-backed, not memory

* fix(server): don't recreate deleted admin user on restart

When the default admin account is deleted via the dashboard, set
a marker key (auth/.admin-deleted) in the store. On startup, skip
admin creation if the marker exists. This prevents the default
admin/micro credentials from reappearing after restart when the
user has intentionally removed them.

* fix: improve agent playground first-run UX and fix doc 404s

Agent playground:
- Add setup hint in empty state explaining how to get started
  (click Settings, enter API key, type a prompt)
- Hide hint automatically when API key is already configured
- Add all 7 providers to dropdown (was only OpenAI + Anthropic)
- Include CLI fallback suggestion (micro chat)

Docs:
- Fix .md links to .html across all doc pages — Jekyll serves
  .html files, not .md. Fixes 404s including the micro run guide.

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-03 11:05:51 +01:00
Asim Aslam 69fc228c73 Enhance CLI color output and expose framework primitives via API (#2924)
* feat: expose framework primitives via API gateway and MCP

Add registry, store, and broker as both HTTP routes and MCP tools
so AI agents and HTTP clients can inspect and operate the framework.

API gateway (/micro/* namespace):
  GET  /micro/registry         List registered services
  GET  /micro/registry/{name}  Describe a service
  GET  /micro/store            List store keys
  GET  /micro/store/{key}      Read a record
  POST /micro/store/{key}      Write a record
  POST /micro/broker/{topic}   Publish a message

MCP gateway (micro_* tool prefix):
  micro_registry_list    List services
  micro_registry_get     Describe a service
  micro_store_list       List keys
  micro_store_read       Read a record
  micro_store_write      Write a record
  micro_broker_publish   Publish a message

Framework tools use a Handler field on the MCP Tool struct for
direct dispatch (no RPC). Service tools continue to use RPC.
Rate limiters and circuit breakers are applied to framework
tools the same as service tools.

* fix: make framework internals opt-in on API and MCP gateways

Framework primitives (registry, broker, store) are now only
exposed when explicitly enabled:

API gateway:  micro api --internal
MCP gateway:  Options{Internal: true}

Off by default — user services are always exposed, framework
internals require the flag. Banner output only shows framework
routes when enabled.

* fix: always expose framework internals, gate by auth in production

Revert the --internal flag approach. Framework primitives (registry,
broker, store) are now always exposed:

- micro api: /micro/* routes always available (dev tool)
- MCP gateway: micro_* tools always registered. When Auth is
  configured (production), they require micro:admin scope.
  Without Auth (dev), they're open — same as all other tools.

This follows the existing pattern: micro run/api = dev (open),
micro server = production (auth + scopes). Framework internals
follow the same security model as user services.

Remove the Internal option from MCP Options. Remove --internal
flag from micro api.

Note: scope persistence depends on the store backend. The default
in-memory store does not survive restarts. Use MICRO_STORE=file
for persistent scopes in production.

* fix: correct DefaultStore comment — it's file-backed, not memory

* fix(server): don't recreate deleted admin user on restart

When the default admin account is deleted via the dashboard, set
a marker key (auth/.admin-deleted) in the store. On startup, skip
admin creation if the marker exists. This prevents the default
admin/micro credentials from reappearing after restart when the
user has intentionally removed them.

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-03 08:26:47 +01:00
Asim Aslam 5d7609027b Enhance CLI with color output and add teardown blog post (#2923)
* feat(cli): add color output to micro chat and micro api

micro chat:
- Startup banner matching micro run style: bold header, cyan
  provider/model, green dots for each discovered tool endpoint
- Cyan bold prompt (> ) instead of plain
- Yellow arrow (→) with dimmed tool name for tool calls
- Red "error:" prefix for errors
- Dimmed "(history cleared)" for reset

micro api:
- Startup banner matching micro run style: bold header, cyan
  address, colored HTTP methods (green GET, yellow POST)

Brings the CLI UX closer to what the generated terminal
screenshot depicts — color-coded, professional, readable.

* feat(cli): adopt consistent color output across all commands

Apply the same banner/output style across the remaining commands:

micro new:    bold header, cyan service name, green ✓, cyan URLs
micro build:  green ✓ checkmarks, cyan file paths
micro deploy: bold header, cyan target
micro mcp:    bold header, green dots per tool, dimmed count
micro flow:   bold header, cyan flow/topic/provider

All commands now follow the micro run/chat/api pattern:
bold header, cyan values, green status indicators, dimmed hints.

* docs: add "Tools as Services" blog post

Write blog/12 — connects the AI story back to Go Micro's original
design: services were always self-describing, named, and uniformly
callable. The path from API gateway to MCP to LLM tools is the
same pattern — read the registry, present services in a format
the consumer understands, route calls back.

Covers the access layer pattern (HTTP, web, CLI, MCP, chat),
why doc comments became functional in the AI era, and how the
framework primitives (registry, broker, store) could all become
tools using the same mechanism.

Add to blog index, link forward from blog/11.

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-02 22:15:18 +01:00
Asim Aslam 5601be009a docs: add "Build Your Own AI Agent CLI" teardown blog post (#2921)
Write blog/11 — a teardown of micro chat showing how to build an
LLM tool-calling agent in ~150 lines. Walks through the four pieces:
discover tools, create the model, track conversation, run the loop.
Uses the actual chat.go source. Ends with extension ideas and a
"make it yours" framing.

Add to blog index, link forward from blog/10.

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-02 12:06:22 +01:00
Asim Aslam 888dbbca4a Refactor AI tool handling and enhance CLI command documentation (#2920)
goreleaser / goreleaser (push) Waiting to run
* refactor(ai): rename ToolSet to Tools, simplify wiring with WithTools

Move tool discovery/execution fully into the ai package as ai.Tools
(formerly ai.ToolSet), and simplify the usage model:

- NewTools(reg, ai.ToolClient(c)) takes the execution client as an
  option instead of threading it through Handler(c) per call
- New ai.WithTools(tools) option wires the tool handler into a model
  in one call, replacing ai.WithToolHandler(set.Handler(c))
- ai.DiscoverTools(reg) for one-shot discovery

Before:
  set := ai.NewToolSet(reg)
  list, _ := set.Discover()
  m := ai.New(p, ai.WithToolHandler(set.Handler(client)))

After:
  tools := ai.NewTools(reg, ai.ToolClient(client))
  list, _ := tools.Discover()
  m := ai.New(p, ai.WithTools(tools))

Update ai/flow, micro chat, README, ai integration doc, Atlas Cloud
guide, and blog posts 3/8/9/10.

* feat(cli): add per-interface commands (registry, broker, store, config)

Map go-micro's core interfaces onto the CLI so the framework's
building blocks are inspectable and manipulable from the terminal:

  micro registry list/get/watch       service discovery
  micro broker publish/subscribe      pub/sub messaging
  micro store read/write/delete/list  persistence
  micro config get/dump               dynamic config (from env)

Structured pluggably in cmd/micro/resource: each interface is one
file exposing a Command() func, all wired through a commandFuncs
slice in resource.go. Adding a new resource command is a single
file plus one slice entry. Shared printJSON/fail helpers keep
output and errors consistent across commands.

Each command's verbs mirror the interface methods. Output is JSON
for structured data, raw for single values. Update README and
getting-started with an "inspecting the framework" section.

* docs: update CLI README with all new commands

Add documentation for commands that were missing from the CLI README:
- micro new --template (crud, pubsub, api)
- micro api (standalone HTTP gateway)
- micro registry list/get/watch
- micro broker publish/subscribe
- micro store read/write/delete/list
- micro config get/dump
- micro chat (interactive LLM agent)
- micro flow run/exec (event-driven orchestration)
- micro mcp serve/list/test

Organized into sections: API Gateway, Inspecting the Framework
(registry, broker, store, config), and AI & Agents (chat, flow, mcp).

* refactor(ai): move History from caller to Request field

History is now pure state (no Generate method). Instead, pass it
via Request.History and call ai.Generate(ctx, model, req):

Before:
  hist := ai.NewHistory("system prompt", 50)
  resp, _ := hist.Generate(ctx, model, prompt, tools)

After:
  hist := ai.NewHistory(50)
  resp, _ := ai.Generate(ctx, model, &ai.Request{
      Prompt:       prompt,
      SystemPrompt: "system prompt",
      Tools:        tools,
      History:      hist,
  })

The model is always the thing you call. History is context you
pass in. ai.Generate() handles the bookkeeping: prepends
accumulated messages before the call, records the exchange after.

NewHistory no longer takes a system prompt (it belongs on the
Request, where it always did).

Update micro chat, ai/flow, and all blog posts/docs.

* refactor(ai): make History a plain message accumulator

History no longer has Generate or touches the model. It's just
Add/Messages/Reset/Len with truncation — a helper for building
Request.Messages across turns.

Before:
  hist := ai.NewHistory(50)
  resp, _ := ai.Generate(ctx, m, &ai.Request{History: hist, ...})

After:
  hist := ai.NewHistory(50)
  hist.Add("user", prompt)
  resp, _ := m.Generate(ctx, &ai.Request{Messages: hist.Messages(), ...})
  hist.Add("assistant", resp.Reply)

Remove History field from Request. Remove package-level
ai.Generate(ctx, model, req) wrapper — users call m.Generate()
directly, which is the interface method. History is a convenience
for accumulating messages, not a participant in generation.

Update micro chat, ai/flow, blog posts 9 and 10.

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-05-30 16:20:38 +01:00
Asim Aslam f48d81c760 Cli commands (#2919)
* refactor(ai): rename ToolSet to Tools, simplify wiring with WithTools

Move tool discovery/execution fully into the ai package as ai.Tools
(formerly ai.ToolSet), and simplify the usage model:

- NewTools(reg, ai.ToolClient(c)) takes the execution client as an
  option instead of threading it through Handler(c) per call
- New ai.WithTools(tools) option wires the tool handler into a model
  in one call, replacing ai.WithToolHandler(set.Handler(c))
- ai.DiscoverTools(reg) for one-shot discovery

Before:
  set := ai.NewToolSet(reg)
  list, _ := set.Discover()
  m := ai.New(p, ai.WithToolHandler(set.Handler(client)))

After:
  tools := ai.NewTools(reg, ai.ToolClient(client))
  list, _ := tools.Discover()
  m := ai.New(p, ai.WithTools(tools))

Update ai/flow, micro chat, README, ai integration doc, Atlas Cloud
guide, and blog posts 3/8/9/10.

* feat(cli): add per-interface commands (registry, broker, store, config)

Map go-micro's core interfaces onto the CLI so the framework's
building blocks are inspectable and manipulable from the terminal:

  micro registry list/get/watch       service discovery
  micro broker publish/subscribe      pub/sub messaging
  micro store read/write/delete/list  persistence
  micro config get/dump               dynamic config (from env)

Structured pluggably in cmd/micro/resource: each interface is one
file exposing a Command() func, all wired through a commandFuncs
slice in resource.go. Adding a new resource command is a single
file plus one slice entry. Shared printJSON/fail helpers keep
output and errors consistent across commands.

Each command's verbs mirror the interface methods. Output is JSON
for structured data, raw for single values. Update README and
getting-started with an "inspecting the framework" section.

* docs: update CLI README with all new commands

Add documentation for commands that were missing from the CLI README:
- micro new --template (crud, pubsub, api)
- micro api (standalone HTTP gateway)
- micro registry list/get/watch
- micro broker publish/subscribe
- micro store read/write/delete/list
- micro config get/dump
- micro chat (interactive LLM agent)
- micro flow run/exec (event-driven orchestration)
- micro mcp serve/list/test

Organized into sections: API Gateway, Inspecting the Framework
(registry, broker, store, config), and AI & Agents (chat, flow, mcp).

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-05-30 14:52:22 +01:00
Asim Aslam 3acf74a29a Refactor tool management and add CLI commands for interfaces (#2918)
* refactor(ai): rename ToolSet to Tools, simplify wiring with WithTools

Move tool discovery/execution fully into the ai package as ai.Tools
(formerly ai.ToolSet), and simplify the usage model:

- NewTools(reg, ai.ToolClient(c)) takes the execution client as an
  option instead of threading it through Handler(c) per call
- New ai.WithTools(tools) option wires the tool handler into a model
  in one call, replacing ai.WithToolHandler(set.Handler(c))
- ai.DiscoverTools(reg) for one-shot discovery

Before:
  set := ai.NewToolSet(reg)
  list, _ := set.Discover()
  m := ai.New(p, ai.WithToolHandler(set.Handler(client)))

After:
  tools := ai.NewTools(reg, ai.ToolClient(client))
  list, _ := tools.Discover()
  m := ai.New(p, ai.WithTools(tools))

Update ai/flow, micro chat, README, ai integration doc, Atlas Cloud
guide, and blog posts 3/8/9/10.

* feat(cli): add per-interface commands (registry, broker, store, config)

Map go-micro's core interfaces onto the CLI so the framework's
building blocks are inspectable and manipulable from the terminal:

  micro registry list/get/watch       service discovery
  micro broker publish/subscribe      pub/sub messaging
  micro store read/write/delete/list  persistence
  micro config get/dump               dynamic config (from env)

Structured pluggably in cmd/micro/resource: each interface is one
file exposing a Command() func, all wired through a commandFuncs
slice in resource.go. Adding a new resource command is a single
file plus one slice entry. Shared printJSON/fail helpers keep
output and errors consistent across commands.

Each command's verbs mirror the interface methods. Output is JSON
for structured data, raw for single values. Update README and
getting-started with an "inspecting the framework" section.

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-05-30 14:43:09 +01:00
Asim Aslam c4b4cbef25 refactor(ai): rename ToolSet to Tools, simplify wiring with WithTools (#2917)
Move tool discovery/execution fully into the ai package as ai.Tools
(formerly ai.ToolSet), and simplify the usage model:

- NewTools(reg, ai.ToolClient(c)) takes the execution client as an
  option instead of threading it through Handler(c) per call
- New ai.WithTools(tools) option wires the tool handler into a model
  in one call, replacing ai.WithToolHandler(set.Handler(c))
- ai.DiscoverTools(reg) for one-shot discovery

Before:
  set := ai.NewToolSet(reg)
  list, _ := set.Discover()
  m := ai.New(p, ai.WithToolHandler(set.Handler(client)))

After:
  tools := ai.NewTools(reg, ai.ToolClient(client))
  list, _ := tools.Discover()
  m := ai.New(p, ai.WithTools(tools))

Update ai/flow, micro chat, README, ai integration doc, Atlas Cloud
guide, and blog posts 3/8/9/10.

Co-authored-by: Claude <noreply@anthropic.com>
2026-05-30 14:21:35 +01:00
Asim Aslam a9421e5b7e Update logo design, add AI integration documentation and blog post (#2916)
* feat: update Go Micro logo to interconnected nodes design

Replace the text-on-blue-square logo with a modern icon: three
teal nodes connected in a triangle, representing distributed
systems. Generated via Atlas Cloud. Clean at all sizes — works
as GitHub avatar, favicon, and nav bar icon.

* feat: new logo, AI integration architecture doc, and landing page CTA

Update logo to triangle-nodes icon + "Go Micro" text wordmark.
Save icon-only variant for favicon/avatar use.

Add docs/ai-integration.md — a single page that explains how the
AI stack fits together: services → registry → MCP gateway →
ai/tools → ai.Model → micro chat. Layer-by-layer with code
examples, provider table, and "what you don't need" section.

Add AI Integration to docs sidebar navigation (after Getting
Started). Update the landing page AI section with a direct CTA
button linking to the new doc.

* fix: restore original logo and add border-radius to all renders

Revert logo to original. Add border-radius: 8px to the logo img
in the landing page nav, docs layout nav, and blog layout nav
so the square logo renders with rounded corners everywhere.
Remove unused icon.png.

* docs: add micro chat blog post

Write blog/10 — a dedicated post for micro chat covering:
- What it does (interactive LLM agent for services)
- How it works (ai/tools → ai.History → ai.Model stack)
- Multi-turn conversation examples
- All provider options and env vars
- Single prompt mode for scripting
- Why it works (registry metadata + doc comments = tool descriptions)
- Programmatic usage with the same building blocks
- Link to micro flow as the event-driven counterpart

Add to blog index. Update blog 9 nav to link forward.

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-05-30 13:46:05 +01:00
Asim Aslam 03f912f68a Add AtlasCloud sponsor logo to README 2026-05-30 09:58:44 +01:00
Asim Aslam 594ee107b7 Clean up README.md formatting
Removed unnecessary whitespace and line breaks in README.
2026-05-30 09:58:08 +01:00
Asim Aslam 2f164595f2 Add Atlas Cloud logo link to README
Added an image link for Atlas Cloud to the README.
2026-05-30 09:49:55 +01:00
Asim Aslam 740980a9cc Clean up whitespace in README.md
Removed extra whitespace before the second image link.
2026-05-30 09:49:33 +01:00
Asim Aslam 3d2d9acd68 Fix formatting issues in README.md 2026-05-30 09:46:28 +01:00
Asim Aslam 88aa0cc666 Update logo, add AI integration docs, and enhance CLI features (#2915)
* feat: update Go Micro logo to interconnected nodes design

Replace the text-on-blue-square logo with a modern icon: three
teal nodes connected in a triangle, representing distributed
systems. Generated via Atlas Cloud. Clean at all sizes — works
as GitHub avatar, favicon, and nav bar icon.

* feat: new logo, AI integration architecture doc, and landing page CTA

Update logo to triangle-nodes icon + "Go Micro" text wordmark.
Save icon-only variant for favicon/avatar use.

Add docs/ai-integration.md — a single page that explains how the
AI stack fits together: services → registry → MCP gateway →
ai/tools → ai.Model → micro chat. Layer-by-layer with code
examples, provider table, and "what you don't need" section.

Add AI Integration to docs sidebar navigation (after Getting
Started). Update the landing page AI section with a direct CTA
button linking to the new doc.

* fix: restore original logo and add border-radius to all renders

Revert logo to original. Add border-radius: 8px to the logo img
in the landing page nav, docs layout nav, and blog layout nav
so the square logo renders with rounded corners everywhere.
Remove unused icon.png.

* feat(ai): add ai/flow package and micro flow CLI

Add ai/flow — event-driven LLM orchestration for go-micro. A Flow
subscribes to a broker topic, discovers services as tools, and
feeds each event into an LLM that decides which RPCs to call.

Key types:
- flow.New(name, opts...) creates a flow with trigger topic,
  prompt template, provider config
- flow.Register(registry, broker, client) wires it into a service
- flow.Execute(ctx, data) runs the flow once (for testing/CLI)
- flow.Results() returns execution history

Add micro flow CLI with two subcommands:
- micro flow run: subscribe to a topic and react to events
- micro flow exec: one-shot execution with inline data

Both output JSON results with flow name, prompt, tool calls,
reply, answer, duration, and errors.

Example:
  micro flow run --trigger events.user.created \
    --prompt "New user: {{.Data}}. Send welcome email." \
    --provider anthropic

  micro flow exec --prompt "List all users" --provider anthropic

* docs: update flows blog post with ai/flow package and CLI examples

Add "Update: We Built It" section to blog/9 showing the ai/flow
package API, CLI usage for both event-driven and one-shot modes,
and what it does/doesn't do. Links the conceptual discussion to
the shipped implementation.

* feat(cli): add micro api gateway command, clarify run vs server

Add 'micro api' — a standalone lightweight HTTP-to-RPC gateway:
- POST /{service}/{endpoint} proxies to RPC calls
- GET / lists all services and endpoints
- GET /{service} describes a service
- GET /health returns ok
- Supports Micro-Endpoint header for endpoint routing
- No dashboard, no auth, no hot reload — just the proxy

Update help text to clarify the three gateway modes:
- micro api: bare HTTP-to-RPC proxy
- micro run: development mode (hot reload + gateway + agent playground)
- micro server: production mode (dashboard + auth + JWT)

* docs: update README, getting started, and AI integration for all new features

Update the development workflow table in both README and getting
started to include all CLI commands: micro new --template,
micro api, micro chat, micro flow, micro call.

Getting started:
- Add CRUD template example to quick start
- Update workflow table with 8 stages
- Add AI Integration, MCP, and gRPC Interop to Next Steps

README:
- Add template flag to quick start example
- Update workflow table
- Reorder User Guides with AI Integration prominent

AI Integration doc:
- Update stack diagram to include micro api and ai/flow
- Add micro flow section with Go API and CLI examples
- Add micro api section
- Renumber layers (now 8 instead of 7)

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-05-29 22:49:37 +01:00
Asim Aslam 601c67675f Update logo, add AI integration docs, and enhance CLI features (#2914)
* feat: update Go Micro logo to interconnected nodes design

Replace the text-on-blue-square logo with a modern icon: three
teal nodes connected in a triangle, representing distributed
systems. Generated via Atlas Cloud. Clean at all sizes — works
as GitHub avatar, favicon, and nav bar icon.

* feat: new logo, AI integration architecture doc, and landing page CTA

Update logo to triangle-nodes icon + "Go Micro" text wordmark.
Save icon-only variant for favicon/avatar use.

Add docs/ai-integration.md — a single page that explains how the
AI stack fits together: services → registry → MCP gateway →
ai/tools → ai.Model → micro chat. Layer-by-layer with code
examples, provider table, and "what you don't need" section.

Add AI Integration to docs sidebar navigation (after Getting
Started). Update the landing page AI section with a direct CTA
button linking to the new doc.

* fix: restore original logo and add border-radius to all renders

Revert logo to original. Add border-radius: 8px to the logo img
in the landing page nav, docs layout nav, and blog layout nav
so the square logo renders with rounded corners everywhere.
Remove unused icon.png.

* feat(ai): add ai/flow package and micro flow CLI

Add ai/flow — event-driven LLM orchestration for go-micro. A Flow
subscribes to a broker topic, discovers services as tools, and
feeds each event into an LLM that decides which RPCs to call.

Key types:
- flow.New(name, opts...) creates a flow with trigger topic,
  prompt template, provider config
- flow.Register(registry, broker, client) wires it into a service
- flow.Execute(ctx, data) runs the flow once (for testing/CLI)
- flow.Results() returns execution history

Add micro flow CLI with two subcommands:
- micro flow run: subscribe to a topic and react to events
- micro flow exec: one-shot execution with inline data

Both output JSON results with flow name, prompt, tool calls,
reply, answer, duration, and errors.

Example:
  micro flow run --trigger events.user.created \
    --prompt "New user: {{.Data}}. Send welcome email." \
    --provider anthropic

  micro flow exec --prompt "List all users" --provider anthropic

* docs: update flows blog post with ai/flow package and CLI examples

Add "Update: We Built It" section to blog/9 showing the ai/flow
package API, CLI usage for both event-driven and one-shot modes,
and what it does/doesn't do. Links the conceptual discussion to
the shipped implementation.

* feat(cli): add micro api gateway command, clarify run vs server

Add 'micro api' — a standalone lightweight HTTP-to-RPC gateway:
- POST /{service}/{endpoint} proxies to RPC calls
- GET / lists all services and endpoints
- GET /{service} describes a service
- GET /health returns ok
- Supports Micro-Endpoint header for endpoint routing
- No dashboard, no auth, no hot reload — just the proxy

Update help text to clarify the three gateway modes:
- micro api: bare HTTP-to-RPC proxy
- micro run: development mode (hot reload + gateway + agent playground)
- micro server: production mode (dashboard + auth + JWT)

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-05-29 18:13:06 +01:00
Asim Aslam b97f45106d Update logo, add AI integration docs, and implement ai/flow package (#2913)
* feat: update Go Micro logo to interconnected nodes design

Replace the text-on-blue-square logo with a modern icon: three
teal nodes connected in a triangle, representing distributed
systems. Generated via Atlas Cloud. Clean at all sizes — works
as GitHub avatar, favicon, and nav bar icon.

* feat: new logo, AI integration architecture doc, and landing page CTA

Update logo to triangle-nodes icon + "Go Micro" text wordmark.
Save icon-only variant for favicon/avatar use.

Add docs/ai-integration.md — a single page that explains how the
AI stack fits together: services → registry → MCP gateway →
ai/tools → ai.Model → micro chat. Layer-by-layer with code
examples, provider table, and "what you don't need" section.

Add AI Integration to docs sidebar navigation (after Getting
Started). Update the landing page AI section with a direct CTA
button linking to the new doc.

* fix: restore original logo and add border-radius to all renders

Revert logo to original. Add border-radius: 8px to the logo img
in the landing page nav, docs layout nav, and blog layout nav
so the square logo renders with rounded corners everywhere.
Remove unused icon.png.

* feat(ai): add ai/flow package and micro flow CLI

Add ai/flow — event-driven LLM orchestration for go-micro. A Flow
subscribes to a broker topic, discovers services as tools, and
feeds each event into an LLM that decides which RPCs to call.

Key types:
- flow.New(name, opts...) creates a flow with trigger topic,
  prompt template, provider config
- flow.Register(registry, broker, client) wires it into a service
- flow.Execute(ctx, data) runs the flow once (for testing/CLI)
- flow.Results() returns execution history

Add micro flow CLI with two subcommands:
- micro flow run: subscribe to a topic and react to events
- micro flow exec: one-shot execution with inline data

Both output JSON results with flow name, prompt, tool calls,
reply, answer, duration, and errors.

Example:
  micro flow run --trigger events.user.created \
    --prompt "New user: {{.Data}}. Send welcome email." \
    --provider anthropic

  micro flow exec --prompt "List all users" --provider anthropic

* docs: update flows blog post with ai/flow package and CLI examples

Add "Update: We Built It" section to blog/9 showing the ai/flow
package API, CLI usage for both event-driven and one-shot modes,
and what it does/doesn't do. Links the conceptual discussion to
the shipped implementation.

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-05-29 17:13:16 +01:00
Asim Aslam 28fa44b2ca Update logo design, enhance AI integration docs, and simplify navigation (#2912)
* feat: update Go Micro logo to interconnected nodes design

Replace the text-on-blue-square logo with a modern icon: three
teal nodes connected in a triangle, representing distributed
systems. Generated via Atlas Cloud. Clean at all sizes — works
as GitHub avatar, favicon, and nav bar icon.

* feat: new logo, AI integration architecture doc, and landing page CTA

Update logo to triangle-nodes icon + "Go Micro" text wordmark.
Save icon-only variant for favicon/avatar use.

Add docs/ai-integration.md — a single page that explains how the
AI stack fits together: services → registry → MCP gateway →
ai/tools → ai.Model → micro chat. Layer-by-layer with code
examples, provider table, and "what you don't need" section.

Add AI Integration to docs sidebar navigation (after Getting
Started). Update the landing page AI section with a direct CTA
button linking to the new doc.

* fix: restore original logo and add border-radius to all renders

Revert logo to original. Add border-radius: 8px to the logo img
in the landing page nav, docs layout nav, and blog layout nav
so the square logo renders with rounded corners everywhere.
Remove unused icon.png.

* fix: trim nav to 3 links across all layouts

Remove Reference and Home links from nav across landing page,
docs layout, and blog layout. Keep only Docs, Blog, GitHub —
the three things people actually need. Fixes crowded nav on
mobile where 5 links plus a menu button didn't fit.

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-05-29 16:55:36 +01:00
Asim Aslam 985621f4b4 AI integration updates (#2911)
* feat: update Go Micro logo to interconnected nodes design

Replace the text-on-blue-square logo with a modern icon: three
teal nodes connected in a triangle, representing distributed
systems. Generated via Atlas Cloud. Clean at all sizes — works
as GitHub avatar, favicon, and nav bar icon.

* feat: new logo, AI integration architecture doc, and landing page CTA

Update logo to triangle-nodes icon + "Go Micro" text wordmark.
Save icon-only variant for favicon/avatar use.

Add docs/ai-integration.md — a single page that explains how the
AI stack fits together: services → registry → MCP gateway →
ai/tools → ai.Model → micro chat. Layer-by-layer with code
examples, provider table, and "what you don't need" section.

Add AI Integration to docs sidebar navigation (after Getting
Started). Update the landing page AI section with a direct CTA
button linking to the new doc.

* fix: restore original logo and add border-radius to all renders

Revert logo to original. Add border-radius: 8px to the logo img
in the landing page nav, docs layout nav, and blog layout nav
so the square logo renders with rounded corners everywhere.
Remove unused icon.png.

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-05-29 16:30:23 +01:00
Asim Aslam 7a1ab14847 docs: rewrite Anthropic blog post with updated content and new header image (#2910)
goreleaser / goreleaser (push) Waiting to run
Rewrite blog/3 to reflect current state of the project:
- Update numbers (7 providers, image/video support, micro chat)
- Add "What Came After" section covering everything shipped since
- Tighten prose, remove stale roadmap percentages
- Replace generic MCP image with Claude-themed header generated
  via Atlas Cloud (orange AI orb connecting to service nodes)
- Streamline code examples
- Update star count and Try It section

Co-authored-by: Claude <noreply@anthropic.com>
2026-05-29 15:57:39 +01:00
Asim Aslam c26d74a8a1 Add CRUD, pub/sub, and API gateway templates; update AI features (#2909)
* feat(website): redesign docs and blog layouts, add blog header images

Redesign both layouts to match the new landing page:
- Consistent nav bar with logo, Docs, Blog, GitHub, Reference, Home
- Consistent footer with copyright and links
- CSS custom properties for theming
- Updated typography, spacing, and code block styling
- Active sidebar link highlighting in docs
- Dark mode support preserved

Generate 4 blog header images via Atlas Cloud:
- blog-deploy.png for post 1 (micro deploy)
- blog-mcp.png for posts 2, 3, 7 (MCP-related)
- blog-agents-demo.png for post 4 (agents demo)
- blog-dx.png for post 5 (DX cleanup)
- Reuse data-model.png for post 6 (model package)

All 7 existing blog posts now have header images.

* fix(website): prevent horizontal scroll on mobile landing page

Add overflow-x: hidden on html and body. Set max-width: 100% and
height: auto on all section and two-col images. Add overflow:
hidden to .two-col grid. Constrain hero pre with max-width and
overflow-x. Reduce font sizes and padding at mobile breakpoint.

* feat(website): add images to remaining core doc pages

Generate 5 more images via Atlas Cloud for docs:
- registry.png: service discovery diagram
- broker.png: pub/sub message broker pattern
- transport.png: multi-transport layers (HTTP, gRPC, NATS)
- config.png: dynamic configuration from multiple sources
- observability.png: monitoring dashboard with metrics/traces

Add images to registry.md, broker.md, transport.md, config.md,
observability.md, and architecture.md. All 11 main doc pages
now have header images.

* feat: add sponsor logos to landing page, README images, and flows blog post

Add Anthropic and Atlas Cloud sponsor logos to the landing page
with links to their respective blog posts. Logos display at 0.7
opacity with hover effect.

Add architecture and MCP agent images to the GitHub README for
the Overview and MCP sections.

Write blog post 9: "From Chat to Flows" — explores the concept
of LLM-powered service orchestration. Compares micro chat's
interactive model with persistent event-driven flows, shows how
the existing building blocks (ai/tools, History, broker) could
compose into a flow engine, discusses tradeoffs vs traditional
orchestration (Step Functions, Temporal), and includes a working
15-line code example. Explicitly positions it as a concept for
community feedback, not an announcement.

* feat(website): add animated hero video to landing page

Generate a 6-second hero video via Atlas Cloud's image-to-video
API (gemini-omni-flash). Shows the microservices network diagram
animating with data flowing between nodes.

Replace the static hero image with an autoplay muted looping
video element. Falls back to the static image via poster
attribute and img fallback for browsers without video support.

* feat(ai): add VideoModel interface with Atlas Cloud provider

Add ai.VideoModel interface for video generation alongside Model
and ImageModel. Supports text-to-video and image-to-video via
VideoRequest with prompt, reference images, duration, aspect
ratio, and resolution fields.

Implement GenerateVideo for Atlas Cloud using their async API:
POST /api/v1/model/generateVideo → poll /api/v1/model/prediction.
Default model is gemini-omni-flash image-to-video. Polls every
5 seconds until completion or context cancellation.

Register Atlas Cloud as a video provider via ai.RegisterVideo.
Add 3 tests: registration, no-key error, compile-time interface
check. Update ai/README.md with VideoModel docs.

The ai package now covers all three modalities:
- Model (text) — 7 providers
- ImageModel (image) — 2 providers (Atlas Cloud, OpenAI)
- VideoModel (video) — 1 provider (Atlas Cloud)

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-05-29 15:52:35 +01:00
Asim Aslam 669481224c Enhance AI features with ImageModel, History, and website updates (#2907)
* feat(cli): add CRUD, pub/sub, and API gateway templates for micro new

Add --template flag to 'micro new' with three preset templates:

- crud: CRUD service with Create/Read/Update/Delete/List, in-memory
  store with sync.RWMutex, UUID generation, pagination, and doc
  comments with @example tags for MCP tool discovery.

- pubsub: Event-driven service with Publish/Stats RPCs and a
  Subscribe method that hooks into the broker. Includes event
  types with ID, type, source, data, and timestamp.

- api: API gateway service with Health and Endpoint RPCs, an
  internal HTTP route table, and a response recorder for
  proxying requests through RPC.

All templates include MCP-ready doc comments and work with
--no-mcp. The default template (no flag) is unchanged.

Usage:
  micro new myservice --template crud
  micro new myservice --template pubsub
  micro new myservice --template api

* fix(ai): update Atlas Cloud provider to use actual API formats

Fix the Atlas Cloud image generation to use their real async API:
POST /api/v1/model/generateImage → poll /api/v1/model/prediction/{id}
instead of the OpenAI-compatible endpoint which doesn't exist.

Add Quality and OutputFormat fields to ai.ImageRequest for
provider-specific image parameters.

Update default text model from llama-3.3-70b (doesn't exist) to
deepseek-ai/DeepSeek-V3-0324 (their flagship model). Update
default image model to openai/gpt-image-2/text-to-image.

* feat(website): add AI-generated images to landing page, docs, and blog

Generate 5 images via Atlas Cloud's image API (gpt-image-2) to
elevate the website experience:

- hero.png: microservices network graph for landing page
- architecture.png: registry + broker architecture diagram
- mcp-agent.png: AI agent calling services via MCP
- developer-experience.png: terminal showing micro run/chat
- blog-atlas.png: Atlas Cloud unified API illustration

Add visual sections to the landing page with architecture,
MCP integration, and developer experience showcases. Add
images to docs index, MCP docs, and Atlas Cloud blog post.

All images resized to 1200px wide and optimized for web.
Generated using Atlas Cloud sponsor credits.

* feat(website): redesign landing page and add images to docs

Redesign the landing page from a centered card layout to a
full-width modern site with:
- Top navigation bar
- Hero section with gradient background and CTA buttons
- Full-width image showcase sections
- Two-column layout for architecture, MCP, and DX sections
- Feature grid with 6 capabilities
- Footer with links
- Responsive breakpoints for mobile

Generate 3 more images via Atlas Cloud for docs:
- getting-started.png for the getting started guide
- deployment.png for the deployment guide
- data-model.png for the data model docs

Add images to getting-started.md, model.md, and deployment.md.

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-05-29 15:16:05 +01:00
Asim Aslam 86782e6d77 Add ImageModel interface and multi-turn conversation support (#2906)
* feat(ai): add ImageModel interface with Atlas Cloud and OpenAI support

Add ai.ImageModel interface for text-to-image generation alongside
the existing ai.Model for text. Uses the same options pattern
(WithAPIKey, WithBaseURL) and the same provider registration
system (RegisterImage/NewImage).

Implement GenerateImage for Atlas Cloud and OpenAI providers via
the OpenAI-compatible /v1/images/generations endpoint. Default
image model is gpt-image-1. Responses return images as URL,
base64, or both depending on the provider.

Update Atlas Cloud blog post and integration guide with image
generation examples. Update ai/README.md with ImageModel docs.

* fix(website): widen docs content by reducing layout max-width to 1100px

Remove the 800px max-width on .content (which left empty space on
the right) and reduce the overall .layout and footer from 1400px
to 1100px. With the 230px sidebar this gives ~830px of content
width — readable and fills the page properly on desktop.

* feat(ai): add History for multi-turn conversation state

Add ai.History — a lightweight message accumulator that tracks
user prompts, assistant replies, and tool call/result pairs
across turns. FIFO truncation when message count exceeds the
configured limit. System prompt is passed through on every
Generate call.

Wire History into micro chat so conversations are multi-turn by
default (limit 50 messages). Add 'reset' command to clear
history mid-session.

5 unit tests covering accumulation, truncation, reset, snapshot
isolation, and tool call recording.

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-05-28 14:44:46 +01:00
Asim Aslam 1e2901ad0e feat(ai): add ImageModel interface with Atlas Cloud and OpenAI support (#2905)
goreleaser / goreleaser (push) Waiting to run
Add ai.ImageModel interface for text-to-image generation alongside
the existing ai.Model for text. Uses the same options pattern
(WithAPIKey, WithBaseURL) and the same provider registration
system (RegisterImage/NewImage).

Implement GenerateImage for Atlas Cloud and OpenAI providers via
the OpenAI-compatible /v1/images/generations endpoint. Default
image model is gpt-image-1. Responses return images as URL,
base64, or both depending on the provider.

Update Atlas Cloud blog post and integration guide with image
generation examples. Update ai/README.md with ImageModel docs.

Co-authored-by: Claude <noreply@anthropic.com>
2026-05-28 12:21:46 +01:00
Asim Aslam 426d7e4e6c fix: align sponsor logos with fixed height and clean SVG sources (#2903)
goreleaser / goreleaser (push) Waiting to run
Use height="26" on both logos for consistent alignment. Switch
Anthropic to the Wikimedia wordmark SVG (no padding) instead of
the logo.wine version which had excessive whitespace.

Co-authored-by: Claude <noreply@anthropic.com>
2026-05-28 11:07:38 +01:00
Asim Aslam 5968fce2d6 docs: add Atlas Cloud sponsorship blog post and integration guide (#2902)
Add blog/8 announcing Atlas Cloud as an official Go Micro sponsor.
Covers the sponsorship, Atlas Cloud's platform (300+ models, OpenAI
compatibility, enterprise compliance), and how the integration
works with the ai package, ai/tools, micro chat, and micro run.

Add guides/atlascloud-integration.md with full setup instructions:
quick start, configuration options, environment variables, model
selection, tool calling with services, and provider swapping.

Add Atlas Cloud and AI Provider guides to the docs sidebar
navigation. Add sponsorship link to README header.

Co-authored-by: Claude <noreply@anthropic.com>
2026-05-28 11:04:04 +01:00
Asim Aslam 415b0a76c2 Fix README header formatting
Removed a redundant pipe character from the README header.
2026-05-28 10:55:54 +01:00
Asim Aslam 7ef9a60441 Update README with documentation link and cleanup
Added documentation link to the README header and removed redundant documentation line.
2026-05-28 10:53:53 +01:00
Asim Aslam be156ecb95 Adjust logo width in README
Reduce the width of the Anthropic logo in sponsors section.
2026-05-28 10:53:01 +01:00
Asim Aslam 713dabbb5a Update Anthropic logo URL in README 2026-05-28 10:52:34 +01:00
Asim Aslam bbea48da78 Add sponsors section to README
Added sponsors section with Anthropic logo to README.
2026-05-28 10:52:03 +01:00
Asim Aslam a0ad9ee566 Claude/fix issue 2893 x3rpd (#2901)
* docs: add AI provider integration guide and Supported AI Providers section

Add a step-by-step guide for AI infrastructure companies to implement
ai.Model and contribute a provider to go-micro. Covers the full
lifecycle: skeleton, tool call handling, tests, registration, and PR
checklist.

Add a "Supported AI Providers" section to the project README that lists
current providers (Anthropic, OpenAI) in a table and links to the
integration guide with a call-to-action for new providers and sponsors.

Streamline the "Adding a New Provider" section in ai/README.md to point
to the new guide instead of duplicating a full code listing.

* fix: remove nonexistent Discord link from README

* fix(website): set content container width to 800px on desktop

Move the 800px max-width from .markdown-body up to .content so
the entire content pane (not just the inner body) is sized
correctly. The container now fills up to 800px beside the sidebar.

* feat(ai): wire Atlas Cloud into server and auto-detection

Import atlascloud provider in the micro server so it is available
when running micro run / micro server. Add atlascloud to
AutoDetectProvider so --ai_base_url with an atlascloud domain
selects the right provider automatically.

* feat(ai): add Google Gemini provider

Add ai/gemini implementing ai.Model for Google's Gemini API. Uses
the native generateContent endpoint with system_instruction,
contents/parts, and functionDeclarations — not an OpenAI shim.
Default model gemini-2.5-flash, auth via x-goog-api-key header.

Wire into micro server imports and AutoDetectProvider (matches
googleapis.com and google in base URL).

Update README.md and ai/README.md with provider listing.

* feat(ai): add Groq, Mistral, and Together AI providers

Add three new OpenAI-compatible providers:

- ai/groq: ultra-fast inference, default model llama-3.3-70b-versatile
- ai/mistral: Mistral AI, default model mistral-large-latest
- ai/together: Together AI, default model Llama-3.3-70B-Instruct-Turbo

All three are wired into the micro server imports and
AutoDetectProvider. README and ai/README updated with the full
provider table.

* feat(ai): add ai/tools helper and 'micro chat' interactive agent

Extract the registry-discovery + RPC-execution loop from the web
agent playground into a reusable ai/tools package:

- tools.New(reg) creates a Set bound to a registry
- Set.Discover() walks the registry and returns []ai.Tool with
  LLM-safe (underscored) names, remembering the mapping back to
  the original dotted form
- Set.Handler(client) returns an ai.ToolHandler that resolves
  the safe name and issues the RPC

Add cmd/micro/chat — an interactive 'micro chat' REPL that uses
ai/tools to let users talk to their services through any
registered AI provider. Supports --prompt for single-shot use,
auto-detects the provider from --base_url, and falls back to the
provider's conventional env var (ANTHROPIC_API_KEY, etc).

Update README with the new command and the programmatic example.

* feat(examples): add gRPC interop example

Add examples/grpc-interop showing that any standard gRPC client can
call a go-micro service — no go-micro SDK required on the client
side. Includes:

- proto/greeter.proto with generated Go, gRPC, and micro stubs
- server/ using go-micro gRPC transport
- client/ using stock google.golang.org/grpc (no go-micro imports)
- README with Python example and explanation of how routing works

Addresses the confusion from issue #2818 where users didn't know
that go-micro gRPC services are callable by any gRPC client.

* fix: strip /api prefix from MCP routes

Change /api/mcp/tools and /api/mcp/call to /mcp/tools and
/mcp/call. MCP is a first-class feature, not a sub-path of the
API proxy. Update server routes, playground template, scopes
template, run.go output, README, CLI README, and all docs.

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-05-26 12:19:26 +01:00
Asim Aslam f5e33317b3 Remove Micro app platform promotion from README
Removed the promotion for the Micro app platform from the README.
2026-05-24 18:17:31 +01:00
Asim Aslam 081e375f29 Add AI provider integration guide and new providers support (#2900)
* docs: add AI provider integration guide and Supported AI Providers section

Add a step-by-step guide for AI infrastructure companies to implement
ai.Model and contribute a provider to go-micro. Covers the full
lifecycle: skeleton, tool call handling, tests, registration, and PR
checklist.

Add a "Supported AI Providers" section to the project README that lists
current providers (Anthropic, OpenAI) in a table and links to the
integration guide with a call-to-action for new providers and sponsors.

Streamline the "Adding a New Provider" section in ai/README.md to point
to the new guide instead of duplicating a full code listing.

* fix: remove nonexistent Discord link from README

* fix(website): set content container width to 800px on desktop

Move the 800px max-width from .markdown-body up to .content so
the entire content pane (not just the inner body) is sized
correctly. The container now fills up to 800px beside the sidebar.

* feat(ai): wire Atlas Cloud into server and auto-detection

Import atlascloud provider in the micro server so it is available
when running micro run / micro server. Add atlascloud to
AutoDetectProvider so --ai_base_url with an atlascloud domain
selects the right provider automatically.

* feat(ai): add Google Gemini provider

Add ai/gemini implementing ai.Model for Google's Gemini API. Uses
the native generateContent endpoint with system_instruction,
contents/parts, and functionDeclarations — not an OpenAI shim.
Default model gemini-2.5-flash, auth via x-goog-api-key header.

Wire into micro server imports and AutoDetectProvider (matches
googleapis.com and google in base URL).

Update README.md and ai/README.md with provider listing.

* feat(ai): add Groq, Mistral, and Together AI providers

Add three new OpenAI-compatible providers:

- ai/groq: ultra-fast inference, default model llama-3.3-70b-versatile
- ai/mistral: Mistral AI, default model mistral-large-latest
- ai/together: Together AI, default model Llama-3.3-70B-Instruct-Turbo

All three are wired into the micro server imports and
AutoDetectProvider. README and ai/README updated with the full
provider table.

* feat(ai): add ai/tools helper and 'micro chat' interactive agent

Extract the registry-discovery + RPC-execution loop from the web
agent playground into a reusable ai/tools package:

- tools.New(reg) creates a Set bound to a registry
- Set.Discover() walks the registry and returns []ai.Tool with
  LLM-safe (underscored) names, remembering the mapping back to
  the original dotted form
- Set.Handler(client) returns an ai.ToolHandler that resolves
  the safe name and issues the RPC

Add cmd/micro/chat — an interactive 'micro chat' REPL that uses
ai/tools to let users talk to their services through any
registered AI provider. Supports --prompt for single-shot use,
auto-detects the provider from --base_url, and falls back to the
provider's conventional env var (ANTHROPIC_API_KEY, etc).

Update README with the new command and the programmatic example.

* feat(examples): add gRPC interop example

Add examples/grpc-interop showing that any standard gRPC client can
call a go-micro service — no go-micro SDK required on the client
side. Includes:

- proto/greeter.proto with generated Go, gRPC, and micro stubs
- server/ using go-micro gRPC transport
- client/ using stock google.golang.org/grpc (no go-micro imports)
- README with Python example and explanation of how routing works

Addresses the confusion from issue #2818 where users didn't know
that go-micro gRPC services are callable by any gRPC client.

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-05-24 18:17:04 +01:00
Asim Aslam 2f78103fed Claude/fix issue 2893 x3rpd (#2899)
* docs: add AI provider integration guide and Supported AI Providers section

Add a step-by-step guide for AI infrastructure companies to implement
ai.Model and contribute a provider to go-micro. Covers the full
lifecycle: skeleton, tool call handling, tests, registration, and PR
checklist.

Add a "Supported AI Providers" section to the project README that lists
current providers (Anthropic, OpenAI) in a table and links to the
integration guide with a call-to-action for new providers and sponsors.

Streamline the "Adding a New Provider" section in ai/README.md to point
to the new guide instead of duplicating a full code listing.

* feat(ai): add Atlas Cloud provider

Add ai/atlascloud implementing ai.Model for Atlas Cloud's
OpenAI-compatible chat completions API. Registers as "atlascloud"
with default model llama-3.3-70b and base URL
https://api.atlascloud.ai. Supports tool calling via ToolHandler.

Includes 7 unit tests covering registration, defaults, init,
generate-without-key, and stream-not-implemented.

Update the Supported AI Providers table in README.md and the
Supported Providers section in ai/README.md.

* fix: remove nonexistent Discord link from README

* fix(website): remove Micro app banner and widen content to 800px

Remove the "Try Micro" promotional banner from the homepage. Set
the docs content max-width to 800px for better readability on
desktop.

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-05-24 13:49:32 +01:00
Asim Aslam 60527e1fe8 Add AI provider integration guide and Atlas Cloud support (#2898)
* docs: add AI provider integration guide and Supported AI Providers section

Add a step-by-step guide for AI infrastructure companies to implement
ai.Model and contribute a provider to go-micro. Covers the full
lifecycle: skeleton, tool call handling, tests, registration, and PR
checklist.

Add a "Supported AI Providers" section to the project README that lists
current providers (Anthropic, OpenAI) in a table and links to the
integration guide with a call-to-action for new providers and sponsors.

Streamline the "Adding a New Provider" section in ai/README.md to point
to the new guide instead of duplicating a full code listing.

* feat(ai): add Atlas Cloud provider

Add ai/atlascloud implementing ai.Model for Atlas Cloud's
OpenAI-compatible chat completions API. Registers as "atlascloud"
with default model llama-3.3-70b and base URL
https://api.atlascloud.ai. Supports tool calling via ToolHandler.

Includes 7 unit tests covering registration, defaults, init,
generate-without-key, and stream-not-implemented.

Update the Supported AI Providers table in README.md and the
Supported Providers section in ai/README.md.

* fix: remove nonexistent Discord link from README

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-05-24 13:31:44 +01:00
Asim Aslam defb2786ef update AI provider documentation (#2897)
goreleaser / goreleaser (push) Waiting to run
* feat: add prometheus monitoring wrapper

Reintroduces the Prometheus metrics wrapper previously available in the
plugins repository, updated for go-micro v5. Exposes request count and
latency histograms for handlers, subscribers, and outgoing client calls
via NewHandlerWrapper, NewSubscriberWrapper, NewCallWrapper and
NewClientWrapper, labelled with service/endpoint/status.

Options cover namespace, subsystem, const labels, histogram buckets and
a custom registerer; duplicate collectors (e.g. from multiple wrappers
sharing the same config) are reused transparently via a cached
metrics bundle.

Fixes #2893

* fix(registry/etcd): clear lease/register caches on KeepAlive channel closure

When the etcd client's long-lived KeepAlive channel closes (e.g. because
the lease expired on the server side during a network partition), the
previous cleanup only removed the channel bookkeeping. The stale entries
in `leases` and `register` caused the next registerNode() heartbeat to
hit the "unchanged hash" short-circuit and skip re-registration entirely,
so the service permanently disappeared from etcd.

Extract the cleanup into handleKeepAliveClosed and also drop the cached
lease id and hash so the next heartbeat performs a full Grant+Put and
the service recovers within one RegisterInterval.

Regression introduced by #2822; fix is symmetric with the existing
synchronous KeepAliveOnce recovery path that propagates
rpctypes.ErrLeaseNotFound.

* docs: add AI provider integration guide and Supported AI Providers section

Add a step-by-step guide for AI infrastructure companies to implement
ai.Model and contribute a provider to go-micro. Covers the full
lifecycle: skeleton, tool call handling, tests, registration, and PR
checklist.

Add a "Supported AI Providers" section to the project README that lists
current providers (Anthropic, OpenAI) in a table and links to the
integration guide with a call-to-action for new providers and sponsors.

Streamline the "Adding a New Provider" section in ai/README.md to point
to the new guide instead of duplicating a full code listing.

* Update contribution guidelines in README.md

Removed Discord contact information for platform contributions.

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-05-10 17:14:04 +01:00
Asim Aslam 15cc876848 Emphasize 'Micro' in README link 2026-05-10 17:01:53 +01:00
Asim Aslam d3cfb3a99a Update app platform name from 'Mu' to 'Micro' 2026-05-10 17:01:23 +01:00
Asim Aslam b1680ca2da Update app platform link from Mu.xyz to Micro 2026-05-10 16:21:41 +01:00
Asim Aslam 90f7617fac Claude/fix issue 2893 x3rpd (#2895)
* feat: add prometheus monitoring wrapper

Reintroduces the Prometheus metrics wrapper previously available in the
plugins repository, updated for go-micro v5. Exposes request count and
latency histograms for handlers, subscribers, and outgoing client calls
via NewHandlerWrapper, NewSubscriberWrapper, NewCallWrapper and
NewClientWrapper, labelled with service/endpoint/status.

Options cover namespace, subsystem, const labels, histogram buckets and
a custom registerer; duplicate collectors (e.g. from multiple wrappers
sharing the same config) are reused transparently via a cached
metrics bundle.

Fixes #2893

* fix(registry/etcd): clear lease/register caches on KeepAlive channel closure

When the etcd client's long-lived KeepAlive channel closes (e.g. because
the lease expired on the server side during a network partition), the
previous cleanup only removed the channel bookkeeping. The stale entries
in `leases` and `register` caused the next registerNode() heartbeat to
hit the "unchanged hash" short-circuit and skip re-registration entirely,
so the service permanently disappeared from etcd.

Extract the cleanup into handleKeepAliveClosed and also drop the cached
lease id and hash so the next heartbeat performs a full Grant+Put and
the service recovers within one RegisterInterval.

Regression introduced by #2822; fix is symmetric with the existing
synchronous KeepAliveOnce recovery path that propagates
rpctypes.ErrLeaseNotFound.

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-04-20 14:55:01 +01:00
Asim Aslam 79722e0c27 feat: add prometheus monitoring wrapper (#2894)
Reintroduces the Prometheus metrics wrapper previously available in the
plugins repository, updated for go-micro v5. Exposes request count and
latency histograms for handlers, subscribers, and outgoing client calls
via NewHandlerWrapper, NewSubscriberWrapper, NewCallWrapper and
NewClientWrapper, labelled with service/endpoint/status.

Options cover namespace, subsystem, const labels, histogram buckets and
a custom registerer; duplicate collectors (e.g. from multiple wrappers
sharing the same config) are reused transparently via a cached
metrics bundle.

Fixes #2893

Co-authored-by: Claude <noreply@anthropic.com>
2026-04-15 09:24:43 +01:00
jejefferson 49070afa8c server/grpc: improve graceful stop behavior (#2892)
* server/grpc: improve graceful stop behavior

* server/grpc: add graceful stop example and test

* examples/graceful-stop: document verification steps
2026-04-10 08:10:10 +01:00
Asim Aslam 03f4759474 Fix inline style attribute in index.html 2026-04-08 07:42:12 +01:00
Asim Aslam f6fb541ace Enhance Mu.xyz promotion with styled div
Updated the promotional text for Mu.xyz with enhanced styling.
2026-04-08 07:40:51 +01:00
Asim Aslam 1426c8f349 Update README to use emoji for Mu.xyz link 2026-04-08 07:34:54 +01:00
Asim Aslam 5aedb601ba Add Mu.xyz promotional link to README
Added a promotional link for Mu.xyz app platform.
2026-04-08 07:34:25 +01:00
Asim Aslam bd13975acf Update container width and add promotional text
Increased the maximum width of the container and added a promotional paragraph for Mu.xyz.
2026-04-08 07:33:47 +01:00
Asim Aslam 213a09276e Update default.html 2026-03-26 10:11:00 +00:00
Asim Aslam f4291957e8 Remove Blog link from index.html
Removed the Blog link from the website index.
2026-03-26 10:09:12 +00:00
Asim Aslam 07411b1ef6 Remove article on chat app from blog index
Removed an article about building a chat app from the blog.
2026-03-26 10:08:54 +00:00
Asim Aslam 544496eec6 Delete internal/website/blog/8.md 2026-03-26 10:08:26 +00:00
Asim Aslam 2e95c4c610 Remove showcase section from index.html
Removed the showcase section for Go Micro projects.
2026-03-26 10:08:01 +00:00
BombartSimon 7b785df302 feat: add connection timeout call option (#2891) 2026-03-16 13:34:24 +00:00
Asim Aslam d96f12f57b Claude/update docs roadmap f zd2 j (#2889)
* feat: add agent platform showcase and blog post

Add a complete platform example (Users, Posts, Comments, Mail) that
mirrors micro/blog, demonstrating how existing microservices become
AI-accessible through MCP with zero code changes.

Includes blog post "Your Microservices Are Already an AI Platform"
walking through real agent workflows: signup, content creation,
commenting, tagging, and cross-service messaging.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* refactor: rename handler types to drop redundant Service suffix

UserService → Users, PostService → Posts, CommentService → Comments,
MailService → Mail. Matches micro/blog naming convention.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* refactor: consolidate top-level directories, reduce framework bloat

Move internal/non-public packages behind internal/ or into their
parent packages where they belong:

- deploy/ → gateway/mcp/deploy/ (Helm charts belong with the gateway)
- profile/ → service/profile/ (preset plugin profiles are a service concern)
- scripts/ → internal/scripts/ (install script is not public API)
- test/ → internal/test/ (test harness is not public API)
- util/ → internal/util/ (internal helpers shouldn't be imported externally)

Also fixes CLAUDE.md merge conflict markers and updates project
structure documentation.

All import paths updated. Build and tests pass.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* refactor: redesign model package to match framework conventions

Rename model.Database interface to model.Model (consistent with
client.Client, server.Server, store.Store). Remove generics in
favor of interface{}-based API with reflection.

Key changes:
- model.Model interface: Register once, CRUD infers table from type
- DefaultModel + NewModel() + package-level convenience functions
- Schema registered via Register(&User{}), no per-call schema passing
- Memory implementation as default (in model package, like store)
- memory/sqlite/postgres backends updated for new interface
- protoc-gen-micro generates RegisterXModel() instead of generic factory
- All docs, blog, and README updated

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* docs: clarify blog post 7 uses modular monolith, not multi-service

Blog post 7 demonstrated all handlers in a single process but framed
it as microservices without acknowledging the architectural difference.

- Add "A Note on Architecture" section explaining this is a modular
  monolith demo and pointing to micro/blog for multi-service
- Clarify that handlers can be broken out into separate services later
- Fix "service registry" language to match single-process reality
- Restructure "Adding MCP to Existing Services" to distinguish the
  in-process approach from registry-based gateway options
- Update closing to acknowledge both paradigms
- Fix README type names (&CommentService{} -> &Comments{}, etc.)

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* docs: add Micro Chat to website showcase

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* feat: github artifact release CI (#2886)

* 👷feat(ci): add artifact and docker releases

* 💚fix(ci): build issues

* 💚fix(ci): add permissions

* 💚fix(ci): multiple artifacts

* 💚fix(ci): split archives

* 💚fix(ci): cross platform list

* 🚧chore(ci): package name

* 🐛fix(script): install script extract arch

* 👷fix(ci): docker origin go-micro

* Update image reference in goreleaser configuration (#2887)

Fix wrong order `user/repo`

* Add blog post on building a chat app with Go Micro

Added a blog post detailing the development of a full chat app using Go Micro, outlining features, architecture, and lessons learned.

* docs: add blog post 8 to index, put Blog before Docs on homepage

- Add "We Built a Full Chat App in a Day" (blog/8) to blog index
- Reorder homepage links: Blog first (primary), Docs second
- Rename "Documentation" to "Docs"

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Alexander Serheyev <74361701+alex-dna-tech@users.noreply.github.com>
2026-03-07 13:00:22 +00:00
Asim Aslam 8608c15fbb Add blog post on building a chat app with Go Micro
Added a blog post detailing the development of a full chat app using Go Micro, outlining features, architecture, and lessons learned.
2026-03-07 12:49:39 +00:00
Asim Aslam 9823f6df5c Add platform showcase, blog post, and refactor project structure (#2888)
* feat: add agent platform showcase and blog post

Add a complete platform example (Users, Posts, Comments, Mail) that
mirrors micro/blog, demonstrating how existing microservices become
AI-accessible through MCP with zero code changes.

Includes blog post "Your Microservices Are Already an AI Platform"
walking through real agent workflows: signup, content creation,
commenting, tagging, and cross-service messaging.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* refactor: rename handler types to drop redundant Service suffix

UserService → Users, PostService → Posts, CommentService → Comments,
MailService → Mail. Matches micro/blog naming convention.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* refactor: consolidate top-level directories, reduce framework bloat

Move internal/non-public packages behind internal/ or into their
parent packages where they belong:

- deploy/ → gateway/mcp/deploy/ (Helm charts belong with the gateway)
- profile/ → service/profile/ (preset plugin profiles are a service concern)
- scripts/ → internal/scripts/ (install script is not public API)
- test/ → internal/test/ (test harness is not public API)
- util/ → internal/util/ (internal helpers shouldn't be imported externally)

Also fixes CLAUDE.md merge conflict markers and updates project
structure documentation.

All import paths updated. Build and tests pass.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* refactor: redesign model package to match framework conventions

Rename model.Database interface to model.Model (consistent with
client.Client, server.Server, store.Store). Remove generics in
favor of interface{}-based API with reflection.

Key changes:
- model.Model interface: Register once, CRUD infers table from type
- DefaultModel + NewModel() + package-level convenience functions
- Schema registered via Register(&User{}), no per-call schema passing
- Memory implementation as default (in model package, like store)
- memory/sqlite/postgres backends updated for new interface
- protoc-gen-micro generates RegisterXModel() instead of generic factory
- All docs, blog, and README updated

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* docs: clarify blog post 7 uses modular monolith, not multi-service

Blog post 7 demonstrated all handlers in a single process but framed
it as microservices without acknowledging the architectural difference.

- Add "A Note on Architecture" section explaining this is a modular
  monolith demo and pointing to micro/blog for multi-service
- Clarify that handlers can be broken out into separate services later
- Fix "service registry" language to match single-process reality
- Restructure "Adding MCP to Existing Services" to distinguish the
  in-process approach from registry-based gateway options
- Update closing to acknowledge both paradigms
- Fix README type names (&CommentService{} -> &Comments{}, etc.)

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* docs: add Micro Chat to website showcase

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-03-07 09:33:18 +00:00
Alexander Serheyev 28f7f53143 Update image reference in goreleaser configuration (#2887)
goreleaser / goreleaser (push) Waiting to run
Fix wrong order `user/repo`
2026-03-06 15:30:53 +00:00
Alexander Serheyev 0842431050 feat: github artifact release CI (#2886)
goreleaser / goreleaser (push) Waiting to run
* 👷feat(ci): add artifact and docker releases

* 💚fix(ci): build issues

* 💚fix(ci): add permissions

* 💚fix(ci): multiple artifacts

* 💚fix(ci): split archives

* 💚fix(ci): cross platform list

* 🚧chore(ci): package name

* 🐛fix(script): install script extract arch

* 👷fix(ci): docker origin go-micro
2026-03-06 14:49:18 +00:00
Asim Aslam 7a5d86a2a4 Claude/update docs roadmap f zd2 j (#2885)
* feat: add agent platform showcase and blog post

Add a complete platform example (Users, Posts, Comments, Mail) that
mirrors micro/blog, demonstrating how existing microservices become
AI-accessible through MCP with zero code changes.

Includes blog post "Your Microservices Are Already an AI Platform"
walking through real agent workflows: signup, content creation,
commenting, tagging, and cross-service messaging.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* refactor: rename handler types to drop redundant Service suffix

UserService → Users, PostService → Posts, CommentService → Comments,
MailService → Mail. Matches micro/blog naming convention.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* refactor: consolidate top-level directories, reduce framework bloat

Move internal/non-public packages behind internal/ or into their
parent packages where they belong:

- deploy/ → gateway/mcp/deploy/ (Helm charts belong with the gateway)
- profile/ → service/profile/ (preset plugin profiles are a service concern)
- scripts/ → internal/scripts/ (install script is not public API)
- test/ → internal/test/ (test harness is not public API)
- util/ → internal/util/ (internal helpers shouldn't be imported externally)

Also fixes CLAUDE.md merge conflict markers and updates project
structure documentation.

All import paths updated. Build and tests pass.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* refactor: redesign model package to match framework conventions

Rename model.Database interface to model.Model (consistent with
client.Client, server.Server, store.Store). Remove generics in
favor of interface{}-based API with reflection.

Key changes:
- model.Model interface: Register once, CRUD infers table from type
- DefaultModel + NewModel() + package-level convenience functions
- Schema registered via Register(&User{}), no per-call schema passing
- Memory implementation as default (in model package, like store)
- memory/sqlite/postgres backends updated for new interface
- protoc-gen-micro generates RegisterXModel() instead of generic factory
- All docs, blog, and README updated

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* docs: clarify blog post 7 uses modular monolith, not multi-service

Blog post 7 demonstrated all handlers in a single process but framed
it as microservices without acknowledging the architectural difference.

- Add "A Note on Architecture" section explaining this is a modular
  monolith demo and pointing to micro/blog for multi-service
- Clarify that handlers can be broken out into separate services later
- Fix "service registry" language to match single-process reality
- Restructure "Adding MCP to Existing Services" to distinguish the
  in-process approach from registry-based gateway options
- Update closing to acknowledge both paradigms
- Fix README type names (&CommentService{} -> &Comments{}, etc.)

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-03-05 13:13:31 +00:00
Asim Aslam 8ecdf07e6b Update description of the blogging platform example 2026-03-05 12:03:26 +00:00
Asim Aslam 1bb25d6e7f Add agent platform showcase and refactor project structure (#2884)
* feat: add agent platform showcase and blog post

Add a complete platform example (Users, Posts, Comments, Mail) that
mirrors micro/blog, demonstrating how existing microservices become
AI-accessible through MCP with zero code changes.

Includes blog post "Your Microservices Are Already an AI Platform"
walking through real agent workflows: signup, content creation,
commenting, tagging, and cross-service messaging.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* refactor: rename handler types to drop redundant Service suffix

UserService → Users, PostService → Posts, CommentService → Comments,
MailService → Mail. Matches micro/blog naming convention.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* refactor: consolidate top-level directories, reduce framework bloat

Move internal/non-public packages behind internal/ or into their
parent packages where they belong:

- deploy/ → gateway/mcp/deploy/ (Helm charts belong with the gateway)
- profile/ → service/profile/ (preset plugin profiles are a service concern)
- scripts/ → internal/scripts/ (install script is not public API)
- test/ → internal/test/ (test harness is not public API)
- util/ → internal/util/ (internal helpers shouldn't be imported externally)

Also fixes CLAUDE.md merge conflict markers and updates project
structure documentation.

All import paths updated. Build and tests pass.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* refactor: redesign model package to match framework conventions

Rename model.Database interface to model.Model (consistent with
client.Client, server.Server, store.Store). Remove generics in
favor of interface{}-based API with reflection.

Key changes:
- model.Model interface: Register once, CRUD infers table from type
- DefaultModel + NewModel() + package-level convenience functions
- Schema registered via Register(&User{}), no per-call schema passing
- Memory implementation as default (in model package, like store)
- memory/sqlite/postgres backends updated for new interface
- protoc-gen-micro generates RegisterXModel() instead of generic factory
- All docs, blog, and README updated

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-03-05 11:21:41 +00:00
Asim Aslam b8fc0902d7 Claude/update docs roadmap f zd2 j (#2883)
* feat: add agent platform showcase and blog post

Add a complete platform example (Users, Posts, Comments, Mail) that
mirrors micro/blog, demonstrating how existing microservices become
AI-accessible through MCP with zero code changes.

Includes blog post "Your Microservices Are Already an AI Platform"
walking through real agent workflows: signup, content creation,
commenting, tagging, and cross-service messaging.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* refactor: rename handler types to drop redundant Service suffix

UserService → Users, PostService → Posts, CommentService → Comments,
MailService → Mail. Matches micro/blog naming convention.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-03-05 08:56:24 +00:00
Asim Aslam 524e16296b Update documentation, add agent demo, and enhance service API (#2882)
* docs: update all four documentation guides and mark Q2 complete

- ai-native-services: add WithMCP one-liner, standalone gateway,
  WebSocket client example, and OpenTelemetry observability section
- mcp-security: add OTel distributed tracing, WebSocket authentication
  (connection-level and per-message), DeniedReason audit field
- tool-descriptions: add manual overrides with WithEndpointDocs and
  export formats section
- agent-patterns: add LangChain/LlamaIndex SDK pattern and standalone
  gateway production pattern with Docker example
- Update roadmap: mark Q2 documentation as complete, Q2 at 100%
- Update status: reflect all recent completions, shift priorities

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* feat: add agent demo example and blog post

Add examples/agent-demo with a multi-service project management app
(projects, tasks, team) that demonstrates AI agents interacting with
Go Micro services through MCP. Includes seed data and example prompts.

Add blog post 4 "Agents Meet Microservices: A Hands-On Demo" walking
through the example code and showing cross-service agent workflows.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* feat: enable multiple services in a single binary

Remove global state mutations from service and cmd option functions so
that configuring one service no longer overwrites another's settings.

Key changes:
- service/options.go: remove all DefaultXxx global writes from option
  functions; newOptions() now creates fresh Server, Client, Store, and
  Cache per service while sharing Registry, Broker, and Transport
- cmd/cmd.go: newCmd() uses local copies instead of pointers to package
  globals; Before() no longer mutates DefaultXxx vars
- cmd/options.go: remove global mutations from all option functions
- service/service.go: export ServiceImpl type for cross-package use
- service/group.go: new Group type for multi-service lifecycle
- micro.go: add Start/Stop to Service interface, expose Group and
  NewGroup convenience function
- examples/multi-service: working example with two services

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* docs: highlight multi-service binary support

Add multi-service section to README with code example, update features
list, add to examples index, and note in status summary.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* feat: unify service API and clean up developer experience

- Unified service creation: micro.New("name", opts...) as canonical API
- Clean handler registration: service.Handle(handler, opts...) accepts
  server.HandlerOption args directly, no need to reach through Server()
- Unexported serviceImpl: users interact through Service interface only
- Service groups use Service interface (not concrete type)
- Fixed Stop() to properly propagate BeforeStop/AfterStop errors
- Fixed store init: error-level log instead of fatal on init failure
- Updated all examples to use consistent patterns
- Updated README, getting-started, MCP docs, and guides
- Added blog post about the DX cleanup

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* fix: add blog post 5 to blog index

Blog post 5 (Developer Experience Cleanup) existed as a file but was
missing from the blog index page.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* feat: make micro new generate MCP-enabled services by default

- main.go template includes mcp.WithMCP(":3001") by default
- Handler template has agent-friendly doc comments with @example tags
- Proto template has descriptive field comments
- README includes MCP usage, Claude Code config, and tool description tips
- Makefile adds mcp-tools, mcp-test, mcp-serve targets
- go.mod updated to Go 1.22
- Added --no-mcp flag to opt out of MCP integration
- Post-create output shows MCP endpoint URLs

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* docs: add MCP migration guide and troubleshooting guide

- Migration guide: 3 approaches to add MCP to existing services
  (WithMCP one-liner, standalone gateway, CLI)
- Troubleshooting guide: common issues with agents, WebSocket,
  Claude Code, auth, rate limiting, and performance

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* refactor: rename model/ package to ai/ for AI model providers

The model/ package name conflicted with the conventional use of "model"
for data models. Renamed to ai/ which better describes the package's
purpose (AI provider abstraction for Anthropic, OpenAI, etc.) and frees
up model/ for future data model layer use.

- Rename model/ → ai/ with package name change
- Update all Go imports from go-micro.dev/v5/model to go-micro.dev/v5/ai
- Update cmd/micro/server/server.go references (model.X → ai.X)
- Update all documentation and roadmap references
- All tests pass, CLI builds successfully

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* feat: add model package for typed data access with CRUD and queries

New model/ package provides a typed data model layer using Go generics.
Supports structured CRUD operations, WHERE filters, ordering, pagination,
and automatic schema creation from struct tags.

Three backends:
- memory: in-memory for development and testing
- sqlite: embedded SQL for dev and single-node production
- postgres: full PostgreSQL for production deployments

Key features:
- Generic Model[T] with Create/Read/Update/Delete/List/Count
- Query builder: Where(), WhereOp(), OrderAsc/Desc(), Limit(), Offset()
- Struct tags: model:"key" for primary key, model:"index" for indexes
- Auto table creation from struct schema
- 19 tests passing across memory and sqlite backends

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* feat: add model code generation to protoc-gen-micro

Extend the micro plugin to generate model structs from proto messages
annotated with // @model. Generated alongside client/server code in
the same .pb.micro.go file.

For a proto message like:
  // @model
  message User { string id = 1; string name = 2; }

Generates:
- UserModel struct with model:"key" and json tags
- NewUserModel(db) factory returning *model.Model[UserModel]
- UserModelFromProto(*User) *UserModel converter
- (*UserModel).ToProto() *User converter

Supports @model(table=custom_table, key=custom_field) options.
Adds GetComments() to generator for plugin comment inspection.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* feat: add Model() to Service interface for Client/Server/Model trifecta

Every service now exposes Client(), Server(), and Model() — call services,
handle requests, and save/query data from the same interface. Includes
README docs, blog post, and a full model guide on the docs site.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* feat: add Helm chart for MCP gateway Kubernetes deployment

Adds official Helm chart at deploy/helm/mcp-gateway/ with:
- Deployment, Service, ServiceAccount templates
- HPA for auto-scaling based on CPU/memory
- Ingress with TLS support
- Configurable registry (consul, etcd, mdns), rate limiting,
  JWT auth, audit logging, and per-tool scopes
- Security context (non-root, read-only rootfs, drop all caps)
- NOTES.txt with post-install connection instructions

Updates roadmap and status docs to reflect Helm Charts as delivered.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* docs: add Helm chart entry to changelog

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* feat: add per-tool circuit breakers to MCP gateway

Protects downstream services from cascading failures. When a tool's
RPC calls fail repeatedly, the circuit opens and rejects requests
immediately until the service recovers (half-open probe pattern).

- CircuitBreakerConfig with MaxFailures, Timeout, MaxHalfOpen
- Per-tool breakers created during service discovery
- Integrated into HTTP call path with 503 response when open
- Records success/failure after each RPC call
- --circuit-breaker and --circuit-breaker-timeout CLI flags
- 8 unit tests covering all state transitions

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-03-05 08:32:59 +00:00
Asim Aslam d91812b476 Update documentation and add multi-service support with examples (#2881)
* docs: update all four documentation guides and mark Q2 complete

- ai-native-services: add WithMCP one-liner, standalone gateway,
  WebSocket client example, and OpenTelemetry observability section
- mcp-security: add OTel distributed tracing, WebSocket authentication
  (connection-level and per-message), DeniedReason audit field
- tool-descriptions: add manual overrides with WithEndpointDocs and
  export formats section
- agent-patterns: add LangChain/LlamaIndex SDK pattern and standalone
  gateway production pattern with Docker example
- Update roadmap: mark Q2 documentation as complete, Q2 at 100%
- Update status: reflect all recent completions, shift priorities

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* feat: add agent demo example and blog post

Add examples/agent-demo with a multi-service project management app
(projects, tasks, team) that demonstrates AI agents interacting with
Go Micro services through MCP. Includes seed data and example prompts.

Add blog post 4 "Agents Meet Microservices: A Hands-On Demo" walking
through the example code and showing cross-service agent workflows.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* feat: enable multiple services in a single binary

Remove global state mutations from service and cmd option functions so
that configuring one service no longer overwrites another's settings.

Key changes:
- service/options.go: remove all DefaultXxx global writes from option
  functions; newOptions() now creates fresh Server, Client, Store, and
  Cache per service while sharing Registry, Broker, and Transport
- cmd/cmd.go: newCmd() uses local copies instead of pointers to package
  globals; Before() no longer mutates DefaultXxx vars
- cmd/options.go: remove global mutations from all option functions
- service/service.go: export ServiceImpl type for cross-package use
- service/group.go: new Group type for multi-service lifecycle
- micro.go: add Start/Stop to Service interface, expose Group and
  NewGroup convenience function
- examples/multi-service: working example with two services

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* docs: highlight multi-service binary support

Add multi-service section to README with code example, update features
list, add to examples index, and note in status summary.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* feat: unify service API and clean up developer experience

- Unified service creation: micro.New("name", opts...) as canonical API
- Clean handler registration: service.Handle(handler, opts...) accepts
  server.HandlerOption args directly, no need to reach through Server()
- Unexported serviceImpl: users interact through Service interface only
- Service groups use Service interface (not concrete type)
- Fixed Stop() to properly propagate BeforeStop/AfterStop errors
- Fixed store init: error-level log instead of fatal on init failure
- Updated all examples to use consistent patterns
- Updated README, getting-started, MCP docs, and guides
- Added blog post about the DX cleanup

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* fix: add blog post 5 to blog index

Blog post 5 (Developer Experience Cleanup) existed as a file but was
missing from the blog index page.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* feat: make micro new generate MCP-enabled services by default

- main.go template includes mcp.WithMCP(":3001") by default
- Handler template has agent-friendly doc comments with @example tags
- Proto template has descriptive field comments
- README includes MCP usage, Claude Code config, and tool description tips
- Makefile adds mcp-tools, mcp-test, mcp-serve targets
- go.mod updated to Go 1.22
- Added --no-mcp flag to opt out of MCP integration
- Post-create output shows MCP endpoint URLs

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* docs: add MCP migration guide and troubleshooting guide

- Migration guide: 3 approaches to add MCP to existing services
  (WithMCP one-liner, standalone gateway, CLI)
- Troubleshooting guide: common issues with agents, WebSocket,
  Claude Code, auth, rate limiting, and performance

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* refactor: rename model/ package to ai/ for AI model providers

The model/ package name conflicted with the conventional use of "model"
for data models. Renamed to ai/ which better describes the package's
purpose (AI provider abstraction for Anthropic, OpenAI, etc.) and frees
up model/ for future data model layer use.

- Rename model/ → ai/ with package name change
- Update all Go imports from go-micro.dev/v5/model to go-micro.dev/v5/ai
- Update cmd/micro/server/server.go references (model.X → ai.X)
- Update all documentation and roadmap references
- All tests pass, CLI builds successfully

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* feat: add model package for typed data access with CRUD and queries

New model/ package provides a typed data model layer using Go generics.
Supports structured CRUD operations, WHERE filters, ordering, pagination,
and automatic schema creation from struct tags.

Three backends:
- memory: in-memory for development and testing
- sqlite: embedded SQL for dev and single-node production
- postgres: full PostgreSQL for production deployments

Key features:
- Generic Model[T] with Create/Read/Update/Delete/List/Count
- Query builder: Where(), WhereOp(), OrderAsc/Desc(), Limit(), Offset()
- Struct tags: model:"key" for primary key, model:"index" for indexes
- Auto table creation from struct schema
- 19 tests passing across memory and sqlite backends

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* feat: add model code generation to protoc-gen-micro

Extend the micro plugin to generate model structs from proto messages
annotated with // @model. Generated alongside client/server code in
the same .pb.micro.go file.

For a proto message like:
  // @model
  message User { string id = 1; string name = 2; }

Generates:
- UserModel struct with model:"key" and json tags
- NewUserModel(db) factory returning *model.Model[UserModel]
- UserModelFromProto(*User) *UserModel converter
- (*UserModel).ToProto() *User converter

Supports @model(table=custom_table, key=custom_field) options.
Adds GetComments() to generator for plugin comment inspection.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* feat: add Model() to Service interface for Client/Server/Model trifecta

Every service now exposes Client(), Server(), and Model() — call services,
handle requests, and save/query data from the same interface. Includes
README docs, blog post, and a full model guide on the docs site.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* feat: add Helm chart for MCP gateway Kubernetes deployment

Adds official Helm chart at deploy/helm/mcp-gateway/ with:
- Deployment, Service, ServiceAccount templates
- HPA for auto-scaling based on CPU/memory
- Ingress with TLS support
- Configurable registry (consul, etcd, mdns), rate limiting,
  JWT auth, audit logging, and per-tool scopes
- Security context (non-root, read-only rootfs, drop all caps)
- NOTES.txt with post-install connection instructions

Updates roadmap and status docs to reflect Helm Charts as delivered.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-03-05 07:28:30 +00:00
Asim Aslam 76bfeae456 Claude/update docs roadmap f zd2 j (#2880)
* docs: update all four documentation guides and mark Q2 complete

- ai-native-services: add WithMCP one-liner, standalone gateway,
  WebSocket client example, and OpenTelemetry observability section
- mcp-security: add OTel distributed tracing, WebSocket authentication
  (connection-level and per-message), DeniedReason audit field
- tool-descriptions: add manual overrides with WithEndpointDocs and
  export formats section
- agent-patterns: add LangChain/LlamaIndex SDK pattern and standalone
  gateway production pattern with Docker example
- Update roadmap: mark Q2 documentation as complete, Q2 at 100%
- Update status: reflect all recent completions, shift priorities

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* feat: add agent demo example and blog post

Add examples/agent-demo with a multi-service project management app
(projects, tasks, team) that demonstrates AI agents interacting with
Go Micro services through MCP. Includes seed data and example prompts.

Add blog post 4 "Agents Meet Microservices: A Hands-On Demo" walking
through the example code and showing cross-service agent workflows.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* feat: enable multiple services in a single binary

Remove global state mutations from service and cmd option functions so
that configuring one service no longer overwrites another's settings.

Key changes:
- service/options.go: remove all DefaultXxx global writes from option
  functions; newOptions() now creates fresh Server, Client, Store, and
  Cache per service while sharing Registry, Broker, and Transport
- cmd/cmd.go: newCmd() uses local copies instead of pointers to package
  globals; Before() no longer mutates DefaultXxx vars
- cmd/options.go: remove global mutations from all option functions
- service/service.go: export ServiceImpl type for cross-package use
- service/group.go: new Group type for multi-service lifecycle
- micro.go: add Start/Stop to Service interface, expose Group and
  NewGroup convenience function
- examples/multi-service: working example with two services

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* docs: highlight multi-service binary support

Add multi-service section to README with code example, update features
list, add to examples index, and note in status summary.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* feat: unify service API and clean up developer experience

- Unified service creation: micro.New("name", opts...) as canonical API
- Clean handler registration: service.Handle(handler, opts...) accepts
  server.HandlerOption args directly, no need to reach through Server()
- Unexported serviceImpl: users interact through Service interface only
- Service groups use Service interface (not concrete type)
- Fixed Stop() to properly propagate BeforeStop/AfterStop errors
- Fixed store init: error-level log instead of fatal on init failure
- Updated all examples to use consistent patterns
- Updated README, getting-started, MCP docs, and guides
- Added blog post about the DX cleanup

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* fix: add blog post 5 to blog index

Blog post 5 (Developer Experience Cleanup) existed as a file but was
missing from the blog index page.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* feat: make micro new generate MCP-enabled services by default

- main.go template includes mcp.WithMCP(":3001") by default
- Handler template has agent-friendly doc comments with @example tags
- Proto template has descriptive field comments
- README includes MCP usage, Claude Code config, and tool description tips
- Makefile adds mcp-tools, mcp-test, mcp-serve targets
- go.mod updated to Go 1.22
- Added --no-mcp flag to opt out of MCP integration
- Post-create output shows MCP endpoint URLs

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* docs: add MCP migration guide and troubleshooting guide

- Migration guide: 3 approaches to add MCP to existing services
  (WithMCP one-liner, standalone gateway, CLI)
- Troubleshooting guide: common issues with agents, WebSocket,
  Claude Code, auth, rate limiting, and performance

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* refactor: rename model/ package to ai/ for AI model providers

The model/ package name conflicted with the conventional use of "model"
for data models. Renamed to ai/ which better describes the package's
purpose (AI provider abstraction for Anthropic, OpenAI, etc.) and frees
up model/ for future data model layer use.

- Rename model/ → ai/ with package name change
- Update all Go imports from go-micro.dev/v5/model to go-micro.dev/v5/ai
- Update cmd/micro/server/server.go references (model.X → ai.X)
- Update all documentation and roadmap references
- All tests pass, CLI builds successfully

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* feat: add model package for typed data access with CRUD and queries

New model/ package provides a typed data model layer using Go generics.
Supports structured CRUD operations, WHERE filters, ordering, pagination,
and automatic schema creation from struct tags.

Three backends:
- memory: in-memory for development and testing
- sqlite: embedded SQL for dev and single-node production
- postgres: full PostgreSQL for production deployments

Key features:
- Generic Model[T] with Create/Read/Update/Delete/List/Count
- Query builder: Where(), WhereOp(), OrderAsc/Desc(), Limit(), Offset()
- Struct tags: model:"key" for primary key, model:"index" for indexes
- Auto table creation from struct schema
- 19 tests passing across memory and sqlite backends

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* feat: add model code generation to protoc-gen-micro

Extend the micro plugin to generate model structs from proto messages
annotated with // @model. Generated alongside client/server code in
the same .pb.micro.go file.

For a proto message like:
  // @model
  message User { string id = 1; string name = 2; }

Generates:
- UserModel struct with model:"key" and json tags
- NewUserModel(db) factory returning *model.Model[UserModel]
- UserModelFromProto(*User) *UserModel converter
- (*UserModel).ToProto() *User converter

Supports @model(table=custom_table, key=custom_field) options.
Adds GetComments() to generator for plugin comment inspection.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* feat: add Model() to Service interface for Client/Server/Model trifecta

Every service now exposes Client(), Server(), and Model() — call services,
handle requests, and save/query data from the same interface. Includes
README docs, blog post, and a full model guide on the docs site.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-03-04 13:13:34 +00:00
Asim Aslam f07a49e0d9 docs: add CHANGELOG.md with structured release history (#2878)
Keep a Changelog format covering 2026.01 through current unreleased
work. Includes all MCP gateway features, CLI commands, agent SDKs,
developer experience improvements, and documentation additions.

This replaces ad-hoc blog posts as the canonical "what changed" reference.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

Co-authored-by: Claude <noreply@anthropic.com>
2026-03-04 12:05:06 +00:00
Asim Aslam 6247b1d065 chore: move internal status docs out of top level (#2879)
Move Claude-context working documents to internal/docs/:
- CURRENT_STATUS_SUMMARY.md
- PROJECT_STATUS_2026.md
- ROADMAP_2026.md
- IMPLEMENTATION_SUMMARY.md

These are session-tracking docs, not useful to most contributors.
Top level now only has standard files: README, CHANGELOG,
CONTRIBUTING, SECURITY, CLAUDE.md, and ROADMAP.

Updated all cross-references in CLAUDE.md, ROADMAP.md, and
website docs.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

Co-authored-by: Claude <noreply@anthropic.com>
2026-03-04 11:59:52 +00:00
Asim Aslam c800dd3729 feat: add deployment example, workflow example, and MCP benchmarks (#2877)
Docker Compose deployment example (examples/deployment/):
- docker-compose.yml with Consul, MCP gateway, Jaeger tracing
- Dockerfile and Dockerfile.gateway for multi-stage builds
- README with architecture diagram and customization guide

Cross-service workflow example (examples/mcp/workflow/):
- Inventory, Orders, Notifications services
- Shows agents orchestrating multi-step workflows from natural language
- Stock check → reserve → order → notify in a single agent conversation

MCP gateway benchmark suite (gateway/mcp/benchmark_test.go):
- ListTools: ~20μs (10 tools), ~48μs (100 tools)
- Tool lookup: ~19ns (zero-alloc, scales to 500+ tools)
- Auth inspect: ~7ns, scope check: ~16ns
- Rate limiter: ~111ns per check
- JSON encode/decode: ~1.5-2μs per tool

Updated examples README with new examples index.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

Co-authored-by: Claude <noreply@anthropic.com>
2026-03-04 11:40:10 +00:00
Asim Aslam 870b540922 Claude/mcp dx improvements f zd2 j (#2876)
* docs: add MCP migration guide and troubleshooting guide

- Migration guide: 3 approaches to add MCP to existing services
  (WithMCP one-liner, standalone gateway, CLI)
- Troubleshooting guide: common issues with agents, WebSocket,
  Claude Code, auth, rate limiting, and performance

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* feat: add CRUD example, error handling guide, and status updates

- CRUD contact book example (examples/mcp/crud/) with 6 operations,
  rich doc comments, @example tags, and description struct tags
- Error handling guide for writing agent-friendly error responses
  using typed errors, actionable messages, and idempotency patterns
- Updated MCP examples index, CLAUDE.md, and status summary

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-03-04 11:32:27 +00:00
Asim Aslam fad2fd7af4 Claude/update docs roadmap f zd2 j (#2875)
* docs: update all four documentation guides and mark Q2 complete

- ai-native-services: add WithMCP one-liner, standalone gateway,
  WebSocket client example, and OpenTelemetry observability section
- mcp-security: add OTel distributed tracing, WebSocket authentication
  (connection-level and per-message), DeniedReason audit field
- tool-descriptions: add manual overrides with WithEndpointDocs and
  export formats section
- agent-patterns: add LangChain/LlamaIndex SDK pattern and standalone
  gateway production pattern with Docker example
- Update roadmap: mark Q2 documentation as complete, Q2 at 100%
- Update status: reflect all recent completions, shift priorities

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* feat: add agent demo example and blog post

Add examples/agent-demo with a multi-service project management app
(projects, tasks, team) that demonstrates AI agents interacting with
Go Micro services through MCP. Includes seed data and example prompts.

Add blog post 4 "Agents Meet Microservices: A Hands-On Demo" walking
through the example code and showing cross-service agent workflows.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* feat: enable multiple services in a single binary

Remove global state mutations from service and cmd option functions so
that configuring one service no longer overwrites another's settings.

Key changes:
- service/options.go: remove all DefaultXxx global writes from option
  functions; newOptions() now creates fresh Server, Client, Store, and
  Cache per service while sharing Registry, Broker, and Transport
- cmd/cmd.go: newCmd() uses local copies instead of pointers to package
  globals; Before() no longer mutates DefaultXxx vars
- cmd/options.go: remove global mutations from all option functions
- service/service.go: export ServiceImpl type for cross-package use
- service/group.go: new Group type for multi-service lifecycle
- micro.go: add Start/Stop to Service interface, expose Group and
  NewGroup convenience function
- examples/multi-service: working example with two services

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* docs: highlight multi-service binary support

Add multi-service section to README with code example, update features
list, add to examples index, and note in status summary.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* feat: unify service API and clean up developer experience

- Unified service creation: micro.New("name", opts...) as canonical API
- Clean handler registration: service.Handle(handler, opts...) accepts
  server.HandlerOption args directly, no need to reach through Server()
- Unexported serviceImpl: users interact through Service interface only
- Service groups use Service interface (not concrete type)
- Fixed Stop() to properly propagate BeforeStop/AfterStop errors
- Fixed store init: error-level log instead of fatal on init failure
- Updated all examples to use consistent patterns
- Updated README, getting-started, MCP docs, and guides
- Added blog post about the DX cleanup

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* fix: add blog post 5 to blog index

Blog post 5 (Developer Experience Cleanup) existed as a file but was
missing from the blog index page.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* feat: make micro new generate MCP-enabled services by default

- main.go template includes mcp.WithMCP(":3001") by default
- Handler template has agent-friendly doc comments with @example tags
- Proto template has descriptive field comments
- README includes MCP usage, Claude Code config, and tool description tips
- Makefile adds mcp-tools, mcp-test, mcp-serve targets
- go.mod updated to Go 1.22
- Added --no-mcp flag to opt out of MCP integration
- Post-create output shows MCP endpoint URLs

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-03-04 11:24:33 +00:00
Asim Aslam 19892f2c67 Claude/update docs roadmap f zd2 j (#2874)
* docs: update all four documentation guides and mark Q2 complete

- ai-native-services: add WithMCP one-liner, standalone gateway,
  WebSocket client example, and OpenTelemetry observability section
- mcp-security: add OTel distributed tracing, WebSocket authentication
  (connection-level and per-message), DeniedReason audit field
- tool-descriptions: add manual overrides with WithEndpointDocs and
  export formats section
- agent-patterns: add LangChain/LlamaIndex SDK pattern and standalone
  gateway production pattern with Docker example
- Update roadmap: mark Q2 documentation as complete, Q2 at 100%
- Update status: reflect all recent completions, shift priorities

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* feat: add agent demo example and blog post

Add examples/agent-demo with a multi-service project management app
(projects, tasks, team) that demonstrates AI agents interacting with
Go Micro services through MCP. Includes seed data and example prompts.

Add blog post 4 "Agents Meet Microservices: A Hands-On Demo" walking
through the example code and showing cross-service agent workflows.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* feat: enable multiple services in a single binary

Remove global state mutations from service and cmd option functions so
that configuring one service no longer overwrites another's settings.

Key changes:
- service/options.go: remove all DefaultXxx global writes from option
  functions; newOptions() now creates fresh Server, Client, Store, and
  Cache per service while sharing Registry, Broker, and Transport
- cmd/cmd.go: newCmd() uses local copies instead of pointers to package
  globals; Before() no longer mutates DefaultXxx vars
- cmd/options.go: remove global mutations from all option functions
- service/service.go: export ServiceImpl type for cross-package use
- service/group.go: new Group type for multi-service lifecycle
- micro.go: add Start/Stop to Service interface, expose Group and
  NewGroup convenience function
- examples/multi-service: working example with two services

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* docs: highlight multi-service binary support

Add multi-service section to README with code example, update features
list, add to examples index, and note in status summary.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* feat: unify service API and clean up developer experience

- Unified service creation: micro.New("name", opts...) as canonical API
- Clean handler registration: service.Handle(handler, opts...) accepts
  server.HandlerOption args directly, no need to reach through Server()
- Unexported serviceImpl: users interact through Service interface only
- Service groups use Service interface (not concrete type)
- Fixed Stop() to properly propagate BeforeStop/AfterStop errors
- Fixed store init: error-level log instead of fatal on init failure
- Updated all examples to use consistent patterns
- Updated README, getting-started, MCP docs, and guides
- Added blog post about the DX cleanup

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* fix: add blog post 5 to blog index

Blog post 5 (Developer Experience Cleanup) existed as a file but was
missing from the blog index page.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-03-04 11:19:43 +00:00
Asim Aslam d2036b880d Claude/update docs roadmap f zd2 j (#2873)
* docs: update all four documentation guides and mark Q2 complete

- ai-native-services: add WithMCP one-liner, standalone gateway,
  WebSocket client example, and OpenTelemetry observability section
- mcp-security: add OTel distributed tracing, WebSocket authentication
  (connection-level and per-message), DeniedReason audit field
- tool-descriptions: add manual overrides with WithEndpointDocs and
  export formats section
- agent-patterns: add LangChain/LlamaIndex SDK pattern and standalone
  gateway production pattern with Docker example
- Update roadmap: mark Q2 documentation as complete, Q2 at 100%
- Update status: reflect all recent completions, shift priorities

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* feat: add agent demo example and blog post

Add examples/agent-demo with a multi-service project management app
(projects, tasks, team) that demonstrates AI agents interacting with
Go Micro services through MCP. Includes seed data and example prompts.

Add blog post 4 "Agents Meet Microservices: A Hands-On Demo" walking
through the example code and showing cross-service agent workflows.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* feat: enable multiple services in a single binary

Remove global state mutations from service and cmd option functions so
that configuring one service no longer overwrites another's settings.

Key changes:
- service/options.go: remove all DefaultXxx global writes from option
  functions; newOptions() now creates fresh Server, Client, Store, and
  Cache per service while sharing Registry, Broker, and Transport
- cmd/cmd.go: newCmd() uses local copies instead of pointers to package
  globals; Before() no longer mutates DefaultXxx vars
- cmd/options.go: remove global mutations from all option functions
- service/service.go: export ServiceImpl type for cross-package use
- service/group.go: new Group type for multi-service lifecycle
- micro.go: add Start/Stop to Service interface, expose Group and
  NewGroup convenience function
- examples/multi-service: working example with two services

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* docs: highlight multi-service binary support

Add multi-service section to README with code example, update features
list, add to examples index, and note in status summary.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* feat: unify service API and clean up developer experience

- Unified service creation: micro.New("name", opts...) as canonical API
- Clean handler registration: service.Handle(handler, opts...) accepts
  server.HandlerOption args directly, no need to reach through Server()
- Unexported serviceImpl: users interact through Service interface only
- Service groups use Service interface (not concrete type)
- Fixed Stop() to properly propagate BeforeStop/AfterStop errors
- Fixed store init: error-level log instead of fatal on init failure
- Updated all examples to use consistent patterns
- Updated README, getting-started, MCP docs, and guides
- Added blog post about the DX cleanup

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-03-04 11:13:27 +00:00
Asim Aslam cad0ff1e49 Claude/update docs roadmap f zd2 j (#2872)
* docs: update all four documentation guides and mark Q2 complete

- ai-native-services: add WithMCP one-liner, standalone gateway,
  WebSocket client example, and OpenTelemetry observability section
- mcp-security: add OTel distributed tracing, WebSocket authentication
  (connection-level and per-message), DeniedReason audit field
- tool-descriptions: add manual overrides with WithEndpointDocs and
  export formats section
- agent-patterns: add LangChain/LlamaIndex SDK pattern and standalone
  gateway production pattern with Docker example
- Update roadmap: mark Q2 documentation as complete, Q2 at 100%
- Update status: reflect all recent completions, shift priorities

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* feat: add agent demo example and blog post

Add examples/agent-demo with a multi-service project management app
(projects, tasks, team) that demonstrates AI agents interacting with
Go Micro services through MCP. Includes seed data and example prompts.

Add blog post 4 "Agents Meet Microservices: A Hands-On Demo" walking
through the example code and showing cross-service agent workflows.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* feat: enable multiple services in a single binary

Remove global state mutations from service and cmd option functions so
that configuring one service no longer overwrites another's settings.

Key changes:
- service/options.go: remove all DefaultXxx global writes from option
  functions; newOptions() now creates fresh Server, Client, Store, and
  Cache per service while sharing Registry, Broker, and Transport
- cmd/cmd.go: newCmd() uses local copies instead of pointers to package
  globals; Before() no longer mutates DefaultXxx vars
- cmd/options.go: remove global mutations from all option functions
- service/service.go: export ServiceImpl type for cross-package use
- service/group.go: new Group type for multi-service lifecycle
- micro.go: add Start/Stop to Service interface, expose Group and
  NewGroup convenience function
- examples/multi-service: working example with two services

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* docs: highlight multi-service binary support

Add multi-service section to README with code example, update features
list, add to examples index, and note in status summary.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-03-04 10:50:00 +00:00
Asim Aslam ffe43e0e6d Claude/update docs roadmap f zd2 j (#2871)
* docs: update all four documentation guides and mark Q2 complete

- ai-native-services: add WithMCP one-liner, standalone gateway,
  WebSocket client example, and OpenTelemetry observability section
- mcp-security: add OTel distributed tracing, WebSocket authentication
  (connection-level and per-message), DeniedReason audit field
- tool-descriptions: add manual overrides with WithEndpointDocs and
  export formats section
- agent-patterns: add LangChain/LlamaIndex SDK pattern and standalone
  gateway production pattern with Docker example
- Update roadmap: mark Q2 documentation as complete, Q2 at 100%
- Update status: reflect all recent completions, shift priorities

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* feat: add agent demo example and blog post

Add examples/agent-demo with a multi-service project management app
(projects, tasks, team) that demonstrates AI agents interacting with
Go Micro services through MCP. Includes seed data and example prompts.

Add blog post 4 "Agents Meet Microservices: A Hands-On Demo" walking
through the example code and showing cross-service agent workflows.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-03-04 10:16:17 +00:00
Asim Aslam ec9473f86f Update sponsorship information in README.md 2026-03-04 10:10:46 +00:00
Asim Aslam 4c673f61b1 Fix formatting in README.md links section 2026-03-04 10:10:18 +00:00
Asim Aslam bed94bfa95 Update sponsorship information in README
Updated sponsorship link and removed sponsor text.
2026-03-04 10:10:04 +00:00
Asim Aslam d02ff2ecfa feat: add standalone MCP gateway binary (#2870)
Add cmd/micro-mcp-gateway for production MCP gateway deployment
independent of micro run. Supports:

- Registry selection: mdns, consul, etcd (via --registry flag)
- Rate limiting per tool (--rate-limit, --rate-burst)
- JWT authentication (--auth)
- Per-tool scope requirements (--scope tool=scope1,scope2)
- Audit logging to stdout (--audit)
- Environment variable configuration for all flags
- Dockerfile for containerized deployment

Usage:
  micro-mcp-gateway --address :3000 --registry consul --registry-address consul:8500

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

Co-authored-by: Claude <noreply@anthropic.com>
2026-03-04 10:08:09 +00:00
Asim Aslam 6d9645adce feat: polish agent playground UI (#2869)
Redesign the /agent playground with improved UX:
- Chat-focused layout with full-height message area and sticky input
- Collapsible tool call cards showing name, input, result, and timing
- Thinking indicator while waiting for agent response
- Settings panel collapsed by default (auto-opens if no API key)
- Empty state with available tools preview
- Clear chat button
- Better visual hierarchy with distinct message styles

Co-authored-by: Claude <noreply@anthropic.com>
2026-03-04 09:38:04 +00:00
Asim Aslam beeaad748e Claude/update docs roadmap f zd2 j (#2868)
* feat: add LlamaIndex SDK for Go Micro services

Add LlamaIndex integration package that enables LlamaIndex agents to
discover and call Go Micro microservices through the MCP gateway.
Follows the same pattern as the existing LangChain SDK.

- GoMicroToolkit with from_gateway() factory and tool filtering
- FunctionTool integration via llama_index.core.tools
- Auth support, error handling, and retry configuration
- Examples for basic agent and RAG + microservices workflows
- Unit tests with mocked gateway responses

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* docs: update status for OTel, WebSocket, and LlamaIndex SDK completion

Reflect recently completed work in roadmap and status documents:
- Q2 progress: 85% -> 95% (WebSocket, LlamaIndex SDK done)
- Q3 progress: 40% -> 50% (OpenTelemetry integration done)
- Transports: 2 -> 3 (added WebSocket)
- Agent SDKs: 1 -> 2 (added LlamaIndex)
- Test coverage: 568 -> 1,000+ lines

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* feat: add WithMCP convenience option, improve startup banner, and blog post

- Add mcp.WithMCP(":3000") service option for one-line MCP setup
- Improve `micro run` startup banner to show Agent playground, MCP
  tools, and WebSocket endpoints prominently
- Add blog post: "Building the AI-Native Future of Go Micro with Claude"
  covering WebSocket transport, OTel integration, LlamaIndex SDK, and
  Anthropic's Claude Max sponsorship
- Update blog index and navigation links

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-03-04 09:28:07 +00:00
Asim Aslam 076b7c37be feat: add WebSocket transport for MCP gateway (#2867)
Add bidirectional WebSocket transport at /mcp/ws using JSON-RPC 2.0
protocol (same as stdio). This enables persistent connections for
real-time AI agents that need streaming tool interactions.

New files:
- gateway/mcp/websocket.go: WebSocketTransport with connection-level
  auth, per-message auth fallback, write serialization, OTel tracing
- gateway/mcp/websocket_test.go: 14 tests covering initialize,
  tools/list, tool calls, auth (header + param), scopes, rate
  limiting, audit, concurrent requests, multiple connections,
  error handling, and connection persistence

Changes:
- gateway/mcp/mcp.go: Register /mcp/ws handler in serveHTTP
- go.mod: Added github.com/gorilla/websocket v1.5.3

Auth supports two modes:
- Connection-level: Bearer token in WebSocket upgrade request headers
- Per-message: _token field in JSON-RPC params (same as stdio)

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

Co-authored-by: Claude <noreply@anthropic.com>
2026-03-04 08:26:09 +00:00
Asim Aslam ab6f027741 Claude/update docs roadmap f zd2 j (#2866)
* Update docs and roadmap to March 2026 with focus priorities

- ROADMAP.md: Updated from Nov 2025 to reflect Q1 completions and current state
- ROADMAP_2026.md: Updated status to March 2026, added model package as delivered
- CURRENT_STATUS_SUMMARY.md: Rewrote with March 2026 status and clear next priorities
- PROJECT_STATUS_2026.md: Added model package section, updated recommendations
- Website roadmap: Updated Q3 security status and timestamps

Key focus areas identified: documentation guides, multi-protocol MCP,
LlamaIndex SDK, and OpenTelemetry integration.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* Add CLAUDE.md and four documentation guides to fill doc gaps

- CLAUDE.md: Project guide with structure, build commands, and priorities
- ai-native-services.md: End-to-end tutorial building an MCP-enabled task service
- mcp-security.md: Production security guide (auth, scopes, rate limiting, audit)
- tool-descriptions.md: Best practices for writing Go comments that help agents
- agent-patterns.md: Six integration patterns from single-agent to event-driven
- Updated docs index with new "AI & Agents" section linking all four guides

These were the highest priority gaps identified in the roadmap analysis:
the framework has solid features that were under-documented.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* feat: add OpenTelemetry tracing to MCP gateway

Integrate OpenTelemetry spans into the MCP gateway for both HTTP and
stdio transports. Each tool call now creates a server span with rich
attributes (tool name, account ID, auth outcome, transport type).
Trace context is propagated to downstream RPC calls via metadata,
enabling end-to-end distributed tracing through Jaeger, Grafana, etc.

New files:
- gateway/mcp/otel.go: Span creation, attribute constants, metadata carrier
- gateway/mcp/otel_test.go: 8 tests covering span creation, auth denied/allowed,
  rate limiting, trace propagation, noop provider, and missing token

Changes:
- Options.TraceProvider: Optional trace.TracerProvider field
- handleCallTool (HTTP): Creates OTel spans with auth/rate-limit attributes
- handleToolsCall (stdio): Same instrumentation for stdio transport
- go.mod: Added go.opentelemetry.io/otel/sdk v1.35.0 (test dependency)

The existing MCP trace ID (UUID) is preserved for backward compatibility
and recorded as a span attribute alongside the W3C trace context.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-03-04 08:16:06 +00:00
Asim Aslam 14ec9b955f Update status docs: March 2026 progress and roadmap refinement (#2865)
* Update docs and roadmap to March 2026 with focus priorities

- ROADMAP.md: Updated from Nov 2025 to reflect Q1 completions and current state
- ROADMAP_2026.md: Updated status to March 2026, added model package as delivered
- CURRENT_STATUS_SUMMARY.md: Rewrote with March 2026 status and clear next priorities
- PROJECT_STATUS_2026.md: Added model package section, updated recommendations
- Website roadmap: Updated Q3 security status and timestamps

Key focus areas identified: documentation guides, multi-protocol MCP,
LlamaIndex SDK, and OpenTelemetry integration.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

* Add CLAUDE.md and four documentation guides to fill doc gaps

- CLAUDE.md: Project guide with structure, build commands, and priorities
- ai-native-services.md: End-to-end tutorial building an MCP-enabled task service
- mcp-security.md: Production security guide (auth, scopes, rate limiting, audit)
- tool-descriptions.md: Best practices for writing Go comments that help agents
- agent-patterns.md: Six integration patterns from single-agent to event-driven
- Updated docs index with new "AI & Agents" section linking all four guides

These were the highest priority gaps identified in the roadmap analysis:
the framework has solid features that were under-documented.

https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-03-04 07:33:19 +00:00
Asim Aslam a789c9e94b Update Go Micro version in README 2026-02-21 05:22:24 +00:00
Copilot e110ccb5ff Refactor model interface to high-level idiomatic Go API (#2863)
* Initial plan

* Add model package with provider abstraction interface

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Add unit tests for model providers

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Refactor server to use model package abstraction

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Use strings.Contains instead of custom substring search

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Add comprehensive documentation for model package

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Refactor model interface to be more idiomatic Go

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Simplify server code to use new high-level Generate API

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Update documentation for new high-level model API

Co-authored-by: asim <17530+asim@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: asim <17530+asim@users.noreply.github.com>
2026-02-14 18:15:07 +00:00
Copilot e3337efd81 Update 2026 roadmap to reflect Q2 completions (85% → docs only) (#2862)
* Initial plan

* Update 2026 roadmap to reflect Q2 completions (CLI exports and LangChain SDK)

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Update PROJECT_STATUS and roadmap docs to reflect Q2 85% completion

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Fix CLI integration status table to show all commands as complete

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Address code review feedback: fix duplicates and add missing metrics

Co-authored-by: asim <17530+asim@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: asim <17530+asim@users.noreply.github.com>
2026-02-13 17:36:25 +00:00
Copilot 13d1116dee Implement Q2 2026 roadmap: MCP CLI export commands and LangChain SDK (#2861)
* Initial plan

* Implement micro mcp docs and export commands (Q2 2026 roadmap)

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Add comprehensive CLI examples and documentation for new MCP commands

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Add LangChain Python SDK for Go Micro (Q2 2026 roadmap)

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Update PROJECT_STATUS to reflect LangChain SDK completion

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Add implementation summary for Roadmap 2026 session

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: asim <17530+asim@users.noreply.github.com>
2026-02-13 14:39:48 +00:00
Copilot 1db7903010 [WIP] Implement missing features from documentation (#2859)
* Initial plan

* Add --header and --metadata flags to micro call command

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Apply code formatting with gofmt

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Add clarifying comments for dual metadata handling paths

Co-authored-by: asim <17530+asim@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: asim <17530+asim@users.noreply.github.com>
2026-02-13 14:20:34 +00:00
Copilot 5e1042e5ae Implement micro mcp test command (#2857)
* Initial plan

* Implement micro mcp test command

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Add test for parseTool function

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Address code review feedback - simplify parseTool

Co-authored-by: asim <17530+asim@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: asim <17530+asim@users.noreply.github.com>
2026-02-13 14:19:41 +00:00
Copilot 0f6453488e Implement missing --service flag for micro deploy command (#2858)
* Initial plan

* Implement --service flag for micro deploy command

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Address code review feedback - optimize validation and add comments

Co-authored-by: asim <17530+asim@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: asim <17530+asim@users.noreply.github.com>
2026-02-13 14:19:03 +00:00
Copilot abc7e3e052 Add MCP tools registry and agent playground to README and docs navigation (#2856)
* Initial plan

* Add MCP tools registry and agent playground to README and docs navigation

Co-authored-by: asim <17530+asim@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: asim <17530+asim@users.noreply.github.com>
2026-02-12 17:56:02 +00:00
Asim Aslam 759ad1de50 x 2026-02-12 10:59:51 +00:00
Asim Aslam 92b9f84d79 x 2026-02-12 10:55:13 +00:00
Asim Aslam 3a605c461d x 2026-02-12 10:45:13 +00:00
Asim Aslam de615e0573 x 2026-02-12 10:34:53 +00:00
Asim Aslam 9d9968d66b scopes 2026-02-12 10:33:15 +00:00
Asim Aslam 9c3e883dff add safe names for tools 2026-02-12 10:15:57 +00:00
Asim Aslam 33e828acdd x 2026-02-12 10:11:58 +00:00
Asim Aslam a2442fa72e x 2026-02-12 10:07:20 +00:00
Asim Aslam c9a3584656 update docs 2026-02-12 10:01:26 +00:00
Asim Aslam 22fa349d5f . 2026-02-12 09:56:19 +00:00
Asim Aslam 2c7f612178 . 2026-02-12 09:55:18 +00:00
Copilot 06608d354e Add Anthropic model support to the agent (#2855)
* Initial plan

* Add MCP Playground page to web UI with tool discovery and calling

- Add playground.html template with chat-style agent prompt interface
- Add /playground route handler in server
- Add /api/mcp/tools endpoint to list available MCP tools
- Add /api/mcp/call endpoint to invoke MCP tools via RPC
- Add Playground link to sidebar navigation
- Playground auto-discovers services from registry and renders them as
  callable tools with input forms and activity logging

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Add playground.html template and fix .gitignore micro pattern

Fix .gitignore pattern 'micro' -> '/micro' to only ignore root-level
binary, not paths containing 'micro' as a component.

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Address code review: use crypto/rand for trace IDs, fix var redecl, remove dup comment

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Rename Playground to Agent, fix styling, add LLM-powered prompt

- Rename /playground to /agent, move Agent link to top of sidebar menu
- Fix template styling: use existing form/input/button CSS from styles.css
  instead of inline styles and form-plain class
- Add /api/agent/settings GET/POST endpoints for model API key, model
  name, and base URL configuration (stored in server store)
- Add /api/agent/prompt POST endpoint that sends user prompt to
  OpenAI-compatible LLM API with tool definitions from registry,
  executes any tool calls via RPC, and returns results with a
  follow-up LLM summary
- Show available tools in a table using existing table styles
- Prompt section is placed above settings for primary workflow

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Address code review: handle unmarshal errors, extract system prompt, improve param descriptions

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Add Anthropic model support to the agent

Support both OpenAI and Anthropic APIs in the agent prompt handler:
- Add provider selector (OpenAI/Anthropic) to settings UI and backend
- Auto-detect provider from base URL when not explicitly set
- Anthropic: use /v1/messages endpoint, x-api-key header, input_schema
  format for tools, content blocks for responses, tool_use/tool_result
  message format for follow-ups
- OpenAI: unchanged /v1/chat/completions with Bearer auth
- Default models: gpt-4o (OpenAI), claude-sonnet-4-20250514 (Anthropic)
- Provider-specific defaults for base URLs

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Remove duplicate Anthropic follow-up message construction

Co-authored-by: asim <17530+asim@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: asim <17530+asim@users.noreply.github.com>
2026-02-12 09:32:27 +00:00
Copilot d8269fbdfb Document MCP integration and tool scopes implementation status (#2852)
* Initial plan

* Add comprehensive project status analysis and update roadmap

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Add executive summary of project status

Co-authored-by: asim <17530+asim@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: asim <17530+asim@users.noreply.github.com>
2026-02-12 07:24:31 +00:00
Copilot ac47a4650a MCP gateway: add per-tool scopes, tracing, rate limiting, and audit logging (#2850)
* Initial plan

* Add MCP per-tool scopes, tracing, rate limiting, and audit logging

- Add Scopes field to Tool struct for per-tool scope requirements
- Add Auth (auth.Auth) integration to Options for token inspection
- Add trace ID generation (UUID) propagated via metadata to downstream RPCs
- Add per-tool rate limiting with configurable requests/sec and burst
- Add AuditFunc callback for immutable tool-call audit records
- Extract tool scopes from registry endpoint metadata ("scopes" key)
- Update both HTTP and stdio transports with auth/trace/rate/audit
- Add comprehensive tests for all new functionality

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Revert unrelated example go.mod changes

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Remove auto-generated example go.sum files

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Add WithEndpointScopes helper, gateway-level ToolScopes, and documentation

- Add server.WithEndpointScopes() for declaring per-endpoint auth scopes at
  handler registration time
- Add mcp.Options.ToolScopes for gateway-level scope overrides without
  changing individual services
- Update documented example to show WithEndpointScopes usage
- Update examples/mcp/README.md with scopes, tracing, and rate-limiting docs
- Update gateway/mcp/DOCUMENTATION.md with scopes section and FAQ
- Add tests for both new features

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Fix ToolScopes doc comment: clarify override (not merge) semantics

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Revert unrelated example go.mod/go.sum changes

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Rename ToolScopes to Scopes in MCP Options

The field name "Scopes" is more universal and consistent with how
auth scopes are used throughout go-micro. Updated all code references,
tests, and documentation.

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* MCP gateway: add per-tool scopes, tracing, rate limiting, and audit logging

Co-authored-by: asim <17530+asim@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: asim <17530+asim@users.noreply.github.com>
2026-02-11 21:01:31 +00:00
asim f1cba0d617 update index 2026-02-11 15:30:35 +00:00
asim c658126b28 update index 2026-02-11 15:28:16 +00:00
asim 0d69e24a24 further mcp integrations 2026-02-11 14:29:26 +00:00
asim fe76f3ddb5 further mcp integrations 2026-02-11 14:12:21 +00:00
asim 3986738e2c stdio MCP transport and gateway refactor
Implement Q2 2026 roadmap items for AI-native microservices:

MCP stdio transport:
- JSON-RPC 2.0 over stdio for Claude Code integration
- Methods: initialize, tools/list, tools/call
- Auto-detection: stdio (no address) vs HTTP/SSE (with address)

micro mcp command:
- 'micro mcp serve' - start MCP server (stdio or HTTP)
- 'micro mcp list' - list available tools
- 'micro mcp test' - test a tool (placeholder)
- Enables Claude Code users to add microservices as tools

Gateway refactor:
- Created gateway/api package (reusable, 150 lines)
- Moved gateway logic from cmd/micro/server/gateway.go
- HandlerRegistrar pattern for flexibility
- cmd/micro/server/gateway.go now compatibility wrapper (72 lines)
- 50% code reduction, better separation of concerns
- Library users can now use gateway in custom apps

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-11 13:38:27 +00:00
asim e58d51c3ef update version in readme 2026-02-11 13:15:16 +00:00
asim bed7c4cc57 fix tests 2026-02-11 12:59:18 +00:00
asim e7335f945a noop auth fixed 2026-02-11 11:46:02 +00:00
asim 46e9940443 new 2026 roadmap 2026-02-11 11:37:14 +00:00
asim c9e582b966 go fmt 2026-02-11 11:25:43 +00:00
asim 7da9e58c81 fully functioning auth 2026-02-11 11:25:36 +00:00
Asim Aslam b1c63fa4ef Add MCP Integration section to README 2026-02-11 11:13:06 +00:00
asim e311586bd2 update mcp doc location 2026-02-11 11:09:04 +00:00
asim bc9d8c9a2b update mcp doc location 2026-02-11 11:03:13 +00:00
asim e2e0a9126f update mcp doc location 2026-02-11 11:00:49 +00:00
asim 4acb55733d update mcp doc location 2026-02-11 10:59:50 +00:00
asim 42efe1862a fix mcp exampl 2026-02-11 10:46:47 +00:00
asim 8d0180aef1 v5.15.0: Unified Gateway Architecture + MCP Support
Major Features:
- Unified gateway architecture (micro run + micro server use same code)
- MCP (Model Context Protocol) integration as library package
- AI-accessible microservices with 3 lines of code

Gateway Unification:
- Created reusable gateway module (cmd/micro/server/gateway.go)
- Updated micro run to use unified gateway (removed duplicate code)
- Conditional authentication (disabled in dev, required in prod)
- Reduced code duplication, simplified maintenance

MCP Integration:
- New library package: gateway/mcp
- Automatic service discovery → MCP tools
- HTTP/SSE transport support (stdio coming soon)
- Works for both library users and CLI users
- CLI flags: --mcp-address for micro run and micro server

Documentation:
- ADR-010: Unified Gateway Architecture
- CLI & Gateway Guide for users
- MCP Gateway README and examples
- Blog post: Making Your Microservices AI-Native with MCP

Breaking Changes: None (fully backward compatible)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-11 10:43:14 +00:00
asim ee76eb6d2c v5.15.0: Unified Gateway Architecture + MCP Support
Major Features:
- Unified gateway architecture (micro run + micro server use same code)
- MCP (Model Context Protocol) integration as library package
- AI-accessible microservices with 3 lines of code

Gateway Unification:
- Created reusable gateway module (cmd/micro/server/gateway.go)
- Updated micro run to use unified gateway (removed duplicate code)
- Conditional authentication (disabled in dev, required in prod)
- Reduced code duplication, simplified maintenance

MCP Integration:
- New library package: gateway/mcp
- Automatic service discovery → MCP tools
- HTTP/SSE transport support (stdio coming soon)
- Works for both library users and CLI users
- CLI flags: --mcp-address for micro run and micro server

Documentation:
- ADR-010: Unified Gateway Architecture
- CLI & Gateway Guide for users
- MCP Gateway README and examples
- Blog post: Making Your Microservices AI-Native with MCP

Breaking Changes: None (fully backward compatible)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-11 10:40:48 +00:00
Copilot 8d7eb01fb3 Add hosting.md documentation for go-micro services (#2848)
* Initial plan

* Add hosting.md documentation for go-micro services hosting options

Co-authored-by: asim <17530+asim@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: asim <17530+asim@users.noreply.github.com>
2026-02-11 10:10:05 +00:00
asim a38d7df106 go fmt 2026-02-04 14:37:40 +00:00
asim f9ba48897a fix build 2026-02-04 14:37:29 +00:00
Asim Aslam 547507b1a2 x 2026-02-04 14:14:41 +00:00
Asim Aslam 3bf02c634c x 2026-02-04 14:14:14 +00:00
Asim Aslam bab115a0bf dev UX optimisations 2026-02-04 14:12:59 +00:00
Asim Aslam 29ea3a21d6 update docs for dev UX 2026-02-04 14:01:16 +00:00
Asim Aslam bce53ce15e move all docs 2026-02-04 13:57:33 +00:00
Asim Aslam b867e490a0 fix docs reference points 2026-02-04 13:55:43 +00:00
Asim Aslam 48da4d3559 Removing genai as not relevant to microservices. 2026-02-04 13:42:59 +00:00
Asim Aslam 0cb85bf103 Add Discord link to README
Added Discord link to the README for community engagement.
2026-02-04 13:25:22 +00:00
Copilot a100a47340 Fix google.protobuf.Any JSON marshaling missing @type field (#2845)
* Initial plan

* Update JSON codec to use modern protojson for proper Any type support

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Add comprehensive tests for google.protobuf.Any JSON marshaling

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Revert codec/proto to old protobuf package for backward compatibility

Co-authored-by: asim <17530+asim@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: asim <17530+asim@users.noreply.github.com>
2026-02-04 09:33:27 +00:00
Copilot 4ba40ea579 Replace custom logger with log/slog (#2844)
* Initial plan

* Replace custom logger with slog implementation

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Fix linting issues in slog implementation

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Address code review feedback: fix locking and use copyFields

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Restore debug/log buffer functionality with slog

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Address code review feedback: extract helper and remove dead code

Co-authored-by: asim <17530+asim@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: asim <17530+asim@users.noreply.github.com>
2026-02-03 15:55:46 +00:00
Copilot 50ce1a5e83 TLS certificate verification: opt-in security to preserve backward compatibility (#2843)
* Initial plan

* Fix insecure TLS configuration - make secure by default

- Changed util/tls/Config() to be secure by default (InsecureSkipVerify=false)
- Added MICRO_TLS_INSECURE=true environment variable for development/testing
- Updated documentation to emphasize security-first approach
- Added comprehensive tests for TLS configuration
- All existing broker tests pass

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Revert to backward-compatible TLS defaults to avoid breaking changes

- Reverted default to InsecureSkipVerify=true for backward compatibility
- Changed environment variable to MICRO_TLS_SECURE=true (opt-in security)
- Added deprecation warning that logs once per process
- Updated tests to reflect backward-compatible behavior
- Added comprehensive migration guide
- No breaking changes - production systems safe to upgrade
- Security improvement is opt-in via environment variable
- Planned breaking change for v6 with proper major version bump

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Add TLS security update documentation

Co-authored-by: asim <17530+asim@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: asim <17530+asim@users.noreply.github.com>
2026-02-03 15:53:03 +00:00
Copilot 3094947953 [WIP] Remove reflect usage and improve performance (#2842)
* Initial plan

* Add comprehensive analysis documents on reflection usage

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Fix performance numbers for consistency

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Add evaluation summary for reflection removal analysis

Co-authored-by: asim <17530+asim@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: asim <17530+asim@users.noreply.github.com>
2026-02-03 15:34:46 +00:00
Copilot 75e32f4d87 Implement NATS connection pooling and fix connection leaks (#2840)
* Initial plan

* Implement NATS connection pool with configuration options

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Implement connection pool for transport/nats

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Fix connection leaks in events/natsjs and config/source/nats

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Fix race condition in connection pool lastUsed field access

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Remove unused maxIdle field from connection pools

Co-authored-by: asim <17530+asim@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: asim <17530+asim@users.noreply.github.com>
2026-02-03 11:43:45 +00:00
Copilot adc90b4d2d Apply rate limiting before singleflight to prevent goroutine blocking on etcd timeout (#2841)
* Initial plan

* Apply rate limiting before singleflight to prevent blocking

- Check rate limiting BEFORE entering singleflight
- If rate-limited AND stale cache exists, return stale cache immediately
- This prevents all goroutines from blocking when etcd is down/slow
- Maintains stampede prevention via singleflight for non-rate-limited requests
- All existing tests pass

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Fix variable shadowing in rate limiting check

- Rename shadowed variables to currentLastRefresh and currentMinimumRetryInterval
- Improves code clarity and prevents potential bugs
- All tests still pass

Co-authored-by: asim <17530+asim@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: asim <17530+asim@users.noreply.github.com>
2026-02-03 11:35:34 +00:00
Copilot 87cf988e03 Fix go install @latest failures by documenting specific version (#2839)
* Initial plan

* Update documentation to use @v5.13.0 instead of @latest for go install commands

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Add explanatory notes about version pinning in documentation

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Add consistent explanatory notes across all documentation files

Co-authored-by: asim <17530+asim@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: asim <17530+asim@users.noreply.github.com>
2026-01-29 10:19:55 +00:00
Asim Aslam 109ff2169a Add blog link to homepage (#2837)
Link to /blog/ from the main navigation, replacing the badge link.

Co-authored-by: Shelley <shelley@exe.dev>
2026-01-27 14:08:32 +00:00
Shelley 82b7fdbec4 Add install.sh to website for curl install
Co-authored-by: Shelley <shelley@exe.dev>
2026-01-27 14:02:38 +00:00
Shelley fea8c911be Fix blog post markdown rendering
Co-authored-by: Shelley <shelley@exe.dev>
2026-01-27 13:54:31 +00:00
Shelley cf9629c41f Add blog section with first post: Introducing micro deploy
- /blog/ - Blog index page
- /blog/1 - First post announcing micro deploy
- /docs/deployment.md - Deployment guide in website docs
- Updated navigation to include Blog link
- New blog layout template

Co-authored-by: Shelley <shelley@exe.dev>
2026-01-27 13:52:09 +00:00
Asim Aslam a5bef7af29 Add systemd-based deployment support (#2836)
* Add systemd-based deployment support

- micro init --server: Initialize server to receive deployments
  - Creates /opt/micro/{bin,data,config} directories
  - Generates systemd template unit (micro@.service)
  - Creates 'micro' system user

- micro deploy: Deploy services via SSH + systemd
  - Builds linux/amd64 binaries automatically
  - Copies via rsync/scp to server
  - Manages services via systemctl
  - Helpful error messages for common issues

- micro status --remote: Check remote service status
- micro logs --remote: Stream remote logs via journalctl
- micro stop --remote: Stop services on remote server

- Config: Added 'deploy' blocks to micro.mu for named targets

The deployment model:
- systemd is the process supervisor (battle-tested)
- SSH is the transport (standard, secure)
- No custom daemons or platforms needed

Co-authored-by: Shelley <shelley@exe.dev>

* Add deployment documentation

- docs/deployment.md: Comprehensive guide for server deployment
- README.md: Updated deployment section with full workflow

Co-authored-by: Shelley <shelley@exe.dev>

* Add deployment section to CLI documentation

Co-authored-by: Shelley <shelley@exe.dev>

* Fix systemd template escaping and rsync permission warnings

- Fix %i escaping in systemd template (was being interpreted by fmt.Sprintf)
- Handle rsync exit code 23/24 gracefully (metadata permission warnings)
- Add --omit-dir-times to rsync to avoid directory timestamp errors

Co-authored-by: Shelley <shelley@exe.dev>

* Add install script for micro CLI

Co-authored-by: Shelley <shelley@exe.dev>

* Fix non-constant format string in deploy error

Co-authored-by: Shelley <shelley@exe.dev>

---------

Co-authored-by: Shelley <shelley@exe.dev>
2026-01-27 13:27:59 +00:00
Asim Aslam 239dbfc27e fix: make build/deploy Go-native, Docker optional (#2835)
micro build:
  - Default: builds Go binaries to ./bin/
  - Cross-compile with --os and --arch
  - Docker is optional via --docker flag

micro deploy:
  - Requires --ssh user@host
  - Copies pre-built binaries (if ./bin/ exists)
  - Or syncs source and builds on remote
  - No Docker dependency

Go binaries are self-contained. No runtime needed.

Co-authored-by: Shelley <shelley@exe.dev>
2026-01-27 12:47:07 +00:00
Asim Aslam de2b3031f3 feat: add micro build and micro deploy commands (#2834)
micro build:
  - Generates Dockerfiles for services (if not present)
  - Builds container images for all services in micro.mu
  - Supports --tag, --registry, --push flags
  - --compose flag generates docker-compose.yml

micro deploy:
  - Default: deploys with docker-compose
  - --ssh user@host: deploys via SSH (rsync + build on remote)
  - --build: rebuild images before deploying

Complete workflow:
  micro run          # Develop locally
  micro build        # Build images
  micro deploy       # Deploy

Or for simple SSH deploys:
  micro deploy --ssh user@host

Co-authored-by: Shelley <shelley@exe.dev>
2026-01-27 12:40:04 +00:00
Asim Aslam 40c3ec0e32 feat: add testing package for in-process service testing (#2833)
Provides a test harness for running micro services in isolation:

  h := testing.NewHarness(t)
  defer h.Stop()

  h.Name("users").Register(new(UsersHandler))
  h.Start()

  var rsp Response
  h.Call("UsersHandler.Create", &req, &rsp)

Features:
- Isolated registry, transport, and broker per harness
- Simple API: Name(), Register(), Start(), Stop()
- Call helpers: Call(), CallContext()
- Assertions: AssertServiceRunning(), AssertCallSucceeds(), AssertCallFails()
- Access to underlying Client(), Server(), Registry()

Note: Due to go-micro's global defaults, each harness tests one service.
For multi-service testing, use integration tests or mocks.

Also fixes README.md example showing conflicting port 8080.

Co-authored-by: Shelley <shelley@exe.dev>
2026-01-27 12:35:05 +00:00
Asim Aslam 139e70e880 feat(run): integrate HTTP gateway with micro run (#2832)
micro run now starts an HTTP gateway alongside your services:

  - Web dashboard at http://localhost:8080
  - API proxy at /api/{service}/{method}
  - Health checks at /health
  - Service listing at /services

The experience is now:
  $ micro new helloworld
  $ cd helloworld
  $ micro run

  Open http://localhost:8080 to see and call your services.

New flags:
  --address :3000    # Custom gateway port
  --no-gateway       # Disable gateway (services only)

Updated documentation to make this the central experience.

Co-authored-by: Shelley <shelley@exe.dev>
2026-01-27 12:22:45 +00:00
Asim Aslam 94e83e57f8 feat: add health check package for K8s-style probes (#2831)
Adds a new health package providing:
- /health endpoint for overall health status
- /health/live for Kubernetes liveness probes
- /health/ready for Kubernetes readiness probes
- Built-in checks: PingCheck, TCPCheck, HTTPCheck, DNSCheck
- Critical vs non-critical checks
- Concurrent check execution
- Configurable timeouts
- Service info metadata

Integrates with micro run's health check waiting when services
specify a port in their micro.mu configuration.

Example usage:

    health.Register("database", health.PingCheck(db.Ping))
    health.Register("redis", health.TCPCheck("localhost:6379", time.Second))
    health.RegisterHandlers(mux)

Co-authored-by: Shelley <shelley@exe.dev>
2026-01-27 12:10:38 +00:00
Asim Aslam 39484560ea docs: add micro run documentation with hot reload and config file guide (#2830)
- Update main README with micro run quick start
- Expand cmd/micro/README.md with configuration options
- Add detailed guide at internal/website/docs/guides/micro-run.md

Documents:
- Hot reload with file watching
- micro.mu DSL configuration
- micro.json alternative
- Dependency ordering
- Environment management
- Graceful shutdown

Co-authored-by: Shelley <shelley@exe.dev>
2026-01-27 12:04:15 +00:00
Asim Aslam 7690c41d5f feat(run): add hot reload, config files, and dependency ordering (#2829)
- Add micro.mu DSL and micro.json config file support
- Implement hot reload with file watching (--no-watch to disable)
- Start services in dependency order (topological sort)
- Environment management (--env flag, MICRO_ENV var)
- Health check waiting before starting dependents
- Graceful shutdown in reverse dependency order

Config file example (micro.mu):

    service users
        path ./users
        port 8081

    service posts
        path ./posts
        port 8082
        depends users

    env development
        STORE_ADDRESS file://./data

Closes #2828

Co-authored-by: Shelley <shelley@exe.dev>
2026-01-27 12:01:47 +00:00
Asim Aslam cae6fbbe76 Framework hardening: security, reliability, and developer experience improvements (#2826)
* fix: remove deprecated rand.Seed calls

Go 1.20+ automatically seeds the global random number generator.
These calls are no-ops and generate warnings with newer Go versions.

Removed from:
- selector/strategy.go
- registry/cache/cache.go
- broker/memory.go
- broker/http.go
- cmd/cmd.go
- transport/memory.go

Co-authored-by: Shelley <shelley@exe.dev>

* fix: handle previously ignored errors

- MySQL store: properly handle prepared statement errors in initDB()
- Consul registry: handle client creation errors in Client() method

These silent failures could cause hard-to-debug issues in production.

Co-authored-by: Shelley <shelley@exe.dev>

* feat(genai): improve provider interface with context and streaming

Breaking changes:
- Generate() and Stream() now require context.Context as first parameter
- Stream.Close() added for proper resource cleanup

Improvements:
- Proper context support for cancellation and timeouts
- Real SSE streaming for OpenAI and Gemini text generation
- Better error handling with wrapped errors and API error responses
- Thread-safe provider registry with sync.RWMutex
- New options: WithMaxTokens, WithTemperature, WithTimeout
- Stream has proper Close() method for cleanup
- Results can include Error field for per-chunk errors

Provider updates:
- OpenAI: true streaming with SSE parsing, proper HTTP client with timeout
- Gemini: true streaming with streamGenerateContent endpoint
- Default model updated to gpt-4o-mini (OpenAI) and gemini-2.0-flash (Gemini)

Co-authored-by: Shelley <shelley@exe.dev>

* feat(tls): make TLS secure by default, configurable via environment

BREAKING: TLS now verifies certificates by default. Set MICRO_TLS_INSECURE=true
to restore previous behavior (NOT recommended for production).

Changes:
- Add util/tls.Config(), SecureConfig(), InsecureConfig(), ConfigFromEnv() helpers
- Update all components to use ConfigFromEnv() instead of hardcoded InsecureSkipVerify
- Set MinVersion to TLS 1.2 for all TLS configs

Affected components:
- broker/http
- broker/rabbitmq
- registry/etcd
- registry/consul
- transport/grpc

This improves security posture while allowing opt-out for development environments.

Co-authored-by: Shelley <shelley@exe.dev>

* feat(tls): add TLS helpers with opt-in secure mode

NOT a breaking change - keeps InsecureSkipVerify=true as default for
local development compatibility.

New util/tls helpers:
- Config() - returns config based on MICRO_TLS_SECURE env var
- SecureConfig() - certificate verification enabled
- InsecureConfig() - certificate verification disabled (dev only)

For production security, use one of:
- Set MICRO_TLS_SECURE=true with proper CA-signed certs
- Use a service mesh (Istio, Linkerd) for automatic mTLS
- Configure TLSConfig directly with your certificates

Also: Changed CLI alias from 'g' to 'gen' for clarity
- micro generate handler -> micro gen handler

Co-authored-by: Shelley <shelley@exe.dev>

* refactor(cli): rename generate directory to gen for consistency

Directory name now matches the command alias:
  cmd/micro/cli/gen/ -> micro gen handler

Co-authored-by: Shelley <shelley@exe.dev>

---------

Co-authored-by: Shelley <shelley@exe.dev>
2026-01-27 10:39:25 +00:00
Asim Aslam a32cdbc117 feat(web): add SSE broadcaster for real-time event streaming (#2825)
This adds Server-Sent Events (SSE) support to the web package, enabling
real-time updates in web applications built with go-micro.

Features:
- SSEBroadcaster manages connected clients and broadcasts events
- Integrates with events.Stream for subscribing to topics
- Supports JSON events and raw HTML (for htmx/datastar)
- Keep-alive mechanism for long-lived connections
- Thread-safe client management

Usage:
  broadcaster := web.NewSSEBroadcaster(
    web.WithStream(stream),
    web.WithTopics("posts", "comments"),
  )
  broadcaster.Start()
  router.GET("/events", broadcaster.Handler())

This enables real-time features requested in #2788, including:
- Live updates without page refresh
- htmx/datastar integration
- Foundation for MCP (Model Context Protocol) support

Closes #2788

Co-authored-by: Shelley <shelley@exe.dev>
2026-01-27 06:29:34 +00:00
Copilot baeb282cf1 Enhance cache rate limiting to prevent registry overload during rolling deployments (#2824)
* Initial plan

* Enhance cache rate limiting to protect against rolling deployment scenarios

Per @asim's feedback, rate limiting now applies to ALL cache refresh attempts
(not just error cases) to prevent registry overload during rolling deployments.

Changes:
- Rate limit ALL refresh attempts using lastRefreshAttempt tracking
- Always return stale cache if available (even if expired) when rate limiting
- Only return ErrNotFound when no cache exists during rate limit period
- Rate limiting happens inside singleflight to avoid race conditions
- Update test to reflect new behavior (no retry when stale cache + rate limit)
- Enhanced documentation with rolling deployment scenario examples

This addresses the scenario where all upstream services expire their cache
simultaneously during a downstream rolling deployment, which would previously
cause a stampede to the registry under high QPS.

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Remove unused failedAttempts and consecutiveFailures fields

Per @asim's feedback, these fields are no longer needed since the new
rate limiting strategy uses lastRefreshAttempt to track ALL refresh
attempts, not just failed ones.

Removed:
- failedAttempts map[string]time.Time
- consecutiveFailures int
- All code that sets these fields

The rate limiting logic now only uses lastRefreshAttempt, making these
fields redundant. All tests continue to pass.

Co-authored-by: asim <17530+asim@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: asim <17530+asim@users.noreply.github.com>
2026-01-14 10:57:14 +00:00
Copilot 2869cc16d1 Add adaptive throttling to registry cache to prevent penetration when no stale cache exists (#2823)
* Initial plan

* Add adaptive throttling to prevent cache penetration without stale cache

Implement rate limiting mechanism to protect etcd when:
- Cache is empty (no stale data available)
- Registry is failing/overloaded
- Multiple sequential requests arrive

Changes:
- Add MinimumRetryInterval option (default 5s)
- Track last failed attempt time per service
- Throttle requests within retry interval when no cache exists
- Clear throttling on successful lookup
- Add comprehensive tests validating throttling behavior

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Fix WaitGroup race condition in events stream tests

The WaitGroup.Add() calls were happening after goroutines started,
causing a race where Done() could be called before Add(), resulting
in "negative WaitGroup counter" panics.

Fixes:
- Move wg.Add(1) before goroutine in TestConsumeTopic
- Move wg.Add(2) before first goroutine in TestConsumeGroup

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Update registry cache documentation with adaptive throttling feature

Document the new adaptive throttling feature that prevents cache
penetration when registry is failing and no stale cache exists.

Includes:
- Feature overview
- Usage examples with configuration options
- Explanation of throttling behavior
- Example scenario demonstrating protection

Co-authored-by: asim <17530+asim@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: asim <17530+asim@users.noreply.github.com>
2026-01-09 12:27:55 +00:00
Copilot dbb66ec938 Fix etcd auth overload and cache stampede with KeepAlive channels (#2822)
* Initial plan

* Replace KeepAliveOnce with KeepAlive to reduce etcd auth requests

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Add tests to verify cache penetration protection via singleflight

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Add etcd integration tests to CI workflow

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Fix race conditions and improve code quality based on review feedback

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Add workflow permissions to fix security scan finding

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Add comprehensive documentation for performance improvements

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Fix memory store limit/offset bug causing events test failure

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Fix memory store to filter before limiting in prefix/suffix reads

The previous fix had a logic error where limit/offset were applied before
prefix/suffix filtering. This could cause incorrect results when the first
N items in the unfiltered list don't match the search criteria.

Now filters first to get all matching keys, then applies limit/offset to
the filtered results. This ensures ReadLimit(1) always returns 1 matching
record if available, regardless of map iteration order.

Co-authored-by: asim <17530+asim@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: asim <17530+asim@users.noreply.github.com>
2026-01-09 11:12:06 +00:00
Copilot 80345fe63d docs: clarify gRPC server option ordering and service name usage (#2820)
* Initial plan

* docs: clarify gRPC server option ordering and service name usage

- Fix all examples to show Server option before Name option
- Add note explaining why option ordering matters
- Add new section on "Option Ordering Issue" in Common Errors
- Add new section on "Service Name vs Package Name" in Common Errors
- Update transport.md to show proper ordering with comment

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* docs: refine comments based on code review feedback

- Clarify that Server ordering before Name is mandatory
- Remove confusing comment about Client ordering being for consistency

Co-authored-by: asim <17530+asim@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: asim <17530+asim@users.noreply.github.com>
2025-11-25 09:26:59 +00:00
Copilot 00a119496e Add documentation for native gRPC compatibility vs transport (#2819)
* Initial plan

* Add documentation for native gRPC compatibility with grpc client/server packages

Co-authored-by: asim <17530+asim@users.noreply.github.com>

* Fix go_package path in proto example to use relative path

Co-authored-by: asim <17530+asim@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: asim <17530+asim@users.noreply.github.com>
2025-11-25 07:28:48 +00:00
Asim Aslam 3e25be984d x 2025-11-13 20:48:01 +00:00
Asim Aslam 4e8934c230 Get Badge 2025-11-13 20:46:20 +00:00
Asim Aslam a368be82cd add showcase 2025-11-13 20:42:45 +00:00
Asim Aslam 43386d4ec1 x 2025-11-13 20:37:54 +00:00
Asim Aslam a84f92c907 mobile hamburger menu 2025-11-13 20:34:09 +00:00
Asim Aslam 751de9e7c0 fix mobile rendering for website 2025-11-13 20:31:29 +00:00
Asim Aslam be1cf9c9d8 x 2025-11-13 20:06:28 +00:00
Asim Aslam d7699845bb Add docs link 2025-11-13 20:01:32 +00:00
Asim Aslam 520a0fa140 Update features 2025-11-13 19:59:28 +00:00
Asim Aslam 8a1591af0c x 2025-11-13 19:58:38 +00:00
Asim Aslam 1f1d9875a2 update landing 2025-11-13 19:56:01 +00:00
Asim Aslam cd4c881db5 x 2025-11-13 19:52:06 +00:00
Asim Aslam de03bbbf81 x 2025-11-13 19:49:34 +00:00
Asim Aslam ee4f656fa5 fix typo in search documentation 2025-11-13 19:26:19 +00:00
Asim Aslam 2cce3e5e1a fix links 2025-11-13 19:21:27 +00:00
Asim Aslam 0526a42efa changes to theme 2025-11-13 19:14:01 +00:00
Asim Aslam dc1e1eb45c fix config file 2025-11-13 19:04:30 +00:00
Asim Aslam 06b31f545a update the docs to easily navigate 2025-11-13 18:59:34 +00:00
Asim Aslam 8cda829320 major docs overhaul 2025-11-13 18:34:40 +00:00
Asim Aslam e755e4a823 updates for syntax highlighting 2025-11-13 18:17:45 +00:00
Asim Aslam eef06fcf01 server docs 2025-11-13 18:12:15 +00:00
Asim Aslam 9e36df224b new copilot generated documentation 2025-11-13 18:11:29 +00:00
Asim Aslam 2da1cc0edd Delete .github/PULL_REQUEST_TEMPLATE.md 2025-11-13 17:19:17 +00:00
Asim Aslam 0ef0143537 Delete .github/ISSUE_TEMPLATE/question.md 2025-11-13 17:19:04 +00:00
Asim Aslam 30dc01523a Delete .github/ISSUE_TEMPLATE/feature-request---enhancement.md 2025-11-13 17:18:54 +00:00
Asim Aslam 4a0648536f Delete .github/ISSUE_TEMPLATE/bug_report.md 2025-11-13 17:18:43 +00:00
nswdewy 01ed999b2a Change template paths from 'html' to 'web' (#2816) 2025-11-06 10:17:30 +00:00
Asim Aslam acfb4e2639 Update README.md 2025-10-29 10:46:41 +00:00
Asim Aslam cd735aba56 Update sponsorship link in README.md 2025-10-29 10:46:14 +00:00
Asim Aslam 8c995ea8ac Update sponsorship link in README 2025-10-29 10:45:28 +00:00
Asim Aslam e9ce3487b6 Update README.md 2025-10-29 10:44:16 +00:00
Asim Aslam 79f5a7a7f6 Fix README formatting and sponsor button placement 2025-10-29 10:43:48 +00:00
Asim Aslam 48c310f70b Update README.md 2025-10-29 10:43:32 +00:00
Asim Aslam 5ffb711dfe Add funding configuration for GitHub 2025-10-29 10:42:01 +00:00
Asim Aslam de5057e35d Update README to remove install script section
Removed mention of install script from README.
2025-10-22 21:19:31 +01:00
Asim Aslam 91d91eef1f Fix for https://github.com/micro/go-micro/issues/2687 2025-10-22 06:38:16 +00:00
asim 48479228b1 Fixes https://github.com/micro/go-micro/issues/2738 2025-10-22 07:18:37 +01:00
asim 5a07370970 Fix https://github.com/micro/go-micro/issues/2769 2025-10-22 07:10:41 +01:00
Asim Aslam db9b1e8d79 Update installation command to specific version 2025-10-20 11:41:26 +01:00
Asim Aslam 3e05108882 Update installation command to specific version 2025-10-20 11:41:04 +01:00
Asim Aslam 85cd80a467 Delete cmd/README.md 2025-10-14 19:34:27 +01:00
Eng Zer Jun bc40df0c9e Update github.com/imdario/mergo to dario.cat/mergo (#2810)
Mergo v1 is released with a new module path URL. No breaking changes,
only the module path update and bug fixes.

Reference: https://github.com/darccio/mergo/releases/tag/v1.0.0
Reference: https://github.com/darccio/mergo/releases/tag/v1.0.1
Reference: https://github.com/darccio/mergo/releases/tag/v1.0.2

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2025-10-14 11:18:28 +01:00
asim 66014eac68 . 2025-10-14 11:17:03 +01:00
asim 26b9d56165 . 2025-10-14 11:15:52 +01:00
asim 6574180b0d . 2025-10-14 11:14:36 +01:00
asim e6c9f4fa39 . 2025-10-14 11:13:53 +01:00
asim 1dde737b64 move micro cli and protoc-gen-micro to cmd/ 2025-10-14 11:13:35 +01:00
Asim Aslam 26adf49e55 Remove Command Line section from README
Removed command line section from README.
2025-10-14 10:33:20 +01:00
Eng Zer Jun 7a9c445321 Update github.com/streadway/amqp to github.com/rabbitmq/amqp091-go (#2811)
The `github.com/streadway/amqp` module is no longer actively maintained.
The new module is now maintained by the RabbitMQ core team under a
different package name.

Reference: https://github.com/rabbitmq/amqp091-go

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2025-10-13 21:34:07 +01:00
Asim Aslam 44cc31345d use buf pool 2025-10-07 16:38:09 +00:00
Asim Aslam aa2ed9aa91 Patch for potential deadlock 2025-10-07 16:20:45 +00:00
Asim Aslam 3d6b6521ab fix atomic int alignment bug 2025-10-07 15:57:43 +00:00
Kenley Wang 7b0fa8b6ae fix: new pool cannot customize closetimeout (#2808) 2025-10-02 14:28:06 +01:00
asim 059d317969 . 2025-09-29 10:28:59 +01:00
Asim Aslam e0af3b61a5 Change 'Toolkit' to 'Command Line' in README
Updated section headers in README for clarity.
2025-09-28 09:55:43 +01:00
Asim Aslam 5bbc24abe1 Clarify micro CLI usage and genai package details
Updated the README to clarify the usage of the micro CLI and the genai package.
2025-09-28 08:51:30 +01:00
Asim Aslam dfcaae7bf8 Update link text from 'Docs' to 'Go Doc' 2025-09-27 09:45:52 +01:00
Ak-Army 9070b3befd [feature] ability to use wildcard in topic name (factory-events.*.*) (#2804) 2025-09-09 12:51:39 +01:00
ExtinctPatronageDeodorize e5cd820c71 fix data race in memory.update (#2802)
Co-authored-by: ExtinctPatronageDeodorize <ExtinctPatronageDeodorize@users.noreply.github.com>
2025-08-29 14:14:11 +01:00
Tsln 479bd58c3f fix consul context key mismatch (#2801) 2025-08-29 07:39:20 +01:00
Byron Silvers 95540b7859 fix consul watcher address handling (#2800) 2025-08-19 09:27:34 +01:00
Asim Aslam be2559c555 Update index.html 2025-08-05 14:15:06 +01:00
Asim Aslam 6e53f541d3 Update README.md 2025-08-05 14:14:28 +01:00
Asim Aslam a6ede13f73 Update index.html 2025-08-04 11:56:59 +01:00
Asim Aslam 31d2d39f76 Update README.md 2025-07-24 21:24:04 +01:00
Roman Perekhod ad73add529 fix the concurrent map writes error (#2794) 2025-07-16 07:27:45 +01:00
asim f99a205b2b add string function 2025-07-15 20:43:58 +01:00
Asim Aslam 3cf5540b0f Update README.md 2025-07-08 19:24:19 +01:00
Asim Aslam 2a140858a8 Update README.md 2025-07-08 19:23:49 +01:00
Asim Aslam 2d19a304fc Update README.md 2025-07-08 19:23:15 +01:00
asim 7b48449a85 fix options 2025-07-07 10:23:23 +01:00
asim 680987aeeb . 2025-07-02 09:56:34 +01:00
Asim Aslam ee9f3afe37 GenAI interface (#2790)
* genai interface

* x

* x

* text to speech

* Re-add events package (#2761)

* Re-add events package

* run redis as a dep

* remove redis events

* fix: data race on event subscriber

* fix: data race in tests

* fix: store errors

* fix: lint issues

* feat: default stream

* Update file.go

---------

Co-authored-by: Brian Ketelsen <bketelsen@gmail.com>

* .

* copilot couldn't make it compile so I did

* copilot couldn't make it compile so I did

* x

---------

Co-authored-by: Brian Ketelsen <bketelsen@gmail.com>
2025-06-20 10:24:31 +01:00
Asim Aslam 7e1bba2baf Re-add events package (#2761)
* Re-add events package

* run redis as a dep

* remove redis events

* fix: data race on event subscriber

* fix: data race in tests

* fix: store errors

* fix: lint issues

* feat: default stream

* Update file.go

---------

Co-authored-by: Brian Ketelsen <bketelsen@gmail.com>
2025-06-18 17:12:02 +01:00
blacksheepaul dd0944bf68 Update getting-started.md (#2787) 2025-06-12 09:56:34 +01:00
Ak-Army 88f38eaef6 Subscribe error handling (#2785)
* [fix] etcd config source prefix issue (#2389)

* http transport data race issue (#2436)

* [fix] #2431 http transport data race issue

* [feature] Ability to close connection while receiving.
Ability to send messages while receiving.
Icreased r channel limit to 100 to more fluently communication.
Do not dropp sent request if r channel is full.

* [feature] always subscribes to all topics and if there is an error in one of them, the unsuccessful topics will be subscribed to again

---------

Co-authored-by: Johnson C <chengqiaosheng@gmail.com>
2025-06-04 08:55:17 +01:00
Asim Aslam 0e45edf439 Set service name as table name (#2780)
* add docs layout

* update all to use _layouts

* update the styling

* always use service name as table name
2025-05-21 22:43:29 +01:00
Asim Aslam 788dcd05b2 Docs (#2779)
* add docs layout

* update all to use _layouts

* update the styling
2025-05-21 13:48:03 +01:00
Asim Aslam 456cd7e092 Add links to readme contents 2025-05-21 12:06:25 +00:00
Asim Aslam 3fd52c66e7 Generated docs for the following files: 2025-05-21 12:03:24 +00:00
Asim Aslam 3c3ba55c45 Create README.md (#2778) 2025-05-21 11:22:11 +01:00
Asim Aslam 1a8074467a Update and rename docs.yml to website.yml (#2777) 2025-05-21 11:18:54 +01:00
Asim Aslam b9665e32c5 Move whole website (#2776)
* adding docs

* minor getting started typo

* move the whole website
2025-05-21 11:17:04 +01:00
Asim Aslam 11b7eb0727 Docs (#2775)
* minor getting started typo
2025-05-21 10:59:04 +01:00
Asim Aslam 5a409f2607 Create docs.yml 2025-05-21 10:49:59 +01:00
Asim Aslam 8e771c57e1 adding docs (#2774) 2025-05-21 10:47:47 +01:00
Brian Ketelsen ddc34801ee Plugins and profiles (#2764)
* feat: more plugins

* chore(ci): split out benchmarks

Attempt to resolve too many open files in ci

* chore(ci): split out benchmarks

* fix(ci): Attempt to resolve too many open files in ci

* fix: set DefaultX for cli flag and service option

* fix: restore http broker

* fix: default http broker

* feat: full nats profile

* chore: still ugly, not ready

* fix: better initialization for profiles

* fix(tests): comment out flaky listen tests

* fix: disable benchmarks on gha

* chore: cleanup, comments

* chore: add nats config source
2025-05-20 13:24:06 -04:00
Brian Ketelsen e12504ce3a feat: re-add profiles (#2772)
* feat: re-add profiles

* fix: make profile separate package

* fix: make profile separate package

* fix: profile flag

* fix: defaults
2025-05-19 13:59:28 -04:00
asim a03ab5f601 switch location of store dir to home dir 2025-05-19 09:28:13 +01:00
Asim Aslam 44ff301d2d syntactically easy way to register commands (#2770) 2025-05-18 09:45:49 +01:00
Asim Aslam 37bb1a8ab6 Revert "WIP: move file store (do not merge) (#2766)" (#2768)
This reverts commit 97275d3db9.
2025-05-16 19:06:45 +01:00
BombartSimon 1fe2638298 Implement MDNS Registry (#2767)
- Removed existing mDNS test file and replaced it with a new implementation.
- Added a new `mdns_registry.go` file that contains the MDNS registry logic.
- Updated the default registry to use the new MDNS registry.
- Refactored tests to accommodate the new MDNS registry implementation.
- Implemented service registration, deregistration, and service discovery using mDNS.
- Added encoding and decoding functions for mDNS TXT records.
- Implemented a watcher for monitoring service changes in the MDNS registry.
2025-05-16 19:03:36 +01:00
Asim Aslam 97275d3db9 WIP: move file store (do not merge) (#2766)
* move file store

* fix build
2025-05-16 15:08:13 +01:00
BombartSimon e29159e836 Rename 'Users' section to 'Adopters' in README (#2765) 2025-05-15 22:20:10 +01:00
Asim Aslam caba761c7b fix extraction field naming with standard Go types (#2763) 2025-05-15 18:59:10 +01:00
Brian Ketelsen cd2b40ca4a Add a selection of plugins to the core repo (#2755)
* WIP

* fix: default memory registry, add registrations for mdns, nats

* fix: same for broker

* fix: add more

* fix: http port

* rename redis

* chore: linting
2025-05-15 18:47:35 +01:00
Asim Aslam 7c04b7cfd6 Update README.md (#2762) 2025-05-15 16:13:27 +01:00
Asim Aslam b4a87d05f7 Update README.md (#2759) 2025-05-15 09:37:12 +01:00
asim 0e47cbf1a2 fix conflicting port range test 2025-05-14 22:11:23 +01:00
asim 12dfa797dc drop the separate go mods 2025-05-14 22:03:38 +01:00
Asim Aslam 230505bf5a Add grpc plugin (#2758)
* Add grpc plugin

* remove stale readmes
2025-05-14 21:04:42 +01:00
Asim Aslam 01b8394c81 Update README.md 2025-05-07 19:39:11 +01:00
Asim Aslam f9d08a14f3 Update README.md (#2756) 2025-05-07 19:35:20 +01:00
Asim Aslam a997f738dd Update README.md 2025-05-07 19:34:21 +01:00
Asim Aslam 46db7df218 Update README.md 2025-05-07 17:07:20 +01:00
Brian Ketelsen 17c04258a4 fix: go version breaking unit tests (#2754) 2025-05-05 21:12:34 -04:00
asim 8eb280126a add go mod 2025-05-05 22:02:32 +01:00
asim f51cd8d883 default to file store 2025-05-05 22:02:11 +01:00
asim ef4dc8b5b0 add json.NewValues to config 2025-05-05 14:39:54 +01:00
asim 23b14123ea errors for go 1.24wq 2025-05-04 21:48:02 +01:00
asim 2388f662cf break config.Get and return error with value 2025-05-04 21:31:17 +01:00
asim 60474ed38f add store encode/decode for record 2025-05-04 20:13:58 +01:00
asim 484eb3d15e public functions for store 2025-05-04 20:00:44 +01:00
asim c51095a074 store.NewRecord 2025-05-04 19:55:10 +01:00
Asim Aslam 03782bc9b3 move service to service dir to make life not suck (#2753) 2025-05-04 19:44:56 +01:00
Asim Aslam 1040b7c58e Update README.md 2025-05-01 10:27:59 +01:00
Asim Aslam bd0e9ca7cb Update README.md 2025-05-01 10:27:37 +01:00
Asim Aslam f5399d56c3 Update README.md 2025-05-01 10:25:44 +01:00
Asim Aslam 0f4c238804 protoc-gen-micro has moved to micro/micro/cmd/protoc-gen-micro (#2751) 2025-04-30 16:50:27 +01:00
Asim Aslam 66c169076c Update README.md 2025-04-25 09:43:41 +01:00
Asim Aslam 280eb5b46d Update README.md 2025-04-25 09:42:43 +01:00
Asim Aslam 4ead4ff953 Update README.md (#2750) 2025-04-25 09:41:35 +01:00
Asim Aslam 200a3cb0ce Update README.md (#2749) 2025-04-23 16:04:24 +01:00
Asim Aslam 049dea6804 Update README.md 2025-04-23 15:56:47 +01:00
asim 3fa2a38d76 syntatic sugar for micro.New("helloworld") 2025-04-23 12:21:21 +01:00
asim 65af48823f yolo development is bad 2025-04-23 12:16:34 +01:00
asim 156a968253 directly support handler in the service interface 2025-04-23 12:13:23 +01:00
Morya 517b2b0855 Update README.md (#2748)
go install github.com/micro/go-micro/cmd/protoc-gen-micro@latest

should be used, instand of 

`go install github.com/micro/go-micro/cmd/protoc-gen-micro`
2025-04-22 17:09:21 +01:00
Pavel Ivanov 4702afe57d Fix http transport client blocking recv (#2744)
* reproduce blocking recv

* fix blocking recv call on httpTransportClient

* prevent race condition

* refactoring
2025-04-10 15:24:54 +01:00
Jörn Friedrich Dreyer e032a6aafd update ttl for updated nodes only (#2740)
Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
2024-11-15 14:08:17 +00:00
Jörn Friedrich Dreyer 14a1791011 invalidate service if node was not updated (#2736)
Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
2024-10-28 15:34:38 +00:00
Morya b318b7f097 go mod tidy (#2730) 2024-08-26 07:20:29 +01:00
Ak-Army 0433e98dbc Better connection pool handling (#2725)
* [fix] etcd config source prefix issue (#2389)

* http transport data race issue (#2436)

* [fix] #2431 http transport data race issue

* [feature] Ability to close connection while receiving.
Ability to send messages while receiving.
Icreased r channel limit to 100 to more fluently communication.
Do not dropp sent request if r channel is full.

* [fix] Use pool connection close timeout

* [fix] replace Close with private function

* [fix] Do not close the transport client twice in stream connection , the transport client is closed in the rpc codec

* [fix] tests

---------

Co-authored-by: Johnson C <chengqiaosheng@gmail.com>
2024-07-23 12:19:43 +01:00
Asim Aslam 1c6c1ff1a3 Update README.md (#2722) 2024-07-15 11:55:17 +01:00
Asim Aslam 4c34451125 Fix data race (#2721) 2024-07-12 09:36:43 +01:00
asim 9a7cd8ce66 update readme 2024-07-08 18:52:06 +01:00
asim dd0145fa18 unused packages 2024-07-08 18:48:52 +01:00
asim 72df27b7d1 remove util/sync 2024-07-08 18:46:34 +01:00
asim e9a52070e6 k8s not needed 2024-07-08 18:44:42 +01:00
asim 6e393f6abf move cmd package back to top level. Strip grpc plugin 2024-07-07 22:38:11 +01:00
asim 90531337db . 2024-07-07 19:14:04 +01:00
asim e756fd32e6 Fix panic 2024-07-07 19:09:19 +01:00
asim 7c3f272001 remove sync package 2024-07-07 19:03:18 +01:00
asim 66b3fd8893 fix retry test 2024-07-07 19:01:43 +01:00
asim c64cb1cb03 more references to runtime 2024-07-07 18:50:52 +01:00
asim 8876002e57 more references to runtime 2024-07-07 18:49:39 +01:00
asim a3809afbdf more references to runtime 2024-07-07 18:44:18 +01:00
asim 563e0d265d meh 2024-07-07 18:40:24 +01:00
asim 3d5f87c01b no one is using that 2024-07-07 18:40:15 +01:00
asim bac34aaec1 still more fixes 2024-07-07 18:36:04 +01:00
asim db0fa9fe1f fix bugs 2024-07-07 18:32:26 +01:00
asim 3676232df1 strip runtime 2024-07-07 18:30:48 +01:00
asim 29d79d748d remove runtime that no one uses 2024-07-07 18:28:38 +01:00
asim 627066baf9 remove events entirely 2024-07-07 18:26:30 +01:00
asim d84da9a8eb meh 2024-07-07 18:19:50 +01:00
asim 6c0a073e33 Merge branch 'master' of ssh://github.com/micro/go-micro 2024-07-07 18:19:19 +01:00
asim 12e8fcd057 Fix parallel test 2024-07-07 18:18:43 +01:00
Asim Aslam 4dcf2e58c0 Update README.md (#2720) 2024-07-07 08:05:08 +01:00
Asim Aslam b56cfaf818 Revert license to Apache 2 2024-07-07 08:04:29 +01:00
Asim Aslam ff52e9f5d0 Delete .github/FUNDING.yml 2024-07-07 07:18:47 +01:00
Asim Aslam c05c11e0c3 Update README.md (#2719) 2024-07-04 10:29:05 +01:00
asim fc614aef2d add back generator 2024-07-04 09:18:52 +01:00
Ak-Army 1515db5240 Fix stream eos error (#2716)
* [fix] etcd config source prefix issue (#2389)

* http transport data race issue (#2436)

* [fix] #2431 http transport data race issue

* [feature] Ability to close connection while receiving.
Ability to send messages while receiving.
Icreased r channel limit to 100 to more fluently communication.
Do not dropp sent request if r channel is full.

* [fix] Do not send error when stream send eos header, just close the connection

* [fix] Do not overwrite the error in http client

---------

Co-authored-by: Johnson C <chengqiaosheng@gmail.com>
2024-07-02 13:06:14 +01:00
littlecoderonway 4d5b3b084f Fix registry cache broken (#2715)
* services is shared between routines, when application change services returned by get function may lead to other routine set a changed services to cache

* services is shared between routines, when application change services returned by get function may lead to other routine set a changed services to cache

---------

Co-authored-by: Shuaihu Liu <shuaihu.liu@shopee.com>
2024-07-02 09:30:51 +01:00
Asim Aslam e9ceb66e32 Update README.md 2024-06-05 18:28:17 +01:00
asim 610c00859f v5 2024-06-04 21:40:43 +01:00
Asim Aslam e11395c8f5 Update LICENSE (#2712)
BSL license
2024-06-04 21:37:52 +01:00
Di Wu 63f2507944 fix(sec): CVE-2024-24786 (#2699) 2024-06-04 20:23:15 +01:00
Asim Aslam 0c6c907c58 Delete CHANGELOG.md
Not being maintained
2024-06-04 20:21:45 +01:00
Asim Aslam 53f691da30 Update README.md (#2711) 2024-06-04 20:21:05 +01:00
Asim Aslam 8f43ae86dd Update FUNDING.yml (#2710) 2024-06-04 20:01:41 +01:00
dependabot[bot] f9ce51c522 chore(deps): bump github.com/opencontainers/runc from 1.1.5 to 1.1.12 (#2706)
Bumps [github.com/opencontainers/runc](https://github.com/opencontainers/runc) from 1.1.5 to 1.1.12.
- [Release notes](https://github.com/opencontainers/runc/releases)
- [Changelog](https://github.com/opencontainers/runc/blob/main/CHANGELOG.md)
- [Commits](https://github.com/opencontainers/runc/compare/v1.1.5...v1.1.12)

---
updated-dependencies:
- dependency-name: github.com/opencontainers/runc
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-04-19 18:51:46 +01:00
dependabot[bot] 08d98adcd2 chore(deps): bump golang.org/x/net from 0.17.0 to 0.23.0 (#2705)
Bumps [golang.org/x/net](https://github.com/golang/net) from 0.17.0 to 0.23.0.
- [Commits](https://github.com/golang/net/compare/v0.17.0...v0.23.0)

---
updated-dependencies:
- dependency-name: golang.org/x/net
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-04-19 13:56:58 +01:00
guangwu 186b8351dc fix: close dockerfile (#2703) 2024-04-17 07:45:39 +01:00
Z.Q.K b1e58a1fe8 fix typo (#2701) 2024-03-26 03:39:45 +00:00
Ak-Army f1a8b39309 Fix double close in stream client (#2693)
* [fix] etcd config source prefix issue (#2389)

* http transport data race issue (#2436)

* [fix] #2431 http transport data race issue

* [feature] Ability to close connection while receiving.
Ability to send messages while receiving.
Icreased r channel limit to 100 to more fluently communication.
Do not dropp sent request if r channel is full.

* [fix] Do not close the transport client twice in stream connection , the transport client is closed in the rpc codec

---------

Co-authored-by: Johnson C <chengqiaosheng@gmail.com>
Co-authored-by: Hunyadvári Péter <peter.hunyadvari@vcc.live>
2024-02-15 20:26:36 +00:00
Asim Aslam 6e55bb1a0e Update README.md (#2692) 2024-02-10 18:47:38 +00:00
Morya f28468a59c feat: allow to set API listen address (#2680) 2023-12-18 10:29:47 +00:00
Asim Aslam 3a4790b3c5 Update tests.yaml (#2681) 2023-12-18 10:28:44 +00:00
Eng Zer Jun cbd45b12dc Avoid allocations with (*regexp.Regexp).MatchString (#2679)
We should use `(*regexp.Regexp).MatchString` instead of
`(*regexp.Regexp).Match([]byte(...))` when matching string to avoid
unnecessary `[]byte` conversions and reduce allocations.

func BenchmarkMatch(b *testing.B) {
	for i := 0; i < b.N; i++ {
		if match := versionRe.Match([]byte("v1")); !match {
			b.Fail()
		}
	}
}

func BenchmarkMatchString(b *testing.B) {
	for i := 0; i < b.N; i++ {
		if match := versionRe.MatchString("v1"); !match {
			b.Fail()
		}
	}
}

goos: linux
goarch: amd64
pkg: go-micro.dev/v4/api/handler/event
cpu: AMD Ryzen 7 PRO 4750U with Radeon Graphics
BenchmarkMatch-16          	11430127	       127.4 ns/op	       2 B/op	       1 allocs/op
BenchmarkMatchString-16    	12220628	        97.54 ns/op	       0 B/op	       0 allocs/op
PASS
ok  	go-micro.dev/v4/api/handler/event	3.822s

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2023-12-04 16:00:01 +00:00
guangwu 252385e39c chore: replace for loop with call to copy (#2678) 2023-11-30 11:18:05 +00:00
ChengDaqi2023 68c026c5d8 update golang.org/x/net v0.8.0 to 0.17.0 (#2677) 2023-11-29 10:24:36 +00:00
Elmut ca6190f5f2 append to subscribers (#2640)
* append to subscribers

* Update rpc_router.go

error correction log
2023-11-26 11:08:28 +01:00
Guillaume Bour 674b9822e0 util/addr: Fixes findIP to return public IP if present. (#2673) 2023-11-26 11:06:55 +01:00
Christian Richter 7392705af8 bump urfave cli & fix race condition (#2659)
* bump urfave cli

Signed-off-by: Christian Richter <crichter@owncloud.com>

* Fix race condition

Co-authored-by: André Duffeck <andre.duffeck@firondu.de>

Signed-off-by: Christian Richter <crichter@owncloud.com>

---------

Signed-off-by: Christian Richter <crichter@owncloud.com>
2023-10-09 10:33:57 +01:00
Asim Aslam 27c488712e Update README.md (#2652) 2023-08-07 09:46:15 +01:00
Asim Aslam c3d7c65c88 Update README.md (#2650) 2023-07-20 07:49:53 +01:00
Asim Aslam 384814c885 Update README.md (#2648) 2023-07-17 09:33:34 +01:00
Asim Aslam 8a3a98a8b8 Update README.md (#2647) 2023-07-16 12:02:53 +01:00
asim 416f65e814 rename test dir 2023-07-11 09:25:35 +01:00
clearcode 8020303017 Update README.md (#2635) 2023-05-06 21:39:24 +02:00
mamadeusia 67d48b205e Add Context in event options (#2634)
Co-authored-by: mamadeusia <timadues7775@gmail.com>
2023-05-03 13:24:36 +01:00
dependabot[bot] 31135d4696 Bump github.com/docker/docker from 20.10.7+incompatible to 20.10.24+incompatible (#2625)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-04-26 02:22:47 +02:00
Coder 1478a8e46d fix(config/source/cli): mergo.Map error, src and dst must be of same … (#2628) 2023-04-26 02:21:08 +02:00
Mohamed MHAMDI ad8fca255b fix(config): fix file source watcher stop behavior when Stop is called (#2630)
Co-authored-by: Mohamed MHAMDI <mmhamdi@hubside.com>
2023-04-26 02:19:52 +02:00
Lukasz Raczylo a7522e7d6c fix: struct field alignment (#2632) 2023-04-26 02:16:34 +02:00
Asim Aslam 0f9b2f00c9 Update README.md 2023-04-12 11:09:56 +01:00
Asim Aslam 7fe95e8732 Update README.md 2023-04-12 11:09:40 +01:00
Asim Aslam d44ed328d1 Add Handle option (#2627) 2023-04-11 10:29:03 +01:00
Thomas Chandelle d392e72021 fix(api/handler): avoid zombie goroutine when connection unexpectedly closes (#2624) 2023-04-05 22:50:24 +02:00
dependabot[bot] 683e2729b4 Bump github.com/opencontainers/runc from 1.1.4 to 1.1.5 (#2623)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-30 20:19:21 +02:00
asim 6f8930926f gofmt 2023-03-22 16:42:54 +00:00
Asim Aslam 2117672933 Update FUNDING.yml 2023-03-21 20:51:42 +00:00
Asim Aslam d7e692b5d1 Update README.md 2023-03-21 15:19:07 +00:00
asim d949258b2f update the logo 2023-03-20 16:48:44 +00:00
fuyou d376656528 fix(sec): upgrade github.com/containerd/containerd to 1.6.18 (#2617)
* update github.com/containerd/containerd v1.4.3 to 1.6.18

* fix(sec): upgrade containerd

* fix(sec): go mod tidy

---------

Co-authored-by: Davincible <david.brouwer.99@gmail.com>
2023-03-07 17:28:22 +01:00
dependabot[bot] 415b3e3a2f Bump golang.org/x/net from 0.0.0-20210510120150-4163338589ed to 0.7.0 (#2615)
Bumps [golang.org/x/net](https://github.com/golang/net) from 0.0.0-20210510120150-4163338589ed to 0.7.0.
- [Release notes](https://github.com/golang/net/releases)
- [Commits](https://github.com/golang/net/commits/v0.7.0)

---
updated-dependencies:
- dependency-name: golang.org/x/net
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-07 17:11:10 +01:00
Hellis e337eb2c3d fix(api): add WithRegistry option for api (#2618) 2023-03-07 17:05:25 +01:00
dependabot[bot] 521e6b644c Bump golang.org/x/crypto from 0.0.0-20210513164829-c07d793c2f9a to 0.1.0 (#2619)
Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.0.0-20210513164829-c07d793c2f9a to 0.1.0.
- [Release notes](https://github.com/golang/crypto/releases)
- [Commits](https://github.com/golang/crypto/commits/v0.1.0)

---
updated-dependencies:
- dependency-name: golang.org/x/crypto
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-07 17:04:20 +01:00
Stanislav ad0b4f103d feat(errors): append errors use variadic arguments (#2606) 2023-01-03 12:58:03 +01:00
Davincible 68a6425ad8 fix(service): profile stop error scope 2022-11-16 05:07:41 +01:00
leoujz 0a91ba7b5d api gateway handing http request adds Content-Type application/x-www-form-urlencoded, and extract endpoints from path if no endpoint matched (#2592)
Co-authored-by: l <l@x>
2022-11-09 04:28:39 +01:00
645775992 a17eaf64da update gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b to 3.0.0 (#2589) 2022-11-04 12:06:13 +01:00
645775992 6df085fd6d update github.com/opencontainers/runc v0.1.1 to 1.1.2 (#2590) 2022-11-04 12:05:41 +01:00
David Brouwer 697ea1b21e Update README.md 2022-11-02 21:45:35 +01:00
JellyTony b442dbb56b fix: fix configuration version data competition (#2586)
Co-authored-by: JeffreyBool <zhanggaoyuan@mediatrack.cn>
2022-10-26 12:12:44 +02:00
Sagan Yaroslav b988a78bae fix: store table initialization (#2584) 2022-10-20 14:59:08 +02:00
David Brouwer a3980c2308 feat: add test framework & refactor RPC server (#2579)
Co-authored-by: Rene Jochum <rene@jochum.dev>
2022-10-20 13:00:50 +02:00
keepstep c25dee7c8a fix(registry/cache): do not watch when ttl=0 eg: some custom registry no s… (#2580)
Co-authored-by: keep <keep@pa.com>
2022-10-08 15:19:48 +02:00
Rene Jochum 24dfcef49a fix(transport/memory): Improve the memory transport, 4x speed (#2581) 2022-10-07 23:54:09 +02:00
Rene Jochum 065f9714e9 fix: easy lint fixes to api/ (#2567) 2022-10-01 10:50:11 +02:00
Rene Jochum 010b1d9f11 fix: linting issues (#2566) 2022-09-30 20:32:55 +02:00
David Brouwer 85c0b0b8eb fix: some linting issues (#2563) 2022-09-30 16:27:07 +02:00
David Brouwer 47e6a8d725 feat(CI): add linting and pretty test output (#2562) 2022-09-30 02:08:42 +02:00
Mohamed MHAMDI 1db36357d5 feat(logger): add logger option to all micro components (override DefaultLogger) closes #2556 (#2559)
Run tests / Test repo (push) Waiting to run
* feat(logger): add logger option to all components

* fix: refactor api/rpc.go

* fix: refactor api/stream.go

* fix: api/options.go comment

* fix(logger): do not use logger.Helper internally

* fix(logger): fix comments

* fix(logger): use level.Enabled method

* fix: rename mlogger to log

* fix: run go fmt

* fix: log level

* fix: factories

Co-authored-by: Mohamed MHAMDI <mmhamdi@hubside.com>
Co-authored-by: Davincible <david.brouwer.99@gmail.com>
2022-09-29 16:44:53 +02:00
David Brouwer 57a0ef5a0f docs: update README shields (#2558)
* docs: add badges to README.md

* docs: new discord badge

* docs: update discord badge

* docs: update discord badge

* docs: remove shield
2022-09-24 03:40:48 +02:00
Mohamed MHAMDI 39e00f11a8 feat(config): add withFs option to file source (#2557)
Co-authored-by: Mohamed MHAMDI <mmhamdi@hubside.com>
2022-09-24 02:46:18 +02:00
David Bereza 34b6434791 fix: prevent returning empty strings for list (#2553) 2022-09-06 20:03:23 +01:00
Asim Aslam a702a1b097 Update README.md 2022-08-17 10:02:52 +01:00
asim d32c8bd0eb move logo
Run tests / Test repo (push) Waiting to run
2022-08-17 09:50:32 +01:00
刘志铭 d7d8123bc7 Fix a problem with the Register Memory component (#2545) 2022-08-13 11:23:42 +01:00
David Bereza f40cfdda82 feat(sync): Add additional context option to sync (#2544) 2022-08-11 13:09:25 +08:00
Arvin 51250bf248 fix: Fix a logic judgment bug. (#2540)
Signed-off-by: Arvin <1458070668@qq.com>
2022-08-02 17:54:51 +01:00
Arvin 63a9b94820 support use of listen options (#2536)
* feat: support use of listen options

* style: Adjust the import order of packages.
2022-07-30 10:56:14 +01:00
Asim Aslam adcc1761d0 Update README.md 2022-07-24 06:39:24 +01:00
Asim Aslam cc53b5e7d7 Update README.md 2022-07-23 11:25:07 +01:00
asim 4d63d61c20 remove function
Run tests / Test repo (push) Waiting to run
2022-07-22 20:12:24 +01:00
asim 678c227061 remove deprecated function 2022-07-22 20:11:27 +01:00
asim ec847fa60c remove generate file 2022-07-22 20:10:06 +01:00
asim 616060876f remove file 2022-07-22 20:08:37 +01:00
asim 641be04fc0 remove plugins dir 2022-07-22 20:07:34 +01:00
Asim Aslam 28f36e8fd6 strip debug handler (#2532)
* strip debug handler

* fix tests
2022-07-22 20:03:27 +01:00
asim a8224e1c67 Merge branch 'master' of ssh://github.com/asim/go-micro 2022-07-22 10:22:58 +01:00
asim 38293f479a strip wrappers for trace/stats 2022-07-22 10:22:50 +01:00
Ak-Army 48eae3b968 Fix http transport panic (#2531)
* [fix] etcd config source prefix issue (#2389)

* http transport data race issue (#2436)

* [fix] #2431 http transport data race issue

* [feature] Ability to close connection while receiving.
Ability to send messages while receiving.
Icreased r channel limit to 100 to more fluently communication.
Do not dropp sent request if r channel is full.

* [fix] Read buff before reset it, when the connection is closed

Co-authored-by: Johnson C <chengqiaosheng@gmail.com>
Co-authored-by: Hunyadvári Péter <peter.hunyadvari@vcc.live>
2022-07-22 08:40:58 +01:00
Asim Aslam e28f5b97f6 Update README.md 2022-07-20 10:34:27 +01:00
Asim Aslam 140f90b354 Update README.md 2022-07-20 10:12:05 +01:00
Asim Aslam 467c8a34e3 Update README.md 2022-07-18 11:40:43 +01:00
Ak-Army 582e3f9310 Http transport stream (#2529)
* [fix] etcd config source prefix issue (#2389)

* http transport data race issue (#2436)

* [fix] #2431 http transport data race issue

* [feature] Ability to close connection while receiving.
Ability to send messages while receiving.
Icreased r channel limit to 100 to more fluently communication.
Do not dropp sent request if r channel is full.

Co-authored-by: Johnson C <chengqiaosheng@gmail.com>
Co-authored-by: Hunyadvári Péter <peter.hunyadvari@vcc.live>
2022-07-15 11:04:41 +01:00
Asim Aslam 98375c7ae5 api honours naming convention of other interfaces 2022-07-11 15:49:30 +01:00
Asim Aslam 7e903d80b6 Update README.md 2022-07-11 15:41:03 +01:00
Asim Aslam 6cf2b02f0f move cmd to util (#2527)
* move cmd to util

* go fmt
2022-07-11 14:37:34 +01:00
Asim Aslam b36949f2c1 Update README.md 2022-07-11 13:08:54 +01:00
Asim Aslam 995abaaea6 go mod tidy 2022-07-11 09:51:48 +01:00
Asim Aslam 97d59fbf78 remove generator and move to github.com/go-micro 2022-07-11 09:11:59 +01:00
Asim Aslam ff1312438c Update README.md 2022-07-07 12:49:56 +01:00
Asim Aslam edaa353826 strip body from gateway 2022-07-04 10:15:14 +01:00
Asim Aslam 48d6650f28 rename api to gateway 2022-07-02 14:42:12 +01:00
Asim Aslam 3381a9f3db Remove body from endpoint 2022-07-02 14:38:58 +01:00
Asim Aslam 63d1f9de4a minor changes 2022-07-02 14:25:21 +01:00
Asim Aslam e313863a2a make router configurable in api 2022-07-02 14:15:02 +01:00
Asim Aslam 73dc3723c7 Update api.go 2022-07-02 13:50:45 +01:00
Asim Aslam 667ee9b85e rename field to Versions 2022-07-02 12:35:57 +01:00
Asim Aslam b6b866c0b2 api package (#2522)
* api gateway

* add comment
2022-07-02 12:11:59 +01:00
Johnson C 28298a30e4 feat: remove plugins and related docs (#2521)
* feat: redis implementation of cache

* Revert "feat: redis implementation of cache"

This reverts commit 4b3f25c1fc494d934613992d8a762024fafad7b6.

* feat: remove plugins
2022-07-02 10:25:57 +01:00
Johnson C b884a68347 feat: update out of date docs (#2520)
Run tests / Test repo (push) Waiting to run
* feat: redis implementation of cache

* Revert "feat: redis implementation of cache"

This reverts commit 4b3f25c1fc494d934613992d8a762024fafad7b6.

* feat: update out of date docs
2022-07-02 08:44:32 +01:00
Asim Aslam bfcdfc3c7f remove m3o
Run tests / Test repo (push) Waiting to run
2022-07-01 11:37:13 +01:00
Asim Aslam 392610022a Update README.md 2022-07-01 08:38:57 +01:00
Asim Aslam 34a51c9f29 Update README.md 2022-07-01 08:34:20 +01:00
Asim Aslam a5fb3fab66 Update README.md 2022-07-01 08:33:53 +01:00
JellyTony 96576a612a feat(web): add start and stop functions to the web (#2519) 2022-07-01 08:06:27 +01:00
Thomas Chandelle 87c96bc4d0 Correctly check error on redis command XTRIM (#2518)
Also:
 - add comment about version requirement
 - move minID to var for code readability
2022-06-30 18:24:27 +08:00
JellyTony 65a2e4ed02 fix(registry): fix watch services only first time (#2517) 2022-06-29 08:49:22 +01:00
Abdul Hadi 9960cd1d36 typo siza #2429 (#2515) 2022-06-24 19:18:47 +01:00
David Brouwer 107bd74187 fix: allow event subscribers to use pointers (#2514)
When a subscriber would use a pointer as event type, panics would occur.
2022-06-22 09:01:13 +08:00
Johnson C 7a6a2b6373 feat: redis implementation of cache (#2513)
* feat: redis implementation of cache

* Revert "feat: redis implementation of cache"

This reverts commit 4b3f25c1fc494d934613992d8a762024fafad7b6.

* feat: redis implementation of cache
2022-06-21 20:05:00 +01:00
Asim Aslam cf51ddeb26 Update README.md 2022-05-30 08:50:02 +01:00
Asim Aslam 13b76331ec Update README.md
Run tests / Test repo (push) Waiting to run
2022-05-11 09:55:41 +01:00
Asim Aslam de0b456b46 Update README.md 2022-05-10 06:59:08 +01:00
yulian 072547201c remove unused variable in loop (#2495) 2022-05-03 11:06:13 +08:00
bosima 8293988499 fix: consume and publish blocked after rabbitmq reconnecting (#2492)
* Support direct generation of grpc method when package and service names of proto files are different.

* fix req.Interface() return nil.

* Get rid of dependence on 'Micro-Topic'

* Revert "Get rid of dependence on 'Micro-Topic'"

This reverts commit 3ff69443364d39f5fda3a32fc2249826e2d207dd.

* Revert "fix req.Interface() return nil."

This reverts commit 90a1b34195e07772fa6f2074e1cf22237ac2a87f.

* Revert "Revert "fix req.Interface() return nil.""

This reverts commit e64737b7da8d1767c4456881f6730f1c196cea60.

* Revert "Revert "Get rid of dependence on 'Micro-Topic'""

This reverts commit 141bb0a557c81cb6d1c651b085b3e65483d5e681.

* fix: consume and publish blocked after reconnecting

Co-authored-by: maxinglun <maxinglun@zhijiaxing.net>
2022-04-28 17:55:06 +08:00
Asim Aslam 367771923c Update README.md 2022-04-19 15:47:45 +01:00
Asim Aslam 4ca75f3ab3 Update README.md 2022-04-19 15:47:31 +01:00
Asim Aslam 4a7c16419e Update README.md 2022-04-19 15:31:23 +01:00
Asim Aslam 1d396bdd64 Update README.md 2022-04-19 15:31:11 +01:00
Sergey Galkin ca807e36c5 option to disable file watcher (#2485)
Co-authored-by: Sergey Galkin <v.sergey.galkin@reddit.com>
2022-04-18 19:30:14 +01:00
Asim Aslam cce02927e7 Update README.md 2022-04-18 19:20:45 +01:00
Wang 034ba9a0de typo fix; (#2480) 2022-04-15 09:55:30 +08:00
bosima 1919048c8f Support direct generation of grpc method (#2474)
* Support direct generation of grpc method when package and service names of proto files are different.
* fix req.Interface() return nil.
2022-04-10 22:12:39 +08:00
Asim Aslam 62c2981baf remove cli 2022-04-07 11:46:07 +01:00
Asim Aslam efa2c4f2d2 remove dashboard 2022-04-07 11:45:58 +01:00
Asim Aslam 27b98c450e Remove examples 2022-04-07 11:45:39 +01:00
Asim Aslam e8604f065c remove services 2022-04-07 11:45:22 +01:00
Asim Aslam aaca7c27da Update README.md 2022-04-07 11:44:47 +01:00
Asim Aslam 664ee31b1a Update README.md 2022-04-07 08:20:57 +01:00
Wang 6dedee5d8c Add header suppor for Kafka broker plugin; (#2470) 2022-04-04 19:54:19 +01:00
Wang d1806e2883 Fix codec/bytes (#2466)
* Update marshaler.go

Byes codec always return error "invalid message" now.

* Update go.mod

Update package name

* Update go.mod
2022-04-02 18:11:12 +01:00
Morya 1f086a3002 fix https://github.com/asim/go-micro/issues/2344 (#2462)
fix https://github.com/asim/go-micro/issues/2344
2022-04-01 07:10:51 +01:00
Muhammad Iqbal Alaydrus 73eda3346d Add Wait option support for sync/etcd plugins (#2459)
* Add Wait support for sync/etcd plugins

* Use ErrLockTimeout if context deadline exceeded
2022-03-25 10:28:19 +08:00
Chris Moran c6d352c832 #2453 Fix with associated test update (#2454) 2022-03-17 10:22:05 +08:00
baerwang 356448017f style:arrays pre-allocation (#2449) 2022-03-14 14:03:14 +08:00
dependabot[bot] d6a74c1a8e Bump github.com/nats-io/nats-server/v2 in /plugins/events/natsjs (#2447)
Bumps [github.com/nats-io/nats-server/v2](https://github.com/nats-io/nats-server) from 2.6.2 to 2.7.4.
- [Release notes](https://github.com/nats-io/nats-server/releases)
- [Changelog](https://github.com/nats-io/nats-server/blob/main/.goreleaser.yml)
- [Commits](https://github.com/nats-io/nats-server/compare/v2.6.2...v2.7.4)

---
updated-dependencies:
- dependency-name: github.com/nats-io/nats-server/v2
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-03-14 12:02:12 +08:00
Willy Kloucek e5a35d38f9 fix natsjs syntax error, remove TODOs and enable tests (#2446) 2022-03-11 16:03:35 +08:00
Willy Kloucek a2f6fac852 add NATS JetStream events plugin (#2433)
* add NATS JetStream plugin

* add notes about de-duplication and inprogress call

* fix typo
2022-03-04 14:53:15 +00:00
Ak-Army dca3a3b553 [fix] http transport deadlock (#2441)
Co-authored-by: Hunyadvári Péter <peter.hunyadvari@vcc.live>
2022-02-24 09:32:09 +00:00
AlkaidChen 4154ed6a80 add tls option for sync etcd plugin (#2440) 2022-02-24 17:07:14 +08:00
Chris Moran 69b4b5d1c6 Support for -micro_out=module=<module_prefix> for protoc-gen-micro (#2435) 2022-02-23 13:14:50 +08:00
Asim Aslam d47c2d984b add new services 2022-02-16 08:43:36 +00:00
Asim Aslam 91cfd18373 Update README.md 2022-02-16 08:35:22 +00:00
Asim Aslam 9e0be6c85d add service updates (#2418)
Run tests / Test repo (push) Waiting to run
2022-01-18 15:27:36 +00:00
Asim Aslam 23f1de80c5 Update README.md 2022-01-17 13:35:01 +00:00
Asim Aslam 6bc97c16ee Update README.md 2022-01-17 13:34:30 +00:00
Asim Aslam a612e09a34 Add files via upload 2022-01-15 20:26:27 +00:00
Asim Aslam 1e2d197c7d default the content type to json (#2412) 2022-01-11 13:36:20 +00:00
Asim Aslam 3a999a0db6 Add files via upload 2022-01-11 12:07:54 +00:00
Asim Aslam b8c2eb2b28 Update README.md 2022-01-11 08:35:55 +00:00
Asim Aslam 6f15174a2f Update README.md 2022-01-11 08:35:16 +00:00
Asim Aslam 748fb39cac Add files via upload 2022-01-11 08:34:58 +00:00
simon 5f2251cfad Add Kafka asynchronous send support (#2409)
* Add Kafka asynchronous send support

* Add Kafka asynchronous send support

* Upgrade sarama to 1.30.1

* Example
2022-01-09 14:12:10 +00:00
Amir Khazaie ef7528ebdb use read lock and unlock instead of write ones (#2410)
Co-authored-by: Amir Khazaie <a.khazaie@digikala.com>
2022-01-09 10:20:08 +00:00
Asim Aslam 696a0ba714 Merge branch 'master' of ssh://github.com/asim/go-micro 2022-01-03 11:21:29 +00:00
Asim Aslam 267da35259 move the api client 2022-01-03 11:21:20 +00:00
Asim Aslam d152870bdb Update client_test.go 2021-12-31 12:39:12 +00:00
Asim Aslam da41ab146e switch services client 2021-12-31 10:11:49 +00:00
Asim Aslam 757d0fe343 fix client 2021-12-30 09:47:40 +00:00
Asim Aslam c8d94c44f0 remove the client 2021-12-30 09:42:08 +00:00
Asim Aslam 5fa6e89f4f fix go mod 2021-12-30 09:35:21 +00:00
Asim Aslam 85f1c44000 Delete go.sum 2021-12-30 08:58:45 +00:00
Asim Aslam 3ba69f11ff Delete go.mod 2021-12-30 08:58:34 +00:00
Asim Aslam af5e70a1d6 add service interfaces 2021-12-30 08:44:34 +00:00
Johnson C 5fe884e59f [FEATURE] add changelog (#2400)
change logs for release history
2021-12-29 11:01:40 +08:00
isfk 415016c6e4 nats config plugin (#2397) 2021-12-28 11:27:36 +08:00
Asim Aslam e0de23c546 Update and rename m3o.go to services.go 2021-12-24 11:43:20 +00:00
Asim Aslam 7af0eb4b7a Update services/ (#2392) 2021-12-21 13:18:29 +00:00
isfk 8e52761edb fix context value nil (#2391) 2021-12-20 16:31:48 +08:00
Johnson C 37de747d19 [fix] nats deregister issue (#2384)
Run tests / Test repo (push) Waiting to run
2021-12-10 19:32:21 +08:00
Johnson C a40f6e8fae [fix] fixing f.IsExported undefined issue (#2382)
IsExported needs go1.17, replace with PkgPath
2021-12-07 17:30:48 +08:00
Johnson C b00c8368b9 [feat] dashboard update (#2381)
* [feature] dashboard update
2021-12-07 10:42:31 +08:00
Ak-Army 97f169c424 fix http_transport Recv and Close race condition on buff (#2374)
fix rpc_stream panic override with the "Unlock of unlocked RWMutex" panic

Co-authored-by: Hunyadvári Péter <peter.hunyadvari@vcc.live>
2021-12-05 11:56:17 +00:00
Ak-Army 81244a41f1 Extend client mock with ability to test publish, and a few useful method like SetResponse and SetSubscriber (#2375)
Co-authored-by: Hunyadvári Péter <peter.hunyadvari@vcc.live>
2021-12-05 11:55:54 +00:00
JeffreyBool 229b369702 [fix] update protoc-gen-micro install doc 2021-12-04 12:52:02 +08:00
Johnson C c0e0b2b225 [FEATURE] dashboard support publish messages (#2373)
* [feature] dashboard

* [feat] support publish message
2021-12-02 13:15:38 +08:00
Johnson C 1e4dd94b71 [fix] zookeeper registry delete event (#2372)
* [fix] #2358 zookeeper delete event
2021-12-01 16:26:31 +08:00
zhaoyang b25d744f5c feat: delete redundant lines (#2364) 2021-11-24 17:41:54 +00:00
zhaoyang 685f9979a1 feat: modify the dependencies urls (#2363) 2021-11-24 16:43:05 +00:00
Asim Aslam 6fc5e45626 Update README.md 2021-11-24 07:32:51 +00:00
Asim Aslam 2c6515152a Update load.go 2021-11-24 07:32:20 +00:00
Johnson C 70d2bd8a6b [feature] dashboard (#2361) 2021-11-24 11:27:23 +08:00
Johnson C 90b3e4af0b [fix] ignore unexported field (#2354)
ignore unexported field when register endpoints
2021-11-18 17:07:00 +08:00
Niek den Breeje 4f1a571704 Fix Micro CLI's proto comments (#2353) 2021-11-18 06:10:43 +01:00
陈杨文 799b8d6a65 upgrade to go 1.17 (#2346)
Run tests / Test repo (push) Waiting to run
2021-11-11 14:03:34 +00:00
Asim Aslam 8e312801a1 Update README.md 2021-11-08 09:03:37 +00:00
Asim Aslam 335c4e54a1 Merge branch 'master' of ssh://github.com/asim/go-micro 2021-11-08 09:01:56 +00:00
Asim Aslam e6d17257b0 add nats and redis events plugins 2021-11-08 08:59:14 +00:00
Asim Aslam 0c2041e439 add events package (#2341)
* add events package

* update go version
2021-11-08 08:52:39 +00:00
Johnson C c5be9f560c fix(#2333): etcd grpc marshal issue (#2334)
make protocodec compatible with legacy proto message type
2021-11-03 10:58:05 +08:00
Asim Aslam 62b985f49c Update README.md 2021-11-01 21:44:52 +00:00
Asim Aslam 2b9a6f9aeb flatten cli (#2332)
Run tests / Test repo (push) Waiting to run
2021-11-01 14:34:09 +00:00
Asim Aslam 3c70d23a1d m3o client changed 2021-11-01 11:00:21 +00:00
Asim Aslam adaa98e6cf use vanity url for cli command 2021-11-01 09:00:14 +00:00
无相 ed90a65783 fix broker nsq plugin nil pointer error (#2329)
Co-authored-by: longhaoteng <longhaoteng@kingsoft.com>
2021-11-01 08:47:22 +00:00
无相 268278c53e fix config json slice parsing (#2330)
Co-authored-by: longhaoteng <longhaoteng@kingsoft.com>
2021-11-01 08:47:00 +00:00
Benjamin 5d5aee1f08 replace ioutil with io and os (#2327)
set the go version to 1.16 in pr.yml and tests.yml, so as to be consistent with the version in go.mod.
2021-10-30 19:24:40 +01:00
Johnson C ed690ed838 fixing #2308 (#2326)
IPV6 too many colons in address
net.SplitHostPort need ipv6 address in [host]:port format
2021-10-28 17:03:48 +08:00
Niek den Breeje e155029a4b Fix Micro CLI by removing replace line in go.mod 2021-10-27 17:40:26 +02:00
Asim Aslam 880d751df4 Update README.md 2021-10-27 16:34:55 +01:00
Niek den Breeje a3202b00ee Rename gomu to micro (#2325)
* Rename Gomu to Micro

* docs: Remove license reference in CLI's README
2021-10-27 16:31:29 +01:00
Asim Aslam efcda9a48c Update README.md 2021-10-26 20:17:07 +01:00
Asim Aslam 2c73c7fcf3 strip protoc-gen-micro go mod 2021-10-26 19:46:25 +01:00
Johnson C d2a51d05c4 [feature] stream CloseSend (#2323)
* support stream CloseSend

* move CloseSend into Closer
2021-10-26 15:07:08 +01:00
Johnson C af3cfa0a4c remove unnecessary dependencies between plugins
remove unnecessary dependencies between plugins
upgrade go-micro.dev/v4 to v4.2.1
2021-10-23 16:20:42 +08:00
Johnson C f96b48dad9 1. use default memory registry in grpc plugins (#2317)
2. try fixing grpc plugin failed to get issue
use v4.0.0-v4.0.0-00010101000000-000000000000 instead of specific version
3. kafka panic on disconnect
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x18 pc=0x1266c50]

goroutine 31 [running]:
github.com/asim/go-micro/plugins/broker/kafka/v3.(*kBroker).Disconnect(0xc0002400c0)
        C:/Workshop/Go/pkg/mod/github.com/asim/go-micro/plugins/broker/kafka/v3@v3.7.0/kafka.go:130 +0xd0
github.com/asim/go-micro/plugins/server/grpc/v3.(*grpcServer).Start.func2()
        C:/Workshop/Go/pkg/mod/github.com/asim/go-micro/plugins/server/grpc/v3@v3.0.0-20210712061837-0532fd9de8ae/grpc.go:998 +0xc8d
created by github.com/asim/go-micro/plugins/server/grpc/v3.(*grpcServer).Start
        C:/Workshop/Go/pkg/mod/github.com/asim/go-micro/plugins/server/grpc/v3@v3.0.0-20210712061837-0532fd9de8ae/grpc.go:917 +0xcaf
exit status 2
2021-10-22 22:30:28 +08:00
Niek den Breeje 9edc569e68 Add update rule to Makefile (#2315)
I realized that when writing `require go-micro.dev/v4 v4.1.0` in the
`go.mod` file, `go mod tidy` will install that exact version of
`go-micro.dev/v4`. As of right now, v4.1.0 is an outdated version, and
preferably we shouldn't be updating gomu's Go Modules template everytime
a new release is tagged, but still want gomu users to generate projects
using the latest Go Micro version.

In an attempt to solve this problem, I'm opting to add a new Makefile
rule for new projects generated by gomu, `update` that runs `go get -u`.
This aggressively updates any dependencies your Go Modules project may
have.  `go mod tidy` is then able to prune the `go.mod` and `go.sum`
files by removing the unnecessary checksums and transitive dependencies
(e.g. `// indirect`), that were added to by go get -u due to newer
semver available.

Put one and one together and you get two. In addition to adding an
`update` rule to the Makefile generated for new projects by gomu, I'm
also updating the proto and client comments printed when new projects
have been generated to promote the `update` rule.

References:

- https://stackoverflow.com/questions/67201708/go-update-all-modules
2021-10-19 21:12:42 +02:00
Johnson C 29fefbad4e Plugins (#2311)
* release plugins

* add window plugins release bat script

Co-authored-by: Johnson C <johnson.cheng@scenestek.com>
2021-10-16 05:56:51 +01:00
Asim Aslam 9f4770e7fd fix generation (#2312)
Run tests / Test repo (push) Waiting to run
2021-10-15 14:03:40 +01:00
Asim Aslam e7dbda689e fix gomu
Run tests / Test repo (push) Waiting to run
2021-10-14 08:09:21 +01:00
Asim Aslam 00f461141a fix examples go mod
Run tests / Test repo (push) Waiting to run
2021-10-13 13:37:24 +01:00
Asim Aslam 8cad88edae update go sums 2021-10-13 13:35:17 +01:00
Asim Aslam 62801c3d68 update 2021-10-13 13:31:23 +01:00
Asim Aslam 7136c61dbd rename to go-micro.dev 2021-10-13 09:52:05 +01:00
Asim Aslam a87f9a808c move to go-micro.dev 2021-10-13 09:44:24 +01:00
Asim Aslam ca594b922c Merge branch 'master' of ssh://github.com/asim/go-micro 2021-10-13 09:42:31 +01:00
Asim Aslam aa4a87ed9a move to v4 in protoc-gen-micro 2021-10-13 09:42:21 +01:00
justcy 690facdb5c update model template (#2307) 2021-10-13 08:07:48 +01:00
Asim Aslam f63e46a7d1 use 4.1.0 2021-10-12 13:22:08 +01:00
Asim Aslam 1cd7cfaa6c go-micro.dev/v4 (#2305)
Run tests / Test repo (push) Waiting to run
2021-10-12 12:55:53 +01:00
jxlwqq d9a6faeb7a Add latest version (#2303)
Run tests / Test repo (push) Waiting to run
2021-10-11 15:15:42 +01:00
Asim Aslam 4cb6168780 Update README.md 2021-10-11 09:21:06 +01:00
Asim Aslam b8d7f87d17 remove file 2021-10-11 09:19:20 +01:00
Asim Aslam b2e17a89e5 rename file 2021-10-11 09:19:01 +01:00
Asim Aslam 4ae2528cbe add m3o services (#2301)
* add m3o services

* update readme
2021-10-11 09:18:28 +01:00
Asim Aslam 043a82bce2 Update README.md 2021-10-11 08:38:31 +01:00
Asim Aslam 99e0b182b7 Update README.md 2021-10-11 08:38:07 +01:00
Asim Aslam ab1b10f13d Update README.md 2021-10-11 08:37:38 +01:00
jxlwqq 86eabf4a4c Use go install (#2300)
go get: installing executables with 'go get' in module mode is deprecated.
        To adjust and download dependencies of the current module, use 'go get -d'.
        To install using requirements of the current module, use 'go install'.
        To install ignoring the current module, use 'go install' with a version,
        like 'go install example.com/cmd@latest'.
        For more information, see https://golang.org/doc/go-get-install-deprecation
        or run 'go help get' or 'go help install'.
2021-10-11 06:32:13 +01:00
Qalifah a99a1e9356 add MultiError type (#2297) 2021-10-06 17:55:14 +01:00
Asim Aslam 2ef523a7eb Delete index.html 2021-10-02 13:13:22 +01:00
Asim Aslam a1da40d9aa Delete CNAME 2021-10-01 20:23:38 +01:00
Defoo Li a315fc2dda Fix missing content type (#2289) 2021-09-30 12:15:09 +01:00
Johnson C 6dc25053ea Errors (#2290)
* add errors.As

convert target err to *Error, return false if err don't match *Error

* update errors.As to (*Error, bool)

* fixing FromError panic issue when err is nil
2021-09-30 07:45:10 +01:00
Qiu Yu 4612baa7f8 zap plugin: allow injecting zap logger options (#2287)
Though some of the Zap logger option can be customized through
plugins/logger/zap.Options, this change allows go.uber.org/zap.Option be
be injected directly for deeper customization.
2021-09-29 07:12:16 +01:00
Johnson C 44ecd6a457 Hystrix filter (#2286)
* support hystrix filter

* filter function should return true of false
2021-09-28 11:23:04 +01:00
Asim Aslam 8c39b1e120 Update index.html 2021-09-24 09:10:04 +01:00
Asim Aslam 12eff1cc60 go fmt 2021-09-24 09:08:39 +01:00
Asim Aslam 9deb715ebb Update go.mod 2021-09-24 09:08:16 +01:00
Arsen 3b60db0dcd logger helper: add "inject" method, to make a pair with "extract" (#2283) 2021-09-23 16:48:08 +01:00
Asim Aslam af22cbb108 Update README.md 2021-09-22 14:48:20 +01:00
Asim Aslam 9d7131a512 Update README.md 2021-09-22 14:43:37 +01:00
Asim Aslam bca9ab165d Update README.md 2021-09-22 14:42:17 +01:00
Asim Aslam d111f96993 Update README.md 2021-09-22 14:41:29 +01:00
Asim Aslam 2f223c276c Update README.md 2021-09-22 14:32:06 +01:00
Asim Aslam 33acb4a956 update readme 2021-09-22 14:31:21 +01:00
Asim Aslam b515785637 add services dir 2021-09-22 14:30:40 +01:00
Asim Aslam 3dcdcdad32 Update README.md 2021-09-22 13:37:07 +01:00
Arsen 916ed6b8ee logger: caller's skip correction (#2280) 2021-09-22 09:01:03 +01:00
gregkv b8fbe87e1f Use context to log "panic recovered" errors in grpc-server plugin (#2278) 2021-09-20 10:50:13 +01:00
Asim Aslam cb3db7dd83 Update options.go 2021-09-19 17:22:28 +01:00
simon 066ce5045b Command Option add NewConfig,NewProfile func (#2276)
* Add grpc,memory,quic transport automatically discover

* Add grpc,memory,quic transport automatically discover

* Add jwt auth automatically discover

* Add jwt auth automatically discover

* Add config command option automatically discover

* Add AuthCall wrapper func

* Add NewConfig func

* Add NewProfile func
2021-09-19 17:21:55 +01:00
Asim Aslam a65932ff82 Create CNAME 2021-09-19 15:10:47 +01:00
Asim Aslam 5496086916 Create index.html 2021-09-19 14:44:03 +01:00
Kurisu_Amatist efd4ef0e62 fix(cache): only watch calling service in registry (#2273) 2021-09-19 10:40:21 +01:00
gregkv 00d819a199 Remove fields map from Helper, add Extract method and fix for defaultLogger.Fields (#2274) 2021-09-19 10:40:09 +01:00
helloword ad532522ea Config CORS (#2270)
* Added cors.config for CORS

* Added cors.config for CORS

* Added cors.config for CORS

Co-authored-by: 于海洋 <yhy@iothinking.com>
2021-09-17 10:17:12 +01:00
Christoffer Åström 4c7d2e28eb test(api): fix randomly failing rpc test (#2268) 2021-09-13 21:56:36 +01:00
Branden Horiuchi d78d35078c Consul sync plugin (#2267)
* adding consul sync provider

* adding logging options

Co-authored-by: Branden Horiuchi <Branden.Horiuchi@blackline.com>
2021-09-13 19:08:05 +01:00
Johnson C 22409c8ff3 support hystrix filter (#2265) 2021-09-13 09:23:26 +01:00
binbin.zhang 6c3a5c161f upgrade nacos sdk version (#2264)
Co-authored-by: binbin <binbin@didiglobal.com>
2021-09-12 22:16:46 +01:00
Niek den Breeje fa27250605 Add generate kubernetes command (#2261) 2021-09-10 18:56:51 +01:00
Niek den Breeje ac21bb5b19 Document Gomu's generator package (#2262) 2021-09-10 18:48:09 +01:00
Niek den Breeje 5b8d22a463 Add Kubernetes flag to new command (#2263)
To remain consistent with the Gomu's generate command, we add a
Kubernetes flag to Gomu's new command as well.
2021-09-10 18:47:55 +01:00
Niek den Breeje 56d5143557 Document Gomu's generate command (#2260) 2021-09-10 14:30:46 +01:00
Niek den Breeje 5772697752 Make generator package a first class citizen (#2259)
There's really no point in having the `generator` be embedded in a
`file` package so we remove the `file` package and make the `generator`
package a first class citizen instead.
2021-09-10 13:31:52 +01:00
Niek den Breeje e23006b1a5 Generate Gomu files after the fact (#2258)
* Move file generation to new package

* Use text/template instead of html/template

* Make config variables more consistent

* Combine generate files and print comments there

* Add gomu generate command

* Refactor project templating to file library

* Determine client earlier
2021-09-10 13:20:57 +01:00
Niek den Breeje 01b7b4409b Fix generating Dockerfile with Gomu (#2254)
Somehow I didn't test this and managed to forget to properly close a
template control structure. This change fixes that.
2021-09-08 14:43:52 +01:00
Niek den Breeje 0dd6afe128 Optimize Dockerfile generated by Gomu (#2253)
This change prevents having to rebuild the entire Docker image when your
source code changes.
2021-09-08 12:50:30 +01:00
Niek den Breeje a36f52c6d2 Fix Gomu's call response (#2251)
Gomu expects a `map[string]string` type response back, but this isn't
always the case. When Gomu calls a service endpoint that responds with,
let's say, a key where its value is a map or a list, Gomu would be
unable to decode that response. By expecting a `map[string]interface{}`
type response, Gomu is able to decode those responses as well.
2021-09-08 08:30:53 +01:00
simon 440aa4a1ce Add AuthCall wrapper func (#2250)
* Add grpc,memory,quic transport automatically discover

* Add grpc,memory,quic transport automatically discover

* Add jwt auth automatically discover

* Add jwt auth automatically discover

* Add config command option automatically discover

* Add AuthCall wrapper func
2021-09-07 07:13:56 +01:00
Niek den Breeje f77c91b7ae Simplify gomu cmd registering (#2249)
* Use internal runtime package for gomu run

This change refactors the `gomu run` command to use Go Micro's internal
runtime package in order to run services. Not only does this clean up
duplicate functionality between Go Micro and Gomu, but also adds the
feature to Gomu to run remote projects. For example, the following
command pulls in a remote project and runs it locally.

```bash
gomu run github.com/auditemarlow/helloworld
```

The `gomu run` command remains backwards compatible. By invoking `gomu
run` in a Go Micro project directory, Gomu will simply run that project.

* Simplify Gomu's command registering

By leveraging Go's `init()` function, we can simplify registering
commands just a tad.
2021-09-06 14:12:27 +01:00
Niek den Breeje a58b8883f8 Use internal runtime package for gomu run (#2248)
This change refactors the `gomu run` command to use Go Micro's internal
runtime package in order to run services. Not only does this clean up
duplicate functionality between Go Micro and Gomu, but also adds the
feature to Gomu to run remote projects. For example, the following
command pulls in a remote project and runs it locally.

```bash
gomu run github.com/auditemarlow/helloworld
```

The `gomu run` command remains backwards compatible. By invoking `gomu
run` in a Go Micro project directory, Gomu will simply run that project.
2021-09-06 14:01:29 +01:00
simon 270d910b73 Add config command option automatically discover (#2246)
* Add grpc,memory,quic transport automatically discover

* Add grpc,memory,quic transport automatically discover

* Add jwt auth automatically discover

* Add jwt auth automatically discover

* Add config command option automatically discover
2021-09-04 07:17:21 +01:00
Niek den Breeje 77bf39f2cd Fix client gRPC plugin (#2245)
The helloworld examples found in the `google.golang.org/grpc/examples`
package were imported multiple times as different versions, resulting in
package conflicts. By running `go mod tidy`, these conflicts are
resolved and the gRPC client plugin can now be imported again.
2021-09-03 14:16:56 +01:00
Niek den Breeje c45073a308 Fix Skaffold pipelines for client projects (#2244)
* Update greeter references to helloworld

* Add new client command

With this change, Gomu users will be able to generate template projects
for clients to services. Additionally vendor support has been built in
so Gomu users can now generate projects using fully qualified package
names, for example:

```bash
gomu new service github.com/auditemarlow/helloworld
```

This will create a new service project `helloworld` with its module name
already set to `github.com/auditemarlow/helloworld`. Likewise, Gomu
users can then generate client projects in the same manner:

```bash
gomu new client github.com/auditemarlow/helloworld
```

This will create a `helloworld-client` project that uses the protobufs
found in the `github.com/auditemarlow/helloworld` service. This removes
at least some strain in configuring these module dependencies yourself;
you can just scaffold them outright from the start.

Although the default client project is highly opinionated, it works
straight out of the box and has Skaffold in mind. Gomu users should be
able to get going in a matter of seconds.

* Update README

* Fix Skaffold pipeline for generated client projects
2021-09-03 13:26:34 +01:00
Niek den Breeje 86de031adc [WIP] Add new client cmd (#2243)
* Update greeter references to helloworld

* Add new client command

With this change, Gomu users will be able to generate template projects
for clients to services. Additionally vendor support has been built in
so Gomu users can now generate projects using fully qualified package
names, for example:

```bash
gomu new service github.com/auditemarlow/helloworld
```

This will create a new service project `helloworld` with its module name
already set to `github.com/auditemarlow/helloworld`. Likewise, Gomu
users can then generate client projects in the same manner:

```bash
gomu new client github.com/auditemarlow/helloworld
```

This will create a `helloworld-client` project that uses the protobufs
found in the `github.com/auditemarlow/helloworld` service. This removes
at least some strain in configuring these module dependencies yourself;
you can just scaffold them outright from the start.

Although the default client project is highly opinionated, it works
straight out of the box and has Skaffold in mind. Gomu users should be
able to get going in a matter of seconds.

* Update README
2021-09-03 12:33:10 +01:00
simon 80dbe51077 Add jwt auth automatically discover (#2242)
* Add grpc,memory,quic transport automatically discover

* Add grpc,memory,quic transport automatically discover

* Add jwt auth automatically discover

* Add jwt auth automatically discover
2021-09-03 07:49:49 +01:00
Johnson C f444dadd50 fixing #2235 win10 install failed issue (#2239) 2021-09-03 07:49:39 +01:00
Christoffer Åström e080791787 chore(gomu): tweak makefile template (#2238) 2021-09-02 18:24:28 +01:00
simon a159598f36 Add grpc,memory,quic transport automatically discover (#2237)
* Add grpc,memory,quic transport automatically discover

* Add grpc,memory,quic transport automatically discover
2021-09-02 18:10:24 +01:00
Niek den Breeje 993e2f55bd Add Kubernetes resources (#2236)
* Refact new command implementation

Everytime I want to add or modify files in the new command, I will have
to do so in 2 places. This change will consolidate functionality so
there's only a single place to modify.

* Move Kubernetes resources to its own file

* Add Kubernetes resources
2021-09-02 13:35:00 +01:00
Niek den Breeje ed9053ed94 Add cache example (#2232) 2021-09-01 10:08:43 +01:00
Niek den Breeje 05a299b76c Add simple in-memory cache (#2231)
* Add simple in-memory cache

* Support configuring cache expiration duration

* Support preinitializing cache with items

* Register cache
2021-08-31 15:31:16 +01:00
Asim Aslam dd0a7746ff update the gomu gomod 2021-08-31 15:19:45 +01:00
Asim Aslam 088ccb5001 Update README.md 2021-08-31 09:27:36 +01:00
Niek den Breeje 4363678e48 Exit when help flag is provided on service run (#2225) 2021-08-31 09:13:35 +01:00
Niek den Breeje 9a77c06b44 Move from micro/cli/v2 to urfave/cli/v2 (#2224)
* Use urfave/cli/v2 instead of micro/cli/v2

Wherever possible we may want to eliminate the use of github.com/micro
imports.

* Fix broken cli test
2021-08-31 09:05:08 +01:00
Niek den Breeje 78bea87690 Add gomu CLI tool (#2223) 2021-08-30 15:48:57 +01:00
Johnson C 49eccbc85a fixing proto3 optional unsupported error (#2213)
add supported features
2021-08-24 08:14:33 +01:00
Asim Aslam 7f1ebaa572 Update README.md 2021-08-23 16:45:04 +01:00
Qiu Yu c7195aae98 Grpc server injection (#2208)
Run tests / Test repo (push) Waiting to run
* plugin: update grpc server readme

* plugin: refactor gprc server test

This is a no-op change to enable test logic reuse for different
combinations.

* plugin: grpc server test Init after New

* plugin: allow grpc.Server to be injected
2021-08-12 18:26:26 +01:00
Arsen ffb0a2f896 grpc client: fix grpc code to micro http status conversion for the fallback case with empty Details (#2206) 2021-08-12 12:15:49 +01:00
Qiu Yu b977a51253 Examples: fix grpc config (#2207)
This change fixes grpc config example code which is currently broken.

Several pieces in the change:
- use yaml encoder to read config files
- rename *.yml to *.yaml to fix format (file suffix) for encoder lookup
- replace util/log package with logger as the former one is deprecated
2021-08-12 06:27:04 +01:00
dependabot[bot] 046d0785c9 Bump github.com/gin-gonic/gin from 1.6.3 to 1.7.0 in /examples (#2205)
Bumps [github.com/gin-gonic/gin](https://github.com/gin-gonic/gin) from 1.6.3 to 1.7.0.
- [Release notes](https://github.com/gin-gonic/gin/releases)
- [Changelog](https://github.com/gin-gonic/gin/blob/master/CHANGELOG.md)
- [Commits](https://github.com/gin-gonic/gin/compare/v1.6.3...v1.7.0)

---
updated-dependencies:
- dependency-name: github.com/gin-gonic/gin
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-08-11 13:57:15 +01:00
Qiu Yu 828d3f2b74 loader: avoid overwriting values if error happens (#2204) 2021-08-11 13:33:58 +01:00
Qiu Yu a46dc0b856 Add yaml config example (#2203)
* examples: add yaml config

* examples: update go mod for yaml plugin
2021-08-11 13:31:29 +01:00
Johnson C 3e0411a3f6 fixing mem.pprof issue: (#2198)
parsing profile: concatenated profiles detected
fixing web service not start profile issue
fixing no default profile options issue
2021-08-04 09:39:01 +01:00
bacndcmc c3107e6843 fix code proto return invalid message (#2196)
Co-authored-by: ben <norton0395@gmail.com>
2021-07-26 06:25:21 +01:00
Asim Aslam e1bc7e3028 Update README.md 2021-07-21 09:06:34 +01:00
Asim Aslam 992418236e Update README.md 2021-07-21 09:05:38 +01:00
Asim Aslam 27a792790b Update README.md 2021-07-21 09:05:20 +01:00
Asim Aslam bd9821111e remove tidy file 2021-07-19 17:57:33 +01:00
Asim Aslam dbba07e7ed Delete tidy.md 2021-07-19 17:55:08 +01:00
xshytikx 753022d2ae fix: imported and not used (log, os) (#2195)
github.com/asim/go-micro/plugins/registry/consul/v3@v3.0.0-20210716165540-546225f1d8db/watcher.go:5:2: imported and not used: "log"
github.com/asim/go-micro/plugins/registry/consul/v3@v3.0.0-20210716165540-546225f1d8db/watcher.go:5:2: imported and not used: "log"
2021-07-18 07:18:11 +01:00
JeffreyBool 546225f1d8 Not Recommended Function Correction (#2194)
* Update http.go

Exit before deregister is executed

* Create http.go

Exit before deregister is executed

* Solve the problem that the resources have not been fully released due to early exit

* Optimize some code

* Optimize some code

* Optimize some code

* fix service default logger

* Not Recommended Function Correction
2021-07-16 17:55:40 +01:00
JeffreyBool 0532fd9de8 fix logger v3 (#2193)
* Update http.go

Exit before deregister is executed

* Create http.go

Exit before deregister is executed

* Solve the problem that the resources have not been fully released due to early exit

* Optimize some code

* Optimize some code

* Optimize some code

* fix service default logger

* Repair mq asynchronous send, mq write failure without error output

* Repair mq asynchronous send, mq write failure without error output

* fix logger v3
2021-07-12 07:18:37 +01:00
lanrion 3fbf2c304f Optimize prometheus wrapper,removed mutex,initialize MetricVec at init() (#2192)
Co-authored-by: dylan.deng <dylan.deng@yijinin.com>
2021-07-09 12:52:08 +01:00
JeffreyBool 6cdf28270f Repair mq asynchronous send, mq write failure without error output (#2191)
* Update http.go

Exit before deregister is executed

* Create http.go

Exit before deregister is executed

* Solve the problem that the resources have not been fully released due to early exit

* Optimize some code

* Optimize some code

* Optimize some code

* fix service default logger

* Repair mq asynchronous send, mq write failure without error output

* Repair mq asynchronous send, mq write failure without error output
2021-07-09 06:19:09 +01:00
Johnson C 7f1de77e8c try fixing staticcheck warning (#2190)
Run tests / Test repo (push) Waiting to run
https://github.com/golang/protobuf/issues/1077
package github.com/golang/protobuf/proto is deprecated: Use the "google.golang.org/protobuf/proto" package instead.  (SA1019)
2021-07-06 12:51:28 +01:00
Asim Aslam 1c482e8922 add web package 2021-07-06 11:12:19 +01:00
wangYue 70ed9bf154 fix missing error (#2189)
Co-authored-by: wangyue <wangyue@actiontech.com>
2021-06-30 10:13:05 +01:00
Jerry 93ba8cd0df continue fix pre version go get bug that unknown v3.5.1 (#2188)
* 1.fix plugins go get bug.
2.update all mode.
3.add tidy tools

* continue fix pre version go get bug that unknown v3.5.1
2021-06-30 09:24:00 +01:00
Jerry c13bb07171 1.fix plugins go get bug. (#2187)
2.update all mode.
3.add tidy tools
2021-06-30 07:21:03 +01:00
Jerry 4929a7c16e update etcd version (#2186)
Remove missing gRPC example from README.md (#2112)

Delete docker.yml

Delete Dockerfile

update plugins version & remove replace (#2118)

* update memory registry plugins version & remove replace

* update plugins version & remove replace

Co-authored-by: 申法宽 <shenfakuan@163.com>

update client/grpc plugins version & remove replace (#2119)

* update memory registry plugins version & remove replace

* update plugins version & remove replace

* update plugins/client/grpc/v3 version

Co-authored-by: 申法宽 <shenfakuan@163.com>

update etcd version (#2120)

update mod version

update

update pulgin registry mod version (#2121)

* update etcd version

* update mod version

* update

fix store delete

support for tls on http plugin (#2126)

improve code quality (#2128)

* Fix inefficient string comparison

* Fix unnecessary calls to Printf

* Canonicalize header key

* Replace `t.Sub(time.Now())` with `time.Until`

* Remove unnecessary blank (_) identifier

* Remove unnecessary use of slice

* Remove unnecessary comparison with bool

Update README.md

Update README.md

remove network package

update quic go mod

remove indirects

update etcd mod version

Update registry plugins mod version (#2130)

* update etcd version

* update mod version

* update

* update etcd mod version

Update README.md

Update README.md

Update README.md

fixing etcd stack in getToken (#2145)

when provide username and password, etcd will try to get auth token from server
if server is unavailble, etcd client will stack in
when dial timeout is set, it will return err instead of stack in

Update README.md

add http demo; http client can call http server; http client can call rpc server (#2149)

Add etcd to default registries when plugin is loaded (#2150)

Co-authored-by: Andrew Jones <andrew@gotoblink.com>

Update README.md

make rpcClient compatible with 32bit arm systems (#2156)

On ARM, 386, and 32-bit MIPS, it is the caller's responsibility to
arrange for 64-bit alignment of 64-bit words accessed
atomically. Only the first word in an allocated struct can
be relied upon to be 64-bit aligned.

optimize the process of switching grpc error to micro error (#2158)

Fix util/log/log.Infof format didn't work (#2160)

Co-authored-by: Cui Gang <cuigang@yunpbx.com>

fixing string field contains invalid UTF-8 issue (#2164)

fix k8s api memory leak (#2166)

fix http No release Broker (#2167)

* Update http.go

Exit before deregister is executed

* Create http.go

Exit before deregister is executed

fix: "Solve the problem that the resources have not been fully released due to early exit" (#2168)

* Update http.go

Exit before deregister is executed

* Create http.go

Exit before deregister is executed

* Solve the problem that the resources have not been fully released due to early exit

* Optimize some code

* Optimize some code

fix service default logger (#2171)

* Update http.go

Exit before deregister is executed

* Create http.go

Exit before deregister is executed

* Solve the problem that the resources have not been fully released due to early exit

* Optimize some code

* Optimize some code

* Optimize some code

* fix service default logger

Update README.md

get k8s pod (#2173)

Update README.md

fix:field (#2176)

* get k8s pod

* fix: filed

* field

Update README.md

add rmq message properties (#2177)

Co-authored-by: dtitov <dtitov@might24.ru>

Update README.md

grpc server add RegisterCheck (#2178)

fix 404 bug (#2179)

fix undefined: err (#2181)

Add registry and config/source plugins based on nacos/v2 (#2182)

* Add registry plugins implement by nacos/v2

* Add config/source plugins implement by nacos/v2

support hystrix fallback (#2183)

Windows event log plugin (#2180)

* add rmq message properties

* eventlog start

* start eventlog

* windows event logger

* readme

* readme

Co-authored-by: dtitov <dtitov@might24.ru>

support etcd auth with env args (#2184)

* support etcd auth with env args
set default registry address with env arg instead of 127.0.0.1

* fixing MICRO_REGISTRY_ADDRESS may empty issue

update mod version
2021-06-29 13:40:54 +01:00
Johnson C 212df8e6c3 support etcd auth with env args (#2184)
* support etcd auth with env args
set default registry address with env arg instead of 127.0.0.1

* fixing MICRO_REGISTRY_ADDRESS may empty issue
2021-06-23 07:45:01 +01:00
Dmitry Titov 8dc9bf49a1 Windows event log plugin (#2180)
* add rmq message properties

* eventlog start

* start eventlog

* windows event logger

* readme

* readme

Co-authored-by: dtitov <dtitov@might24.ru>
2021-06-20 09:28:30 +01:00
qm012 4daa499912 support hystrix fallback (#2183) 2021-06-20 09:28:15 +01:00
Yusan Kurban 939f346d83 Add registry and config/source plugins based on nacos/v2 (#2182)
* Add registry plugins implement by nacos/v2

* Add config/source plugins implement by nacos/v2
2021-06-18 14:23:03 +01:00
qm012 08216ccf31 fix undefined: err (#2181) 2021-06-17 11:11:38 +01:00
qm012 4deeaff8ad fix 404 bug (#2179) 2021-06-16 07:56:41 +01:00
dudu b892efa25f grpc server add RegisterCheck (#2178) 2021-06-11 09:57:44 +01:00
Asim Aslam 4af9e245fb Update README.md 2021-06-09 10:31:10 +01:00
Dmitry Titov 52bb3845f6 add rmq message properties (#2177)
Co-authored-by: dtitov <dtitov@might24.ru>
2021-06-08 10:34:47 +01:00
Asim Aslam a1e9b88495 Update README.md 2021-06-04 10:17:30 +01:00
biubiubiu-ljd ed44e9acc3 fix:field (#2176)
* get k8s pod

* fix: filed

* field
2021-06-03 07:01:26 +01:00
Asim Aslam 86d8d8f07e Update README.md 2021-06-02 14:02:58 +01:00
biubiubiu-ljd 62112b015f get k8s pod (#2173) 2021-06-02 13:54:02 +01:00
Asim Aslam ca2014bf8e Update README.md 2021-06-01 06:23:33 +01:00
JeffreyBool acc3f5479f fix service default logger (#2171)
* Update http.go

Exit before deregister is executed

* Create http.go

Exit before deregister is executed

* Solve the problem that the resources have not been fully released due to early exit

* Optimize some code

* Optimize some code

* Optimize some code

* fix service default logger
2021-05-23 08:38:20 +01:00
JeffreyBool f48911d2c3 fix: "Solve the problem that the resources have not been fully released due to early exit" (#2168)
* Update http.go

Exit before deregister is executed

* Create http.go

Exit before deregister is executed

* Solve the problem that the resources have not been fully released due to early exit

* Optimize some code

* Optimize some code
2021-05-17 08:16:52 +01:00
JeffreyBool 4c1f81dadb fix http No release Broker (#2167)
* Update http.go

Exit before deregister is executed

* Create http.go

Exit before deregister is executed
2021-05-13 13:07:25 +01:00
Tt yo 32cb1b435b fix k8s api memory leak (#2166) 2021-05-11 08:58:19 +01:00
Johnson C 8c9c7a5927 fixing string field contains invalid UTF-8 issue (#2164) 2021-05-10 11:25:31 +01:00
Cui Gang 9e9157d878 Fix util/log/log.Infof format didn't work (#2160)
Co-authored-by: Cui Gang <cuigang@yunpbx.com>
2021-05-06 06:43:05 +01:00
Scout Wang 1b5d372b5b optimize the process of switching grpc error to micro error (#2158) 2021-04-29 13:03:40 +01:00
Tobias Wellnitz b11a2f17e9 make rpcClient compatible with 32bit arm systems (#2156)
On ARM, 386, and 32-bit MIPS, it is the caller's responsibility to
arrange for 64-bit alignment of 64-bit words accessed
atomically. Only the first word in an allocated struct can
be relied upon to be 64-bit aligned.
2021-04-25 06:54:00 +01:00
Asim Aslam a91d1f7a3d Update README.md
Run tests / Test repo (push) Waiting to run
2021-04-16 17:34:42 +01:00
Andrew 0d57213d3f Add etcd to default registries when plugin is loaded (#2150)
Co-authored-by: Andrew Jones <andrew@gotoblink.com>
2021-04-08 18:31:39 +01:00
orange-jacky 6ae252b892 add http demo; http client can call http server; http client can call rpc server (#2149) 2021-04-08 18:31:15 +01:00
Asim Aslam e7a7e3a050 Update README.md 2021-04-03 08:39:40 +01:00
Johnson C bed53b605f fixing etcd stack in getToken (#2145)
when provide username and password, etcd will try to get auth token from server
if server is unavailble, etcd client will stack in
when dial timeout is set, it will return err instead of stack in
2021-04-01 09:55:21 +01:00
Asim Aslam 9b41d1bf08 Update README.md 2021-03-29 11:33:59 +01:00
Asim Aslam 0a41e6d80f Update README.md 2021-03-17 09:37:20 +00:00
Asim Aslam b636a4bfe3 Update README.md 2021-03-17 07:52:35 +00:00
Jerry df90f2ca63 Update registry plugins mod version (#2130)
* update etcd version

* update mod version

* update

* update etcd mod version
2021-02-27 06:48:44 +00:00
Asim Aslam 0bf3719a9a remove indirects 2021-02-26 08:34:03 +00:00
Asim Aslam bfa9e7c88c update quic go mod 2021-02-26 08:14:11 +00:00
Asim Aslam 57003414be remove network package 2021-02-26 08:13:12 +00:00
Asim Aslam a54f40baa7 Update README.md 2021-02-25 10:32:47 +00:00
Asim Aslam 56c779f9df Update README.md 2021-02-25 10:31:55 +00:00
Shubhendra Singh Chauhan 26b859c4f9 improve code quality (#2128)
* Fix inefficient string comparison

* Fix unnecessary calls to Printf

* Canonicalize header key

* Replace `t.Sub(time.Now())` with `time.Until`

* Remove unnecessary blank (_) identifier

* Remove unnecessary use of slice

* Remove unnecessary comparison with bool
2021-02-25 08:30:35 +00:00
Alex Unger 0f0ace1a44 support for tls on http plugin (#2126) 2021-02-17 18:20:06 +00:00
Asim Aslam f9f5e7422d fix store delete 2021-02-10 07:14:49 +00:00
Jerry 2653e7a977 update pulgin registry mod version (#2121)
* update etcd version

* update mod version

* update
2021-02-08 08:56:39 +00:00
Jerry 55b477ba07 update etcd version (#2120) 2021-02-07 12:15:06 +00:00
isfk 6f666d63c8 update client/grpc plugins version & remove replace (#2119)
* update memory registry plugins version & remove replace

* update plugins version & remove replace

* update plugins/client/grpc/v3 version

Co-authored-by: 申法宽 <shenfakuan@163.com>
2021-02-05 09:50:42 +00:00
isfk e8167a8b79 update plugins version & remove replace (#2118)
* update memory registry plugins version & remove replace

* update plugins version & remove replace

Co-authored-by: 申法宽 <shenfakuan@163.com>
2021-02-05 09:09:25 +00:00
Asim Aslam 0702501552 Delete Dockerfile 2021-02-02 14:58:31 +00:00
Asim Aslam 89fe31310e Delete docker.yml 2021-02-02 14:58:19 +00:00
Josemy Duarte ca3dfc4580 Remove missing gRPC example from README.md (#2112) 2021-01-30 18:13:56 +00:00
francescocarzaniga bba3107ae1 Remove hpcloud/tail in favour of nxadm/tail (#2109)
Docker / build (push) Waiting to run
Run tests / Test repo (push) Waiting to run
2021-01-25 07:51:17 +00:00
Asim Aslam 60010e82e2 update protoc-gen-micro
Docker / build (push) Waiting to run
Run tests / Test repo (push) Waiting to run
2021-01-20 21:36:17 +00:00
Asim Aslam ad94eeb635 Update README.md
Docker / build (push) Waiting to run
Run tests / Test repo (push) Waiting to run
2021-01-20 21:30:26 +00:00
Asim Aslam 88be70a6af Update README.md 2021-01-20 21:30:10 +00:00
Asim Aslam 226833c4ab Update README.md 2021-01-20 21:29:36 +00:00
Asim Aslam 8e3b7a57d9 examples at v3 2021-01-20 21:28:48 +00:00
Asim Aslam dc8236ec05 update v3 plugins (#2105) 2021-01-20 21:01:10 +00:00
Asim Aslam d94936f6c9 v3 (#2104)
* v3

* revert plugins

* fixup some issues
2021-01-20 13:54:31 +00:00
Goober bf4ab679e1 Fix zk watchDir (#2102)
Signed-off-by: Goober <chenhao86899@gmail.com>
2021-01-05 17:32:17 +00:00
Asim Aslam 20b5755788 move encoders out to plugins 2020-12-30 08:46:31 +00:00
Asim Aslam f64ffdbab1 remove indirects in go mod 2020-12-30 08:26:26 +00:00
Asim Aslam eb1e22bd10 strip grpc 2020-12-30 08:21:30 +00:00
Asim Aslam 18fb7a5d62 move certmagic 2020-12-29 20:12:10 +00:00
Asim Aslam ee8b369a19 add initialisers 2020-12-29 16:50:18 +00:00
Asim Aslam f4f6feafb3 remove etcd store 2020-12-29 16:32:06 +00:00
Asim Aslam 9ddfe696a4 go fmt 2020-12-29 16:29:58 +00:00
Asim Aslam 762fff8a51 Merge branch 'master' of ssh://github.com/asim/go-micro 2020-12-29 16:28:21 +00:00
Asim Aslam 36bcd8317b remove micro deps 2020-12-29 16:28:12 +00:00
Asim Aslam 10005db702 Rename default.go to noop.go 2020-12-29 16:24:31 +00:00
Asim Aslam 1b610403ba go mod tidy 2020-12-29 15:50:14 +00:00
Asim Aslam 2fde8a76eb Merge branch 'master' of ssh://github.com/asim/go-micro 2020-12-29 15:49:33 +00:00
Asim Aslam a7c31a0d2b refactor all the things 2020-12-29 15:49:26 +00:00
Asim Aslam 35d72660c8 Update README.md 2020-12-26 15:42:10 +00:00
Asim Aslam d197438e16 Merge branch 'master' of ssh://github.com/asim/go-micro 2020-12-26 15:32:54 +00:00
Asim Aslam 7fc0b7ef72 add all the plugins 2020-12-26 15:32:45 +00:00
Asim Aslam f44b832bac Update README.md 2020-12-26 15:23:06 +00:00
Asim Aslam 5fe144bda8 Update README.md 2020-12-26 15:22:41 +00:00
Asim Aslam df2dab0169 Update README.md 2020-12-26 15:22:14 +00:00
Asim Aslam 7ab46b0850 rename imports 2020-12-26 15:21:29 +00:00
Asim Aslam c3fe6eb3ac update readme 2020-12-26 15:18:11 +00:00
Asim Aslam a34c70de0e Add examples 2020-12-26 15:17:20 +00:00
Asim Aslam 273bab5dd7 update readme 2020-12-26 15:15:39 +00:00
Asim Aslam f8fc9d0304 Add protoc-gen-micro 2020-12-26 15:13:09 +00:00
Hao b5431de2e8 Use singleflight to prevent registry cache breakdown (#2098) 2020-12-21 14:34:59 +00:00
Asim Aslam dc0cac9ba4 Update README.md 2020-12-18 18:45:14 +00:00
Asim Aslam 8628dc0fc4 Update FUNDING.yml 2020-12-13 08:18:02 +00:00
Asim Aslam b57f56fb0b Merge branch 'master' of ssh://github.com/asim/go-micro 2020-12-12 20:51:40 +00:00
Asim Aslam 690169f6e5 remove k8s logs 2020-12-12 20:51:32 +00:00
Asim Aslam a543157f50 Delete debug.go 2020-12-12 20:50:53 +00:00
Asim Aslam 15a62ae0b9 move debug handler 2020-12-12 20:50:36 +00:00
Asim Aslam 28afbf164f Merge branch 'master' of ssh://github.com/asim/go-micro 2020-12-12 20:44:45 +00:00
Asim Aslam 4ce77373c0 remove auth cruft 2020-12-12 20:44:32 +00:00
Asim Aslam 8de1ede0f0 Update network.go 2020-12-12 20:35:43 +00:00
Asim Aslam 8054478cc3 remove util/scope 2020-12-12 20:28:09 +00:00
Asim Aslam 167fcd0d78 fix wrapper test 2020-12-12 20:25:29 +00:00
Asim Aslam 206bf8cd0a remove web 2020-12-12 20:15:59 +00:00
Asim Aslam df687fe5d4 move selector 2020-12-12 20:14:50 +00:00
Asim Aslam de4f3ee4a2 separate rules and auth 2020-12-12 20:08:39 +00:00
Asim Aslam 202338bd2d update all the things to go 1.15 2020-12-12 19:51:18 +00:00
Asim Aslam e2034b2438 Merge branch 'master' of ssh://github.com/asim/go-micro 2020-12-12 19:39:14 +00:00
Asim Aslam 0ec2399a2c fix command 2020-12-12 19:39:04 +00:00
Asim Aslam df5f158cef Delete .golangci.yml 2020-12-12 19:09:48 +00:00
Asim Aslam 19ac4fbcaf move rules 2020-12-12 19:08:36 +00:00
Asim Aslam d07de3751e remove auth provider 2020-12-12 19:06:43 +00:00
Asim Aslam 4977aca09c move router 2020-12-12 19:04:19 +00:00
Asim Aslam 43ff2a540d move proxy 2020-12-12 19:02:04 +00:00
Asim Aslam 35c59042bf refactor network 2020-12-12 18:59:40 +00:00
Asim Aslam f8f84b42ac Merge branch 'master' of ssh://github.com/asim/go-micro 2020-12-11 21:42:43 +00:00
Asim Aslam 1dc9b40b90 move network/tunnel 2020-12-11 21:42:31 +00:00
Asim Aslam 345845ec16 Delete CNAME 2020-12-11 11:22:37 +00:00
Asim Aslam dbe8c93e20 remove service implementations (#2094) 2020-12-11 11:12:44 +00:00
Asim Aslam 4d481b0363 Update README.md 2020-12-09 21:52:18 +00:00
Asim Aslam 88d954cf97 Update README.md 2020-12-09 18:35:07 +00:00
Asim Aslam 71883f1b04 Update tests.yml 2020-12-09 18:19:37 +00:00
Asim Aslam bfc212f7ed remove service package 2020-12-09 18:11:10 +00:00
Asim Aslam 43f80b1b0d Delete build-micro.sh 2020-12-09 18:09:02 +00:00
Asim Aslam f83d64d092 Delete build-all-examples.sh 2020-12-09 18:08:55 +00:00
Asim Aslam e67b9f0cc1 Delete micro-main.yml 2020-12-09 18:08:39 +00:00
Asim Aslam 134c5f0e41 Delete micro-examples.yml 2020-12-09 18:08:26 +00:00
Asim Aslam e761aa1940 move cmd 2020-12-09 18:07:01 +00:00
Asim Aslam 8c8380dcd4 delete agent package 2020-12-09 18:03:00 +00:00
Asim Aslam dd5eca2561 Update README.md 2020-12-09 17:05:05 +00:00
Dominic Wong 94bd1025a6 push tags to docker hub (#1766)
Docker / build (push) Waiting to run
Run tests / Test repo (push) Waiting to run
2020-07-03 11:30:59 +01:00
Dominic Wong 7be4a67673 MDNS registry fix for users on VPNs (#1759)
* filter out unsolicited responses
* send to local ip in case
* allow ip func to be passed in. add option for sending to 0.0.0.0
2020-07-03 11:30:59 +01:00
Di Wu 3e6ac73cfe Fix invalid usage for sync.WaitGroup (#1752)
* Custom private blocks

* Fix invalid usage for sync.WaitGroup

Co-authored-by: Asim Aslam <asim@aslam.me>
2020-07-03 11:30:59 +01:00
Colin Hoglund aef6878ee0 config: use configured reader by default (#1717) 2020-07-03 11:30:59 +01:00
sunfuze 81aa8e0231 Fix config watch (#1670)
* add dirty overrite test case

* need version to figure out if config need update or not

* using nanosecond as version for two goroutine can run in same second

* config should check snapshot version when update

* set checksum of ChangeSet

Co-authored-by: Asim Aslam <asim@aslam.me>
2020-07-03 11:30:59 +01:00
Di Wu c28f625cd4 Custom private blocks (#1705)
Co-authored-by: Asim Aslam <asim@aslam.me>
2020-07-03 11:30:59 +01:00
Dmitry Kozlov 5b161b88f7 Split long discord output message into the chunks by 2000 characters (#1704)
Signed-off-by: Dmitry Kozlov <dmitry.f.kozlov@gmail.com>
2020-07-03 11:30:59 +01:00
ben-toogood cca8826a1f registry/mdns: fix nil host bug (#1703) 2020-07-03 11:30:59 +01:00
Dominic Wong 0327f30e3c Fix regex detection. Fixes #1663 (#1696)
Docker / build (push) Waiting to run
Run tests / Test repo (push) Waiting to run
2020-06-12 10:42:52 +01:00
Dominic Wong 0ce132eb8f Fix race condition when updating process being waited on (#1694) 2020-06-12 10:42:52 +01:00
Janos Dobronszki 00b76e0a64 Initialize selector before we make an auth.Generate call (#1693) 2020-06-12 10:42:52 +01:00
Dominic Wong aec27be9b4 Fix race when opening DB for first time (#1691) 2020-06-12 10:42:52 +01:00
Dominic Wong 86dfcb819b Ignore "no such process" error (#1686)
* Cleanup how status is updated for service. Ignore "no such process" error as it could be that the pid died

* add nice error log to record process error exit
2020-06-12 10:42:52 +01:00
Janos Dobronszki d613804b0a Sigterm instead of Sigkill (#1687)
Co-authored-by: Dominic Wong <domwongemail@googlemail.com>
Co-authored-by: Asim Aslam <asim@aslam.me>
2020-06-12 10:42:52 +01:00
Vasiliy Tolstov 92e9d05432 api/handler/rpc: dont log error on normal websocket error code (#1688)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-06-12 10:42:52 +01:00
ben-toogood 8dfd93e915 util/wrapper: Add Static Client wrapper (#1685)
* util/wrapper: Add Static Client wrapper

* util/wrapper/static: pass address to stream too

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* add static client wrapper tests

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* server: fix error message spaces between words

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* server/{rpc,grpc}: replace log.Error with log.Errorf

* server/grpc: fix log typo

* server/rpc: fix log typo

Co-authored-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-06-12 10:42:52 +01:00
Dominic Wong e5136332e3 Add build and test of micro to pre-release testing (#1684)
* fix up example test build

* build and test micro when cutting a new release
2020-06-12 10:42:52 +01:00
Dominic Wong f10fd4b479 Build all micro/examples for release-X.X.X branches (#1683)
* Build all the examples on push to any release branch
2020-06-12 10:42:52 +01:00
ben-toogood 74368026a5 Fix incorrect namespace variable name (merge conflict) (#1677) 2020-06-12 10:42:52 +01:00
ben-toogood fde1aa9d6a Move auth account creation to config/cmd (#1676) 2020-06-12 10:42:52 +01:00
ben-toogood f45cdba9ba Apply wrappers to gRPC streams (#1675)
* Add wrappers to grpc streams

* Fix typo
2020-06-12 10:42:52 +01:00
Asim Aslam b270860b79 Update README.md (#1695) 2020-06-10 10:22:53 +01:00
Asim Aslam e7ba930236 Update FUNDING.yml (#1692) 2020-06-08 18:12:19 +01:00
Dominic Wong aa679f7a73 Create PULL_REQUEST_TEMPLATE.md 2020-06-03 10:32:28 +01:00
Asim Aslam 7b379bf1f1 WIP: Add metadata to store record (#1604)
* Add metadata to store record

* Add metadata to cockroach store

* add metadata to store service implementation

* fix breaking cache test

* Test/fix cockroach metadata usage

* fix store memory metadata bug
2020-06-03 09:45:08 +01:00
Dominic Wong e4e56b0f3f Merge pull request #1671 from sadwxqezc/fix-jwt
Fix jwt revoke
2020-06-02 09:27:14 +01:00
huanghuan.27@bytedance.com 219d29f664 fix jwt revoke 2020-06-02 10:26:33 +08:00
Asim Aslam 8fb138af06 Update README.md 2020-05-31 11:56:55 +01:00
Asim Aslam a39e6515da Update README.md
Docker / build (push) Waiting to run
Run tests / Test repo (push) Waiting to run
2020-05-31 11:35:09 +01:00
Asim Aslam 2c7fd286de Update README.md 2020-05-31 11:34:49 +01:00
Asim Aslam 8aa2712b4d Delete README.zh-cn.md 2020-05-31 11:33:31 +01:00
Asim Aslam b5c2121cef Update README.md 2020-05-31 11:31:41 +01:00
Asim Aslam ca9b877646 Update README.md 2020-05-31 11:28:32 +01:00
Asim Aslam ff49b4fc71 Update README.md 2020-05-31 11:27:54 +01:00
Asim Aslam 222431b57a Update README.md 2020-05-31 11:26:46 +01:00
Asim Aslam ddb51529a7 Update README.md 2020-05-31 11:26:18 +01:00
Asim Aslam 7c048f331a Update README.md 2020-05-31 11:21:55 +01:00
Asim Aslam 8475183bbb Update README.md 2020-05-31 11:19:26 +01:00
Asim Aslam 10f35db3ed Update README.md 2020-05-31 11:16:20 +01:00
Asim Aslam b68af8ab63 run go fmt 2020-05-30 11:00:43 +01:00
Asim Aslam 266602a3d6 Update README.md 2020-05-30 10:59:59 +01:00
mlboy 15d5142d9b fix: misspell (#1667) 2020-05-29 17:49:22 +01:00
Máximo Cuadros 0d88650511 go modules cleanup and remove wrong self import to v1 (#1658)
* Runtime local git, simply go-git code
* go modules cleanup and remove wrong self import to v1
* pin mergo v0.3.8 to avoid panics

Signed-off-by: Máximo Cuadros <mcuadros@gmail.com>
Co-authored-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-05-29 14:32:11 +03:00
Dominic Wong 8660370dc9 Merge pull request #1657 from xpunch/master
logger caller not trim in windows
2020-05-29 10:35:03 +01:00
Dominic Wong 73339dde85 Merge branch 'master' into master 2020-05-29 10:27:20 +01:00
Dominic Wong 3f354f3c30 Merge pull request #1661 from micro/bugfix/sock_pool_threads
fix locking of socket pool
2020-05-28 08:31:47 +01:00
potato c08eb5f892 Merge branch 'master' into master 2020-05-28 10:19:53 +08:00
Dominic Wong 27e41c4ad5 fix locking of socket pool 2020-05-27 20:18:26 +01:00
Dominic Wong 1da8a640da Merge pull request #1660 from micro/bugfix/mdns_nil_host
Check ipv4 or ipv6 address is valid before assigning
2020-05-27 15:53:27 +01:00
Dominic Wong e7ad031eb8 Check ipv4 or ipv6 address is valid before assigning 2020-05-27 15:47:12 +01:00
ben-toogood 192f548c83 Merge pull request #1659 from micro/config-srv-not-found
Handle config service not found errors
2020-05-27 12:24:33 +01:00
Ben Toogood d85b4197b4 Return nil changeset and not blank 2020-05-27 12:20:31 +01:00
Ben Toogood bb5f2e5525 Handle config service not found errors 2020-05-27 12:12:34 +01:00
ben-toogood f00b696282 Merge pull request #1654 from micro/auth-scopes
Auth Improvements
2020-05-27 10:52:07 +01:00
Ben Toogood e2d662608c Fix tests 2020-05-27 09:14:16 +01:00
Ben Toogood 9e9773c9c7 Only use namespace for cache key 2020-05-27 09:07:59 +01:00
potato 2f8e2487f7 Merge branch 'master' into master 2020-05-27 09:32:27 +08:00
Ben Toogood d6c1fbf841 Fix web service auth name 2020-05-26 17:43:45 +01:00
Ben Toogood c3b404bab0 Fix server calling across namespace 2020-05-26 17:35:06 +01:00
Ben Toogood cd283654eb Cache Rules 2020-05-26 15:53:28 +01:00
Ben Toogood 5712cc9c62 Merge master 2020-05-26 15:52:21 +01:00
ben-toogood be5a10a4d4 Merge pull request #1656 from micro/client-cache
Client Cache
2020-05-26 15:38:30 +01:00
Ben Toogood b53a2c67f1 Merge branch 'master' of https://github.com/micro/go-micro into auth-scopes 2020-05-26 15:37:31 +01:00
johnson cc79692d68 make caller filepath package/file style
this code is from zap
https://github.com/uber-go/zap/blob/9a9fa7d4b5f07a9b634983678a65b5525f81e58b/zapcore/entry.go#L101
2020-05-26 14:33:56 +08:00
potato 796a598b37 Merge pull request #7 from micro/master
go micro v2
2020-05-26 14:18:25 +08:00
Ben Toogood 73b4423682 Merge branch 'master' of https://github.com/micro/go-micro into client-cache 2020-05-24 20:36:22 +01:00
Ben Toogood 198e942889 Remove redundant test 2020-05-24 20:32:22 +01:00
Ben Toogood 95703e4565 Fixes and improved test coverage 2020-05-24 20:26:37 +01:00
Ben Toogood 2729569f66 Add Debug.Cache method 2020-05-24 18:45:57 +01:00
Ben Toogood 67146ecdc2 Client Cache tests 2020-05-24 18:05:23 +01:00
Asim Aslam bd049a51e6 Update README.md 2020-05-23 16:47:23 +01:00
Asim Aslam ffd89599a0 Update README.md 2020-05-23 16:46:50 +01:00
Ben Toogood 496293afa1 Use hash/fnv, add tests, fix request bug 2020-05-23 11:34:44 +01:00
Ben Toogood 7d7f4046e8 Client Cache 2020-05-22 16:52:24 +01:00
Ben Toogood c800070477 Check for error before loading rules 2020-05-22 14:03:12 +01:00
Ben Toogood 877fe5fb0a Update web wildcard to enable /foo/bar/baz/* to verify /foo/bar/baz 2020-05-22 14:02:02 +01:00
Ben Toogood dad011cab4 Fix noop issuer bug 2020-05-22 12:40:34 +01:00
Ben Toogood f939200b34 Improve service auth log 2020-05-22 12:24:37 +01:00
Ben Toogood 9c072a372c Add auth scope constants 2020-05-22 11:37:12 +01:00
Ben Toogood fbb91c6cb7 Auth wrapper tests 2020-05-22 10:44:18 +01:00
Ben Toogood b2cf501952 Auth Rules tests & bug fixes 2020-05-22 09:31:15 +01:00
Ben Toogood 1fce0f02b6 Verify Namespace 2020-05-21 18:11:35 +01:00
Ben Toogood 12061bd006 Add account issuers 2020-05-21 16:41:55 +01:00
Ben Toogood 856c73b341 Remove roles (replaced with scope) 2020-05-21 14:56:17 +01:00
Ben Toogood 4de19805ba Remove redundant test 2020-05-21 12:33:58 +01:00
Ben Toogood c09b871a6b Merge branch 'master' of https://github.com/micro/go-micro into auth-scopes 2020-05-21 12:32:52 +01:00
Ben Toogood e876cb917d auth/service support for micro clients (rules from mutltiple namespaces 2020-05-21 12:25:47 +01:00
Ben Toogood 8f5ef012ff Update Rules.Delete proto 2020-05-21 12:07:22 +01:00
Ben Toogood 287992cef3 Fix service => service namespace bug 2020-05-21 11:35:07 +01:00
Ben Toogood 344ce061ce Verify Options 2020-05-20 16:49:52 +01:00
Ben Toogood 5d14970a55 Fix nil account bug 2020-05-20 16:11:34 +01:00
Janos Dobronszki 0615fe825f Auth invalid token fix (#1650) 2020-05-20 16:18:05 +02:00
Asim Aslam 6a661fd08c check if the db conn is nil before doing anything (#1652) 2020-05-20 14:03:38 +01:00
Ben Toogood f6d9416a9e Add Rule to Auth interface 2020-05-20 11:59:01 +01:00
Asim Aslam a29676b86a Registration Retry / Interval (#1651)
* Change the default ttl to 90 seconds

* add retries to registration

* Add retry to web register
2020-05-20 11:49:09 +01:00
Ben Toogood dc10f88c12 Replace auth account.Namespace with account.Scopes 2020-05-19 18:17:17 +01:00
ben-toogood e61edf6280 Merge pull request #1645 from micro/runtime-multitenancy
Runtime multi-tenancy
2020-05-19 17:06:11 +01:00
ben-toogood 3410a0949b Merge branch 'master' into runtime-multitenancy 2020-05-19 17:00:51 +01:00
Jake Sanders 9216a47724 fix client race (#1647) 2020-05-19 14:44:46 +01:00
ben-toogood cf37d64819 Merge branch 'master' into runtime-multitenancy 2020-05-19 13:24:35 +01:00
Patrik Lindahl f0c0f3d4c4 Fixes for #1560 (#1644)
close #1560

This fixes one of the reported data races and also allows for
having a different name on the micro.Service and web.Service.
This makes it possible to discover the two service variants separately.

Co-authored-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-05-19 14:11:26 +03:00
Ben Toogood c4e3f8c336 Merge branch 'master' of https://github.com/micro/go-micro into runtime-multitenancy 2020-05-19 11:02:40 +01:00
Ben Toogood 8875719619 Default Runtime multi-tenancy 2020-05-19 11:01:06 +01:00
Ben Toogood c19b349e96 Update runtime.Event struct 2020-05-19 10:14:07 +01:00
Ben Toogood 14155c7e02 Add runtime ErrNotFound 2020-05-19 09:28:00 +01:00
Maarten Bezemer 3d36398818 Fix client RPC stream close mutex (#1643)
Docker / build (push) Waiting to run
Run tests / Test repo (push) Waiting to run
2020-05-18 17:22:33 +01:00
Asim Aslam 56a7897c91 update readme 2020-05-17 12:39:20 +01:00
ben-toogood 5efb386224 Merge pull request #1640 from micro/auth/public-rule
Auth: setup a public rule
2020-05-15 10:28:52 +01:00
Ben Toogood 4d2de923cd Auth: setup a public rule 2020-05-15 10:24:30 +01:00
ben-toogood f64b1468a5 Merge pull request #1639 from micro/registy-not-found
Registry service: return not found error
2020-05-14 19:43:19 +01:00
ben-toogood 56f281002b Merge branch 'master' into registy-not-found 2020-05-14 19:39:43 +01:00
Ben Toogood 0d7250352f Registry service: return not found error 2020-05-14 19:38:56 +01:00
ben-toogood ef43f01da4 Merge pull request #1638 from micro/registry-addrs-fix
Fix registry address option unused
2020-05-14 18:07:14 +01:00
ben-toogood c9e5ae6a2b Merge branch 'master' into registry-addrs-fix 2020-05-14 18:03:46 +01:00
Ben Toogood 8a802d8f7a Fix registry address option unused 2020-05-14 18:00:13 +01:00
ben-toogood 331ab3715c Merge pull request #1636 from micro/auth-util
Refactor auth setup to util/auth
2020-05-14 16:15:47 +01:00
Ben Toogood 6b451a2197 Refactor auth setup to util/auth 2020-05-14 16:10:14 +01:00
ben-toogood b4c0224746 Merge pull request #1635 from micro/auth-fixes
Auth: Move token generation logic out the client wrappers
2020-05-14 14:00:55 +01:00
Ben Toogood 500d793fc4 Merge branch 'auth-fixes' of https://github.com/micro/go-micro into auth-fixes 2020-05-14 13:57:00 +01:00
Ben Toogood 16af265e8b Seperate JWT refresh / access tokens 2020-05-14 13:56:51 +01:00
ben-toogood b222cf8e13 Merge branch 'master' into auth-fixes 2020-05-14 13:47:26 +01:00
Ben Toogood f549e20fa2 tidy go mdo 2020-05-14 13:33:11 +01:00
Ben Toogood 83e9c1fad2 Remove unnecessary change 2020-05-14 13:32:42 +01:00
Ben Toogood c220686c29 Fix token bug 2020-05-14 13:30:21 +01:00
Ben Toogood 1b18730d54 Custom micro client 2020-05-14 11:25:19 +01:00
Ben Toogood 5764519f5b Refactor auth to load token outside wrappers 2020-05-14 11:06:22 +01:00
ben-toogood 957001f8ad Merge pull request #1634 from micro/disable-clients
Disable Clients
2020-05-13 18:54:34 +01:00
Ben Toogood 0955671e45 Merge branch 'disable-clients' of https://github.com/micro/go-micro into disable-clients 2020-05-13 18:49:47 +01:00
Ben Toogood 57b060bac5 Disable Addresses 2020-05-13 18:49:36 +01:00
ben-toogood 3136e1409e Merge branch 'master' into disable-clients 2020-05-13 18:48:24 +01:00
Ben Toogood ca791d7e8d Disable Clients 2020-05-13 18:47:53 +01:00
Dominic Wong 05858b746c kill all processes correctly for micro kill command (#1633) 2020-05-13 18:36:45 +01:00
ben-toogood 09d1450d7d Merge pull request #1632 from micro/fix-auth-bug
Auth: Fix recursive bug
2020-05-13 18:18:39 +01:00
Ben Toogood 1ca1fd411a Auth: Fix recursive bug 2020-05-13 18:17:04 +01:00
ben-toogood a2d4d62f1c Merge pull request #1631 from micro/auth-address
Auth: Set address
2020-05-13 18:02:10 +01:00
Ben Toogood 8ab20f501c Fix merge conflicts 2020-05-13 17:58:03 +01:00
Ben Toogood 366fb228e5 Auth: Set address 2020-05-13 17:54:47 +01:00
Asim Aslam bba8c254d7 fix auth initialisation (#1630) 2020-05-13 17:35:57 +01:00
ben-toogood ebd53794af Merge pull request #1629 from micro/auth/rules-fix
Auth: Load rules if not present
2020-05-13 17:27:53 +01:00
Ben Toogood 2299244332 Auth: Load rules if not present 2020-05-13 17:07:46 +01:00
ben-toogood cf61d98635 Merge pull request #1628 from micro/registry
Misc Muti-Tenancy / Auth Fixes
2020-05-13 16:53:39 +01:00
ben-toogood 15d1967aaf Merge branch 'master' into registry 2020-05-13 16:50:12 +01:00
Ben Toogood 410fec8ee4 Fix auth bug 2020-05-13 16:49:17 +01:00
Ben Toogood c831b6c03a Fix 2020-05-13 16:35:57 +01:00
Asim Aslam 290595f88e Strip down router code (#1627) 2020-05-13 16:13:36 +01:00
ben-toogood ba64518ebd Merge pull request #1626 from PieterVoorwinden/master
Check if auth is nil to prevent nilpointer
2020-05-13 15:18:58 +01:00
Pieter Voorwinden b14d63b4a1 Check if auth is nil to prevent nilpointer 2020-05-13 16:13:23 +02:00
x1nchen af2db0a0d9 fix: update dependency certmagic (#1625)
module github.com/mholt/certmagic has been renamed github.com/caddyserver/certmagic,
so upgrade on this module will fail.

fix: micro/micro#835

caddyserver/certmagic@v0.10.6 is Maximum upgradeable version with go version 1.13

Higher version use *tls.ClientHelloInfo.SupportsCertificate which only supported in go 1.14
2020-05-13 15:00:13 +01:00
ben-toogood fb255a7e5a Merge pull request #1622 from micro/registry-multi-tenancy
Registry mutli-tenancy
2020-05-13 13:54:39 +01:00
Ben Toogood 47c1cb433e Store account credentials 2020-05-13 13:48:25 +01:00
Ben Toogood 3fac7d79ab Remove service type role 2020-05-13 13:42:56 +01:00
Ben Toogood 25c937fd0e Naming changes 2020-05-13 13:38:13 +01:00
Ben Toogood e5c1fbc591 Merge branch 'master' of https://github.com/micro/go-micro into registry-multi-tenancy 2020-05-13 13:35:47 +01:00
Ben Toogood d781c9ae2d Remove namespace specific logic 2020-05-13 13:35:34 +01:00
Ben Toogood 54951740bf Authenticate on service start 2020-05-13 13:13:11 +01:00
Janos Dobronszki 0fb4734e67 Upload local source code to micro server (#1613) 2020-05-13 12:07:53 +02:00
Ben Toogood 346e034d0a Add mutli-tenancy support to the registry 2020-05-13 10:40:08 +01:00
Asim Aslam 116cc1e9ee Stop parsing proxy address (#1619) 2020-05-12 17:38:22 +01:00
ben-toogood 762a5bc9e8 Merge pull request #1618 from micro/auth-namespace-flag
Auth Namespace Flag
2020-05-12 16:45:42 +01:00
Ben Toogood d39b723511 Auth Namespace Flag 2020-05-12 16:41:29 +01:00
ben-toogood 5494e935f4 Merge pull request #1617 from micro/k8s/secret-type
K8s: Add Secret Type to yaml template
2020-05-12 14:21:30 +01:00
Ben Toogood e0863bb7eb K8s: Add Secret Type to yaml template 2020-05-12 14:10:39 +01:00
ben-toogood 89f86167ad Merge pull request #1616 from micro/k8s/secret-template-fix
Fix k8s secret template (yaml)
2020-05-12 11:45:12 +01:00
ben-toogood dfec1ad6b1 Merge branch 'master' into k8s/secret-template-fix 2020-05-12 11:41:41 +01:00
Ben Toogood 66d3e4a595 Fix k8s secret template (yaml) 2020-05-12 11:40:54 +01:00
Asim Aslam 19a03babc4 Update server.go 2020-05-12 11:32:01 +01:00
ben-toogood ee24b4f083 Merge pull request #1615 from micro/disable-auth-client
Disable auth service client
2020-05-11 20:38:49 +01:00
Ben Toogood 937ecc8d2f Disable auth service client 2020-05-11 20:38:05 +01:00
ben-toogood 6078adb8bc Merge pull request #1614 from micro/runtime-clients
Runtime Options: Replace client.DefaultClient
2020-05-11 20:05:00 +01:00
ben-toogood 39f18b0b70 Merge branch 'master' into runtime-clients 2020-05-11 18:03:11 +01:00
Ben Toogood efb64b7dbb Pass client to more of the runtime 2020-05-11 17:57:39 +01:00
Ben Toogood f892b41299 Add runtime to service.Options() 2020-05-11 17:09:28 +01:00
Janos Dobronszki 1eb63635b5 Adding file upload and download capabilities (#1610) 2020-05-11 14:08:27 +02:00
ben-toogood 688228377b Merge pull request #1612 from micro/auth-options
Auth: pass options in service RPC
2020-05-11 11:53:38 +01:00
Ben Toogood 506006f0fa Auth Options 2020-05-11 11:47:59 +01:00
ben-toogood 22de001a80 Merge pull request #1611 from micro/auth-has-role
Auth account.HasRole
2020-05-11 11:40:20 +01:00
ben-toogood d90cc8bf2f Merge branch 'master' into auth-has-role 2020-05-11 11:36:06 +01:00
Ben Toogood 5a8f19589b Auth account.HasRole 2020-05-11 11:34:22 +01:00
gggwvg d61df6363b web: fix advertise address (#1608)
* web: fix advertise address
* web: fix test

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
Co-authored-by: Asim Aslam <asim@aslam.me>
Co-authored-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-05-08 12:31:03 +03:00
ben-toogood f062013a7b Merge pull request #1607 from micro/k8s-debug
Log k8s Requests
2020-05-07 11:41:43 +01:00
Ben Toogood fea93a5b7a Log k8s Requests 2020-05-07 11:35:56 +01:00
fztcjjl 30dc29e17f fix ring buffer (#1606) 2020-05-07 10:45:48 +01:00
ben-toogood 5387f73b5d Handle cockroach createDB error (#1603) 2020-05-06 10:58:14 +01:00
Vasiliy Tolstov 90dd1f63c8 api/handler/rpc: fix encoding of inner message (#1601)
* api/handler/rpc: fix encoding of inner message

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-05-04 15:50:53 +03:00
Asim Aslam 38cdb9cc2f Set table name in store
Docker / build (push) Waiting to run
Run tests / Test repo (push) Waiting to run
2020-05-01 18:24:35 +01:00
Asim Aslam b3915b6020 Add store to options (#1600) 2020-05-01 18:05:09 +01:00
Asim Aslam 08a2de1ef5 Account for missing options database/table in cockroach store 2020-05-01 15:31:55 +01:00
Asim Aslam 7a2dea6cc2 Set database/table from init first 2020-05-01 15:22:44 +01:00
Asim Aslam 2a14feed93 force codec on call not on dial (#1599) 2020-05-01 14:59:50 +01:00
Asim Aslam e8105d22ad cruft 2020-05-01 00:25:17 +01:00
Asim Aslam c76a5e608d sql fixes 2020-04-30 23:53:54 +01:00
Asim Aslam 359b8bc503 Add opts to service proto (#1517)
* Add opts to service proto

* Support database/table opts
2020-04-30 22:51:25 +01:00
Janos Dobronszki fccab8ad27 Runtime name should be base folder outside repos (#1598) 2020-04-30 18:20:51 +02:00
Socket 46d09ec2bc unsubscribe can async (#1596)
Co-authored-by: huangshaojie <huangshaojie@corp.netease.com>
Co-authored-by: Asim Aslam <asim@aslam.me>
2020-04-30 10:42:13 +01:00
Asim Aslam 7792dbc34d Update FUNDING.yml 2020-04-29 18:45:55 +01:00
ben-toogood 1d29f126f9 Merge pull request #1595 from micro/auth-client-wrapper
Auth Client Wrapper
2020-04-29 15:43:30 +01:00
Ben Toogood bcddb98867 Fix Tests 2020-04-29 15:37:02 +01:00
Ben Toogood f48dec1fb0 Use Server ID in account name 2020-04-29 15:27:18 +01:00
Ben Toogood ef9f65c78b Improve Comments 2020-04-29 15:15:38 +01:00
Ben Toogood 99f8be5b3d Auth Client Wrapper 2020-04-29 15:11:06 +01:00
ben-toogood 9d2fdb84be Merge pull request #1592 from micro/jwt-auth
JWT auth implementation
2020-04-29 14:10:05 +01:00
ben-toogood 8b004feb9a Merge branch 'master' into jwt-auth 2020-04-29 13:33:47 +01:00
Ben Toogood 70736e24c0 Set RefreshToken 2020-04-29 13:33:22 +01:00
Vasiliy Tolstov d44adafca5 api/router: avoid unneeded loops and fix path match (#1594)
* api/router: avoid unneeded loops and fix path match

* if match found in google api path syntax, not try pcre loop
* if path is not ending via $ sign, append it to pcre to avoid matching other strings like
  /api/account/register can be matched to /api/account
* api: add tests and validations

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-04-29 15:23:10 +03:00
ben-toogood e57b20c1f8 Merge branch 'master' into jwt-auth 2020-04-29 13:22:09 +01:00
Ben Toogood 94971aee77 Complete JWT implementation 2020-04-29 13:21:51 +01:00
Ben Toogood 0ed66d0664 Fix Typo 2020-04-29 09:38:39 +01:00
Ben Toogood 7e27c97c6c Remove Comment 2020-04-29 09:22:15 +01:00
Ben Toogood 669364985e JWT auth implementation 2020-04-29 09:21:17 +01:00
Asim Aslam c7440274dd touch 2020-04-28 19:35:13 +01:00
Asim Aslam 8ccbf53dfc secret cookie unused 2020-04-28 18:12:07 +01:00
Asim Aslam f908110fb6 swap out context access for account (#1589) 2020-04-28 17:35:18 +01:00
Vasiliy Tolstov 9bb1904a38 broker: add publish context (#1590)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-04-28 19:29:00 +03:00
Vasiliy Tolstov 06220ab8c8 client: add context publish option (#1588)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-04-28 19:03:37 +03:00
Janos Dobronszki da66561d1e Fixing too large offsets for default runtime logs (#1587) 2020-04-28 13:42:15 +01:00
Dmitry Kozlov 52861310b0 fix HTTP 401 Unauthorized, {"message": "401: Unauthorized", "code": 0} (#1586)
fix file=bot.go:426 level=error service=bot error starting bot HTTP 401 Unauthorized, {"message": "401: Unauthorized", "code": 0}
see https://github.com/bwmarrin/discordgo#usage
2020-04-28 13:06:01 +01:00
Vasiliy Tolstov 414b2ec5f8 web: fix deadlock (#1585)
* web: fix deadlock

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* add web tests

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-04-28 12:23:52 +01:00
Janos Dobronszki b875868a39 Don't ignore errors from checkout source code (#1584)
Don't check out code for builtin services.
2020-04-28 10:51:39 +02:00
Janos Dobronszki 8148e0a0f8 Micro log fixes (#1570) 2020-04-28 09:49:39 +02:00
ben-toogood 25c82245b1 Merge pull request #1582 from micro/k8s-srv-accounts
Runtime: Add Kubernetes ServiceAccounts & Remove imagePullSecrets
2020-04-27 15:24:16 +01:00
ben-toogood 95a7e21f5f Merge branch 'master' into k8s-srv-accounts 2020-04-27 15:08:24 +01:00
Asim Aslam 83ab47333f rename Codec to Secrets (#1581) 2020-04-27 14:57:57 +01:00
Ben Toogood 8d7d6ef358 Add k8s secrets 2020-04-27 14:37:28 +01:00
Ben Toogood 494e0b5060 Runtime: Add Kubernetes ServiceAccounts & Remove imagePullSecrets 2020-04-27 14:13:51 +01:00
Janos Dobronszki 434997e676 Display only logging file name as opposed to path in logs (#1580) 2020-04-27 09:55:50 +01:00
Janos Dobronszki ec44b67e9f Fixing log file path in logs (#1578) 2020-04-27 09:36:09 +01:00
Vasiliy Tolstov e0c9234c0e web: use default logger (#1577)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-04-27 00:03:05 +03:00
Vasiliy Tolstov 980b772801 fix races in web and logger (#1576)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-04-26 17:41:36 +03:00
Vasiliy Tolstov a22da39e1c logger: add caller info to default implementation (#1575)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-04-26 17:11:53 +03:00
徐旭 7253635cd3 delete invalid copy (#1573)
* prealloc

* delete invalid copy
2020-04-26 12:44:59 +01:00
Asim Aslam 0a030f3d8a strip unused list endpoint 2020-04-24 18:05:38 +01:00
Asim Aslam edee3b6765 Add proxy env test (#1569) 2020-04-24 11:26:46 +01:00
Asim Aslam d62ae23a9c Strip label 2020-04-23 20:20:48 +01:00
Asim Aslam c68226e9b0 only do namespace check if not default 2020-04-23 19:19:13 +01:00
ben-toogood 041d68b1ce Merge pull request #1566 from micro/image-pull-secret-fix
Fix Runtime Namespace List
2020-04-23 18:16:38 +01:00
ben-toogood 85a8f36565 Merge branch 'master' into image-pull-secret-fix 2020-04-23 18:15:04 +01:00
Ben Toogood f34d58cfbd Remove Debug 2020-04-23 18:14:06 +01:00
Asim Aslam e0a651bfc3 set namespace on create 2020-04-23 18:10:13 +01:00
Ben Toogood cd35f503a0 Remove hardcoded labels 2020-04-23 18:08:02 +01:00
Ben Toogood 8b3d223fc0 Remove hardcoded labels: 2020-04-23 18:05:58 +01:00
Ben Toogood bb25bd94c8 Log k8s requests 2020-04-23 17:56:00 +01:00
ben-toogood 986e3d3c35 Merge pull request #1565 from micro/image-pull-secret-fix
Runtime: Fix ImagePullSecret
2020-04-23 17:53:09 +01:00
Ben Toogood 616db3442a Debugging 2020-04-23 17:44:40 +01:00
Ben Toogood 5fe3c0bfe5 Merge branch 'image-pull-secret-fix' of https://github.com/micro/go-micro into image-pull-secret-fix 2020-04-23 17:37:33 +01:00
Ben Toogood 8849b85a7f Merge branch 'master' of https://github.com/micro/go-micro into image-pull-secret-fix 2020-04-23 17:37:15 +01:00
ben-toogood 893bbafa03 Merge branch 'master' into image-pull-secret-fix 2020-04-23 17:28:06 +01:00
Ben Toogood 4c05623a3c Image pull secret fix 2020-04-23 17:26:59 +01:00
Asim Aslam ec929b3d2f log error and ensure we pass through namespace 2020-04-23 17:14:30 +01:00
Asim Aslam 2299559397 Check for namespace (#1564) 2020-04-23 16:22:41 +01:00
ben-toogood 6be53536d3 Merge pull request #1562 from micro/git-secrets
Runtime - Image Pull Secrets
2020-04-23 15:45:32 +01:00
ben-toogood 99d4b2b31a Merge branch 'master' into git-secrets 2020-04-23 15:39:37 +01:00
Janos Dobronszki ff8ad7d4ca Default runtime now checks out code on demand (#1563)
* Default runtime now checks out code on demand

* Go mod tidy
2020-04-23 16:30:43 +02:00
ben-toogood b692c045b5 Merge branch 'master' into git-secrets 2020-04-23 15:01:47 +01:00
Ben Toogood b5f53595ca Pass image_pull_secrets in runtime service 2020-04-23 14:22:23 +01:00
Ben Toogood 88176dca53 Remove debugging 2020-04-23 14:13:07 +01:00
Ben Toogood 020476614c Tweak CreateImagePullSecret 2020-04-23 14:06:33 +01:00
Ben Toogood 0f42346976 Additonal Debugging 2020-04-23 14:03:04 +01:00
ben-toogood 692b27578c Runtime Namespace (#1547)
* Add context option to runtime; Add dynamic namespace to kubectl client

* Add namespace runtime arg

* Fixes & Debugging

* Pass options in k8s runtime

* Set namespace on k8s resources

* Additional Logging

* More debugging

* Remove Debugging

* Ensure namespace exists

* Add debugging

* Refactor namespaceExists check

* Fix

* Fix

* Fix

* Fix

* Change the way we check for namespace

* Fix

* Tidying Up

* Fix Test

* Fix merge bugs

* Serialize k8s namespaces

* Add namespace to watch

* Serialize namespace when creating k8s namespace

Co-authored-by: Ben Toogood <ben@micro.mu>
Co-authored-by: Asim Aslam <asim@aslam.me>
2020-04-23 13:53:42 +01:00
Micro 316b81f790 Debugging 2020-04-23 13:11:00 +01:00
Micro 5e3262a62c Passs img pull secrets using name key 2020-04-23 12:52:59 +01:00
Micro 053fa0e457 Fix template syntax 2020-04-23 12:38:00 +01:00
Micro 501a6bf3ea Add imagePullSecrets to PodSpec 2020-04-23 12:27:36 +01:00
Asim Aslam 7345ce9192 change logging for service startup 2020-04-23 11:24:39 +01:00
Vasiliy Tolstov 6fa27373ed bundle qson lib in util (#1561)
* copy qson from https://github.com/joncalhoun/qson
  as author not want to maintain repo
* latest code contains our fix to proper decode strings
  with escaped & symbol
* replace package in api/handler/rpc

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-04-23 11:08:09 +03:00
徐旭 e55c23164a fix prealloc in trace (#1558) 2020-04-22 16:10:59 +03:00
Asim Aslam e25ab9f4ca Fix typo for proxy 2020-04-22 10:44:34 +01:00
Vasiliy Tolstov bea092f082 server: set registered only after configuring subscribers (#1557)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-04-21 23:01:59 +03:00
Asim Aslam d7ecb58f6c Add network proxying (#1556)
* Add network proxying

* go fmt
2020-04-21 15:54:40 +01:00
Jake Sanders 05d2b34e10 Add util/pki for creating and signing certificates (#1555) 2020-04-21 15:03:33 +01:00
ben-toogood 211fd9b9a3 Merge pull request #1554 from micro/oauth-login-hint
Add oauth login hint param
2020-04-21 13:40:47 +01:00
Ben Toogood 19f0836e70 Add oauth login hint param 2020-04-21 13:37:26 +01:00
Janos Dobronszki 075d7d4fef Renaming ShutdownSignals -> Shutdown (#1553) 2020-04-21 14:14:20 +02:00
Janos Dobronszki e5c215556e Add SIGKILL to shutdown signals (#1552)
* Add SIGKILL to shutdown signals

* go mod tidy

* Add missing file
2020-04-21 14:00:12 +02:00
Janos Dobronszki 7c31edd5f8 Enabling default runtime to run multiple versions (#1545)
* Enabling default runtime to run multiple versions

* Trigger build

* Fix

* Sprintf
2020-04-20 15:54:29 +02:00
Asim Aslam c4acf3c2cb Static serving disabled 2020-04-19 20:30:38 +01:00
Asim Aslam 53db26a614 Use go.micro.mu 2020-04-19 17:03:25 +01:00
Asim Aslam dde8f18b52 Update readme 2020-04-19 00:46:33 +01:00
Asim Aslam 6071b74fb5 Update readme 2020-04-19 00:45:29 +01:00
Asim Aslam ab041012b2 Update readme 2020-04-19 00:44:52 +01:00
Asim Aslam 226d6ad22b log whats happening in http handler 2020-04-19 00:41:03 +01:00
Asim Aslam a08ff90976 fix this bs logging issue 2020-04-18 23:36:00 +01:00
Asim Aslam ae8404d760 Log listening port 2020-04-18 23:32:20 +01:00
Vasiliy Tolstov f00fd7a49e api/router: support pcre and google.api pattern matching (#1549)
* api/router: support pcre and google.api pattern matching

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-04-19 00:31:34 +03:00
Asim Aslam ecbc42755c set network nodes in http resolver 2020-04-18 21:00:00 +01:00
Asim Aslam 16db76bee2 remove list endpoint from runtime and stop checking type in update 2020-04-17 17:54:34 +01:00
Asim Aslam dca5305e8a replaced build with updated timestamp in runtime 2020-04-17 16:29:05 +01:00
Asim Aslam c0b0f63757 Update docker workflow to push releases 2020-04-17 10:50:44 +01:00
Janos Dobronszki ac5822f1ee Fix local runtime updates (#1543) 2020-04-16 17:50:24 +02:00
ben-toogood ae56becbbd Merge pull request #1542 from micro/stream-auth
Set authorization header on grpc stream
2020-04-16 15:06:19 +01:00
ben-toogood 5bb18e685e Merge branch 'master' into stream-auth 2020-04-16 15:03:12 +01:00
Ben Toogood 2dfaab439c Set authorization header on grpc stream 2020-04-16 15:01:16 +01:00
Vasiliy Tolstov 62cedf64da api/router/registry: extract path based parameters from url to req (#1530)
Run tests / Test repo (push) Waiting to run
* api/router/registry: extract path based parameters from url to req
* api/handler/rpc: fix empty body request parsing
* bundle grpc-gateway util funcs

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-04-15 17:50:51 +03:00
ben-toogood 9961ebb46e Merge pull request #1538 from micro/rule-priority
Add priority to auth.CreateRequest and auth.DeleteRequest
2020-04-15 11:54:01 +01:00
Ben Toogood fe31a71557 Fix formatting 2020-04-15 11:50:52 +01:00
Ben Toogood c9a6b07c52 Add priority to auth.CreateRequest and auth.DeleteRequest 2020-04-15 11:49:24 +01:00
ben-toogood f1e6eff303 Merge pull request #1537 from micro/rule-priority
Add Priority to auth rules
2020-04-15 11:42:53 +01:00
Ben Toogood 2de03e5fd7 Tidy go mod 2020-04-15 11:39:53 +01:00
Ben Toogood 234c192faf Update protoc-gen-micro 2020-04-15 11:39:12 +01:00
Ben Toogood ea29920afb Add Priority to auth rules 2020-04-15 11:31:19 +01:00
Vasiliy Tolstov 4d177a782e vendor proto files from google (#1536)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-04-15 13:22:32 +03:00
Vasiliy Tolstov b700d425a4 api/handler/rpc: improvements and fixes (#1535)
* api/handler/rpc: fix empty body case
* api/handler/rpc: copy all request headers to metadata

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-04-15 01:37:15 +03:00
Asim Aslam 9a5b8ff50d use api 2020-04-14 22:14:55 +01:00
Asim Aslam c787fd0483 fix missing pointer 2020-04-14 17:13:38 +01:00
Asim Aslam 1134ea5ff3 make proto.Message compatible with raw json 2020-04-14 16:59:24 +01:00
ben-toogood fd16cd298f Merge pull request #1532 from micro/registry-namespace
Registry Namespace
2020-04-14 16:14:18 +01:00
ben-toogood 67e7aa223a Merge branch 'master' into registry-namespace 2020-04-14 16:03:29 +01:00
Asim Aslam 9d0381306d add a proto message without serialisation 2020-04-14 15:54:25 +01:00
ben-toogood f8837bfcbd Merge branch 'master' into registry-namespace 2020-04-14 15:37:44 +01:00
Vasiliy Tolstov 268651df18 regenerate all proto based files (#1531)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-04-14 16:25:09 +03:00
Ben Toogood e17825474f Add context options to the runtime 2020-04-14 12:32:59 +01:00
Ben Toogood 0c75a0306b Merge master into registry-namespace 2020-04-14 09:15:13 +01:00
Ben Toogood d61d30ef66 Inject Namespace into Context 2020-04-14 09:14:07 +01:00
Asim Aslam 71d4253927 Merge branch 'master' of ssh://github.com/micro/go-micro 2020-04-13 23:05:47 +01:00
Asim Aslam e515005083 Remove only allowing certain methods 2020-04-13 23:05:39 +01:00
Asim Aslam 4bdc18d64a Update README.md 2020-04-13 22:15:21 +01:00
Asim Aslam f840a5003e Remove runtime List 2020-04-12 23:46:06 +01:00
Asim Aslam 5ef1698632 remove readme 2020-04-12 23:43:55 +01:00
Asim Aslam 1bb6967a38 reorder 2020-04-12 23:41:21 +01:00
Asim Aslam a056bdce7c fix metadata parsing 2020-04-12 14:40:37 +01:00
Asim Aslam b08c636b44 fixup handler tests 2020-04-12 14:29:38 +01:00
Asim Aslam d03a02f2e4 fix import 2020-04-12 11:25:12 +01:00
Asim Aslam 08ca61c121 add metadata set 2020-04-12 11:17:23 +01:00
Asim Aslam 962588b649 Strip MetadataKey global var 2020-04-12 11:16:08 +01:00
Asim Aslam cf67d460b7 strip down mdns watcher 2020-04-12 11:01:09 +01:00
Asim Aslam 4e539361fa strip file 2020-04-12 10:58:12 +01:00
Vasiliy Tolstov 3ce2ab88f5 broker/nats: remove embed nats server reference (#1527)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-04-11 22:37:29 +03:00
Vasiliy Tolstov 0a2363b49b api minor improvements (#1526)
* api/handler/rpc: unblock all http methods and set Host meta
* api/router/static: add debug log

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-04-11 22:21:55 +03:00
Asim Aslam ec80ceb8c2 Update readme 2020-04-11 18:23:37 +01:00
Asim Aslam ea2bb0275c Strip external use of mdns 2020-04-11 13:02:53 +01:00
Asim Aslam 51d4f737b8 fixup store cache# 2020-04-11 12:10:19 +01:00
Asim Aslam 3f81f685df Move sync 2020-04-11 12:00:34 +01:00
Asim Aslam bb1ccf09e8 prefix store dir 2020-04-11 11:23:41 +01:00
Asim Aslam c878237567 fix log file creation 2020-04-11 11:22:02 +01:00
Asim Aslam ac8b6f944e Prefix logs dir micro/logs for runtime 2020-04-11 11:15:01 +01:00
Asim Aslam 0f2006ac50 fix compilation issues 2020-04-11 11:02:06 +01:00
Asim Aslam c697eed1be Update comments 2020-04-11 10:48:32 +01:00
Asim Aslam b887d91f94 remove readme 2020-04-11 10:38:13 +01:00
Asim Aslam 39470c1b11 Completely replace sync implementation 2020-04-11 10:37:54 +01:00
Asim Aslam 6d553cb6fe add whitespace 2020-04-11 09:34:04 +01:00
Asim Aslam c612d86480 Move sync store 2020-04-11 09:33:10 +01:00
Asim Aslam 3f3d2f5027 fixup broker http address 2020-04-11 01:51:26 +01:00
Vasiliy Tolstov bc71640fd9 broker: swap default broker from eats to http (#1524)
* broker: swap default broker from eats to http

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-04-11 03:46:54 +03:00
Asim Aslam b979db6d9d remove sync event 2020-04-10 23:29:15 +01:00
Asim Aslam 57b758db7e push 2020-04-10 22:09:06 +01:00
Asim Aslam b5f546b137 go mod tidy 2020-04-10 19:55:45 +01:00
Asim Aslam d4b2c948dd Remove cloudflare store 2020-04-10 19:50:57 +01:00
Asim Aslam b9a5e9d610 fixup sync map 2020-04-10 17:47:13 +01:00
Asim Aslam 57853b2849 remove etcd store 2020-04-10 17:43:02 +01:00
Asim Aslam e5268dd0a6 move reg util to own package (#1523)
* move reg util to own package

* fix test

* fix broken static router
2020-04-10 17:41:10 +01:00
Asim Aslam 4fd12430d0 cleanup mdns files 2020-04-10 17:19:26 +01:00
Asim Aslam d134b469be rename file 2020-04-10 17:17:24 +01:00
Asim Aslam 9a685b2df5 delete k8s registry (#1522) 2020-04-10 17:15:20 +01:00
Jake Sanders 6a666c9c7d Add json tags to store.Record (#1518) 2020-04-09 19:38:43 +01:00
Asim Aslam 53549b6b30 Add options for Database/Table (#1516)
* Add options for Database/Table

* fix opts
2020-04-09 17:56:13 +01:00
Jake Sanders 0a27a08184 Add Databases and Tables endpoints to store RPC proto (#1515)
* Add Databases and Tables to store RPC

* add Database to TablesRequest
2020-04-09 16:37:32 +01:00
Janos Dobronszki 77f0abb0ba Enabling micro run for subfolders (#1510)
* Enabling micro run for subfolders

* Use source instead of os.Args[2]

* Works now

* PR comments

* WorkDir -> Dir
2020-04-09 15:44:39 +01:00
Asim Aslam 29cccd0b4a minor tweak add log line to proxy and basic auth provider by default (#1513) 2020-04-09 14:10:17 +01:00
ben-toogood bf65dc71c7 Merge pull request #1505 from micro/resover-refactor
Extract Micro Resolver (Namespace)
2020-04-09 13:14:49 +01:00
Asim Aslam 5bc8ee39f7 Merge branch 'master' into resover-refactor 2020-04-09 13:07:05 +01:00
Vasiliy Tolstov 8c1b477279 store/cockroach: fixup test (#1512)
* store/cockroach: fixup test

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-04-09 14:58:50 +03:00
Ben Toogood f9cfbe96c0 Merge master into resover-refactor 2020-04-09 12:42:34 +01:00
Jake Sanders 2e379ca7d0 Don't break the build! 2020-04-09 12:18:02 +01:00
Jake Sanders 2659215d5e cockroachDB doesn't support this syntax (#1509) 2020-04-09 12:11:24 +01:00
Vasiliy Tolstov 1063b954de dont display t.Log/t.Logf as errors in github actions (#1508)
* fix tests and github action annotations

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-04-09 14:05:46 +03:00
Ben Toogood 4ff959ef50 Dynamic Namespace 2020-04-09 11:03:33 +01:00
Janos Dobronszki bc1c8223e6 Remove ugly unneeded log in runtime local (#1507) 2020-04-09 11:50:12 +02:00
Ben Toogood 27eb7db1c2 Add default resolver to api router 2020-04-09 10:34:21 +01:00
Ben Toogood 3ede494945 Change import name 2020-04-09 10:32:08 +01:00
Ben Toogood f102aba4c1 Fix HTTP tests 2020-04-09 10:28:38 +01:00
Asim Aslam f2dd091ec0 strip log 2020-04-09 10:28:16 +01:00
Asim Aslam c1ad6d6c7c set service name in web 2020-04-09 09:41:50 +01:00
Jake Sanders 1e7cd8c484 Make the constraint explicit rather than inferred (#1506) 2020-04-08 23:52:35 +01:00
Asim Aslam bf8ebf8ad2 add namespace 2020-04-08 23:27:32 +01:00
Asim Aslam 1768958af7 fix typo 2020-04-08 22:50:56 +01:00
Asim Aslam bf41d8d28e fix store table env var 2020-04-08 19:44:49 +01:00
Asim Aslam 45700eaabe set database/table in header 2020-04-08 19:25:57 +01:00
Asim Aslam 48dd30c4c2 fix http test 2020-04-08 19:20:43 +01:00
Ben Toogood 8ff86ae08b Extract micro resolver 2020-04-08 16:21:53 +01:00
Asim Aslam b2079669f7 Strip namespace from router 2020-04-08 15:39:01 +01:00
Asim Aslam 2c1d1afd71 Strip namespace from registry router 2020-04-08 15:38:02 +01:00
Asim Aslam 9a73828782 Remove unused handlers 2020-04-08 15:34:11 +01:00
ben-toogood c5d085cff8 Merge pull request #1496 from micro/namespace
Configurable Namespace & Public Suffix Domain Resolution
2020-04-08 13:48:50 +01:00
ben-toogood 9f4286fc4e Merge branch 'master' into namespace 2020-04-08 13:44:46 +01:00
Jake Sanders 77f5cc5023 Fix nil dereference in cloudflare store (#1504) 2020-04-08 13:00:30 +01:00
Vasiliy Tolstov 8400aba81c broker/memory: small memory improvements (#1501)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-04-08 14:56:54 +03:00
Jake Sanders cc027d900e Close statements, add default table if the store was not initialised through service.Init() (#1502) 2020-04-08 12:08:08 +01:00
Edward bc0dc2e509 fix :no syscall.Kill on windows #1474 (#1474) 2020-04-08 10:50:44 +01:00
Vasiliy Tolstov 1fbc056dd4 minimize allocations (#1472)
* server: minimize allocations on re-register

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* server: stop old instance before Init()

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* client/grpc: fix allocations in protobuf marshal

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* codec/json: fix allocations in protobuf marshal

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* remove stop from init

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* codec/grpc: expose MaxMessageSize

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* codec: use buffer pool

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* metadata: minimize reallocations

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* util/wrapper: use metadata helper

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* registry/cache: move logs to debug level

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* server: move logs to debug level

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* server: cache service only when Advertise is ip addr

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* server: use metadata.Copy

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-04-08 10:50:19 +01:00
Asim Aslam 98fc3dfbad use single data bucket 2020-04-08 09:57:51 +01:00
Asim Aslam 4b0e27413e add Store Close method (#1500)
* add Store Close method

* Update sync store build failure
2020-04-08 09:51:10 +01:00
ben-toogood 6b524e2c55 Merge branch 'master' into namespace 2020-04-08 09:12:28 +01:00
Asim Aslam 4cac7dcc48 fix file tests 2020-04-07 19:45:27 +01:00
Ben Toogood e907d24e3b API Wrappers 2020-04-07 19:29:26 +01:00
Asim Aslam 39c352f210 Remove the test that takes 30 seconds sleeping 2020-04-07 18:22:40 +01:00
Ben Toogood 67cd59d7bc Rename namespace from Resolver.Endpoint 2020-04-07 16:27:59 +01:00
Ben Toogood 3735b0e529 Remove global namespace option 2020-04-07 16:27:01 +01:00
Ben Toogood 4362a885eb Refactor Namespace Resolver 2020-04-07 16:24:51 +01:00
Janos Dobronszki 038b936ce9 Setting up file store in constructor and not in init which is o… (#1499) 2020-04-07 16:43:43 +02:00
Vasiliy Tolstov 6aaad7d63f api/router/static: allow to specify body dst (#1486)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-04-07 15:38:27 +01:00
Janos Dobronszki aaee01b1a7 Use file store by default (as opposed to memory store) (#1498)
* Use file store by default (as opposed to memory store)

* Default table for file store
2020-04-07 15:19:45 +02:00
Jake Sanders 71538adfdc Explicitly set the table name during service init (#1497) 2020-04-07 13:00:05 +01:00
Janos Dobronszki 2ea5b33955 Disk backed local store (#1491) 2020-04-07 13:53:22 +02:00
Ben Toogood 3df87510a1 Add namespace 2020-04-07 12:46:44 +01:00
Ben Toogood 9d598836c3 Fix Tests 2020-04-07 11:37:04 +01:00
Ben Toogood 05ac3ff274 Tweak 2020-04-07 11:24:13 +01:00
Ben Toogood 76f6f80318 Default to Hostname 2020-04-07 11:23:21 +01:00
Ben Toogood cb96949551 Merge branch 'master' of https://github.com/micro/go-micro into namespace 2020-04-07 10:58:54 +01:00
ben-toogood 87cc4f273b Merge pull request #1495 from micro/log-level
Change cross namespace request err level
2020-04-07 10:58:22 +01:00
Ben Toogood f0980e9b30 Change cross namespace request err level 2020-04-07 10:54:27 +01:00
Ben Toogood 977934f8fd ServiceNamespace => ServicePrefix in api server 2020-04-07 10:39:27 +01:00
Ben Toogood 9e116731b1 ServiceNamespace => ServicePrefix in api server 2020-04-07 10:38:27 +01:00
Ben Toogood 316424f0f7 Fix comments typo 2020-04-07 10:35:57 +01:00
Ben Toogood bd23dc1f18 Improve micro.mu check 2020-04-07 10:34:26 +01:00
Ben Toogood 501fc5c059 Refactor to use publicsuffix 2020-04-07 10:28:39 +01:00
Ben Toogood 11e1e9120a Remove debugging 2020-04-07 10:10:37 +01:00
Ben Toogood a81d86ed08 Merge Asim's Fixes 2020-04-07 10:08:06 +01:00
Ben Toogood 7206d5f964 Add Namespace to CombinedAuthHandler 2020-04-07 09:40:40 +01:00
Asim Aslam b5f5027549 Move store scope to util 2020-04-07 02:23:16 +01:00
Asim Aslam e8a86585da contains missing host port 2020-04-07 00:54:27 +01:00
Asim Aslam 5374896ed0 clone request 2020-04-07 00:29:35 +01:00
Asim Aslam b6348ba59a Fix cruft 2020-04-07 00:25:11 +01:00
Asim Aslam ca11c4a672 Few nitpicks 2020-04-07 00:19:49 +01:00
Lars Lehtonen 900b2d24f9 config/secrets/box: fix dropped test error (#1494) 2020-04-06 23:09:42 +01:00
Jake Sanders 3324d140c0 Rename store Namespace / Prefix options to Database and Table (#1492)
* Rename Namespace to DB, Rename Prefix to table, Remove Suffix Option

* Rename options

* Rename options

* Add store_table option

* Table per service, not Database per service
2020-04-06 16:45:55 +01:00
ben-toogood 3a378eb7d6 Merge pull request #1493 from micro/auth-encode-endpoint
Encode Endpoint in API auth wrapper
2020-04-06 16:21:14 +01:00
Ben Toogood 574bf5ac69 Set value in context, not metadata 2020-04-06 16:10:08 +01:00
Ben Toogood 774c0d30a7 Encode Endpoint in API auth wrapper 2020-04-06 16:01:42 +01:00
ben-toogood 0f570d98e1 Merge pull request #1475 from micro/auth-resolver
Auth integrate resolver to support micro web & api
2020-04-06 14:57:41 +01:00
ben-toogood 7f07e1a642 Merge branch 'master' into auth-resolver 2020-04-06 14:43:22 +01:00
ben-toogood 9b546a7242 Change auth namespace log level (#1490)
Co-authored-by: Ben Toogood <ben@micro.mu>
2020-04-06 13:51:28 +01:00
Asim Aslam c4442a7533 Don't set the registry in new options for web services (#1489) 2020-04-06 13:40:40 +01:00
ben-toogood bea7c3f7e7 Merge pull request #1488 from micro/disable-warn-log
Change namespace error log level
2020-04-06 12:55:47 +01:00
ben-toogood cca9773269 Merge branch 'master' into disable-warn-log 2020-04-06 12:51:47 +01:00
Ben Toogood 600b20fb81 Change namespace error log level 2020-04-06 12:50:04 +01:00
Edward 31a1ea6fae fix: use registry from opts not use default directly:(#1436) (#1468)
web: use passed user registry, or default
2020-04-05 13:15:38 +03:00
Vasiliy Tolstov bc7579f1d8 api/handler/rpc: fix panic on invalid error conversation (#1483)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-04-04 00:55:15 +03:00
Vasiliy Tolstov 38aed6f0f6 api/handler/rpc: not log error on client disconnect (#1482)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-04-04 00:37:18 +03:00
ben-toogood 7f8b35e295 Merge pull request #1480 from micro/host-fix
Add Debugging
2020-04-03 15:07:22 +01:00
ben-toogood b09dd9a689 Merge branch 'master' into host-fix 2020-04-03 15:03:49 +01:00
Ben Toogood a82ce4d1ae Add Debug 2020-04-03 15:03:18 +01:00
ben-toogood 34234fc486 Merge pull request #1479 from micro/host-fix
Auth host fix
2020-04-03 14:43:35 +01:00
Ben Toogood 4a850ff8a0 Auth host fix 2020-04-03 14:40:24 +01:00
ben-toogood 350dd41732 Merge branch 'master' into auth-resolver 2020-04-03 14:19:03 +01:00
ben-toogood d8cca31738 Merge pull request #1478 from micro/auth-hosts-fix
Fix auth hosts bug
2020-04-03 14:13:51 +01:00
Ben Toogood b864b3e350 Fix auth hosts bug 2020-04-03 14:09:25 +01:00
ben-toogood 41b746e435 Merge pull request #1477 from micro/fix
Hotfix
2020-04-03 13:37:50 +01:00
Ben Toogood 906263291b Hotfix 2020-04-03 13:37:02 +01:00
ben-toogood 46f0bda31e Merge pull request #1476 from micro/namespace-fix
Namespace Fix
2020-04-03 13:30:30 +01:00
Ben Toogood d0e47206cc Fix 2020-04-03 13:29:48 +01:00
ben-toogood ed6fe67880 Merge pull request #1471 from micro/namespace
Detect & Propagate Namespace
2020-04-03 13:07:26 +01:00
Ben Toogood 1374a9e528 Fix namespace bug in auth wrapper 2020-04-03 13:03:27 +01:00
Ben Toogood a9c0e043d2 Fix nil grpc server auth bug 2020-04-03 12:50:50 +01:00
Ben Toogood 49a568e9c0 Set default server auth 2020-04-03 12:33:19 +01:00
Ben Toogood dea2d7ab9f Fix go-micro auth wrapper init 2020-04-03 12:27:01 +01:00
Ben Toogood ebb1a42d48 Merge branch 'namespace' of https://github.com/micro/go-micro into namespace 2020-04-03 12:14:26 +01:00
Ben Toogood 1096c8fb39 Fix failing test 2020-04-03 10:16:19 +01:00
Ben Toogood 91b9c3f92e Add defaults 2020-04-03 10:08:39 +01:00
Ben Toogood 183c8bfb81 Apply fix for apis 2020-04-03 09:45:39 +01:00
Ben Toogood 49a1130281 Merge branch 'auth-resolver' of https://github.com/micro/go-micro into auth-resolver 2020-04-03 09:34:57 +01:00
Ben Toogood 760233b858 Reverse Change 2020-04-03 09:34:52 +01:00
ben-toogood ede076e899 Merge branch 'master' into auth-resolver 2020-04-03 09:33:13 +01:00
Ben Toogood fdcb013f24 Fix web registry compatability bugs 2020-04-03 09:18:30 +01:00
Ben Toogood ce23ab36cb Improve Err Handling 2020-04-02 18:41:06 +01:00
ben-toogood 61f0619e97 Merge branch 'master' into namespace 2020-04-02 18:05:21 +01:00
Ben Toogood cfde3ec3d9 Remove resolver logic 2020-04-02 18:03:57 +01:00
Ben Toogood 4a4c666528 Remove resolver logic 2020-04-02 18:03:21 +01:00
Ben Toogood 8b35c264eb Pass resolver to api auth handler 2020-04-02 17:44:48 +01:00
Ben Toogood 4999f6dfd4 Namespace requests coming via api & web 2020-04-02 17:01:06 +01:00
Asim Aslam 31c4452fc7 delete monitor (#1470) 2020-04-02 14:05:17 +01:00
Janos Dobronszki 2cafa289b6 Stop LogStream if there is an error in k8s pod log streaming (#1469)
* Stop LogStream if there is an error in k8s pod log streaming

* Locking stream Stops

* PR comment
2020-04-02 12:16:35 +01:00
Vasiliy Tolstov 0241197c6a api/handler/rpc: binary streaming support (#1466)
* api/handler/rpc: binary streaming support

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* fixup

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* fix

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* fix sec webscoekt protol

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-04-02 10:13:04 +01:00
Asim Aslam 0a15ae9b9d Move String method (#1467) 2020-04-01 23:27:15 +01:00
Janos Dobronszki d2b6d35220 log.Errorf when pod streaming fails (#1463)
* log.Errorf when pod streaming fails

* Error method added for loggers

Co-authored-by: Asim Aslam <asim@aslam.me>
2020-04-01 23:03:26 +01:00
Asim Aslam e1bc0f6288 replace strings for store prefix (#1465)
Co-authored-by: ben-toogood <bentoogood@gmail.com>
2020-04-01 20:19:21 +01:00
ben-toogood cd3d704aa5 Merge pull request #1459 from micro/auth-interface-update
Auth Interface Iteration
2020-04-01 17:56:38 +01:00
Ben Toogood 9de69529ce Fix token tests 2020-04-01 17:29:17 +01:00
ben-toogood 623f0c0c90 Merge branch 'master' into auth-interface-update 2020-04-01 17:24:01 +01:00
Ben Toogood c766679687 Fix typo 2020-04-01 17:22:01 +01:00
Ben Toogood df8c0bb5e1 Auth Generate, make secret optional 2020-04-01 17:20:02 +01:00
Ben Toogood d577c32563 Add back auth.PrivateKey 2020-04-01 17:17:40 +01:00
Ben Toogood 365dfe9df5 Code => State 2020-04-01 17:11:46 +01:00
Ben Toogood ae15793fc3 Support oauth codes 2020-04-01 15:36:22 +01:00
Janos Dobronszki 15fcd5ecef Remove Go micro 1.18 dependency (#1462) 2020-04-01 16:14:08 +02:00
Ben Toogood 1750fd8d10 Merge branch 'auth-interface-update' of https://github.com/micro/go-micro into auth-interface-update 2020-04-01 14:42:37 +01:00
Ben Toogood 525ab094c8 Remove LoginOptions 2020-04-01 14:42:11 +01:00
Janos Dobronszki bb51b8203e Runtime logs (#1447)
* Runtime logs

* Slightly broken

* Pushing for diff

* Log trailing works locally

* LogsOptions

* Comments and streamcount support for local logs

* Adding kubernetes logs

* Fixing k8s logs

* K8s fixes

* StreamCount is now nuked

* PR comments

* PR comments again

* Fix typo
2020-04-01 15:40:15 +02:00
ben-toogood 75a75c56ad Merge branch 'master' into auth-interface-update 2020-04-01 14:37:06 +01:00
Ben Toogood 26cb6bf5b9 Remove Legacy JWT fields 2020-04-01 14:27:56 +01:00
Ben Toogood 9cbbd71855 Remove default login 2020-04-01 14:26:24 +01:00
Ben Toogood f7655b71ea Merge branch 'auth-interface-update' of https://github.com/micro/go-micro into auth-interface-update 2020-04-01 14:25:07 +01:00
Ben Toogood 8e4d9e1702 Further Refactoring 2020-04-01 14:25:00 +01:00
Asim Aslam 20c95d94cd api completeness (#1460) 2020-04-01 12:07:50 +01:00
ben-toogood 0a7d8afe67 Merge branch 'master' into auth-interface-update 2020-04-01 09:42:45 +01:00
Vasiliy Tolstov 7b7a859a03 api: use http request Clone (#1458)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-04-01 01:50:37 +03:00
Vasiliy Tolstov 8a8742f867 api/handler/rpc: dont change types of url fields (#1457)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-04-01 01:26:58 +03:00
Asim Aslam 68b0238a5d add stream timeout option which defaults to 0 (#1456)
* add stream timeout option which defaults to 0

* fix option
2020-03-31 23:22:11 +01:00
Vasiliy Tolstov 1490aff38e api/handler/rpc: correctly parse nested url vars (#1455)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-04-01 00:23:17 +03:00
Vasiliy Tolstov 3a22efbd7d metadata: change method name (#1454)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-03-31 23:39:18 +03:00
Vasiliy Tolstov 5e65a46be3 metadata: allow to remove key from metadata (#1453)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-03-31 22:55:33 +03:00
Vasiliy Tolstov 18061723bb fix api metadata extract from context (#1452)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-03-31 22:36:51 +03:00
Vasiliy Tolstov d6bef84de0 api/handler/rpc: fix metadata cleanup (#1451)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-03-31 21:59:35 +03:00
Ben Toogood 82bc3cbf8d Update interface to add provider and make secret optional 2020-03-31 19:01:43 +01:00
Ben Toogood cffb0a1eae Remove ContextWithToken 2020-03-31 18:34:31 +01:00
Ben Toogood 134bc1c68a Implement new interface 2020-03-31 18:17:01 +01:00
Asim Aslam 6c6c5359b1 Add options to config (#1450) 2020-03-31 17:13:21 +01:00
Ben Toogood 8dbb5153f4 Tweak Auth Interface 2020-03-31 17:01:51 +01:00
ben-toogood 2674790694 Service => Service Auth (#1448)
* Service => Service Auth

* WithServicePrivileges => ServicePrivileges

* Fixes for CLI login

* ServicePrivileges => ServiceToken

* Fallback to service token

Co-authored-by: Ben Toogood <ben@micro.mu>
2020-03-31 16:18:04 +01:00
ben-toogood 9fb1d476a2 Merge branch 'master' into auth-srv-srv 2020-03-31 16:15:17 +01:00
Ben Toogood 36386354d7 Fallback to service token 2020-03-31 13:51:32 +01:00
Ben Toogood bd70820b6b ServicePrivileges => ServiceToken 2020-03-31 13:48:28 +01:00
Ben Toogood 956029ae3d Fixes for CLI login 2020-03-31 13:30:14 +01:00
Ben Toogood e0c7f48d20 WithServicePrivileges => ServicePrivileges 2020-03-31 12:57:38 +01:00
Ben Toogood d659e435c6 Service => Service Auth 2020-03-31 12:44:34 +01:00
Jake Sanders 3d274ab6a2 Add namespace support to Kubernetes client (#1446)
* Add namespace support to Kubernetes client

* Fix LastUpdateTime Condition
2020-03-31 12:03:32 +01:00
Asim Aslam 1222d076f2 There can be only one! (#1445)
Run tests / Test repo (push) Waiting to run
* There can be only one

* fix proto?
2020-03-31 10:18:50 +01:00
ben-toogood 76ade7efd9 Auth - Swap Refresh to Token and change secrets to be strings, not tokens (#1444)
* Refresh => Token

* Secret is no longer a token

Co-authored-by: Ben Toogood <ben@micro.mu>
2020-03-31 10:06:13 +01:00
Vasiliy Tolstov c706ebe3fb auth proto: provide help to protoc-gen-go (#1442)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-03-31 00:35:11 +03:00
Vasiliy Tolstov 9e6db79860 regenerate all proto (#1440)
* regenerate all proto

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* regenerate from proto

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* regenerate from proto

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-03-30 21:58:32 +01:00
Vasiliy Tolstov 756b346672 auth/service: move all proto files to single dir (#1439)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-03-30 18:23:00 +03:00
ben-toogood 4db2f5e79d Add Namespace to Auth (#1438)
Co-authored-by: Ben Toogood <ben@micro.mu>
2020-03-30 09:51:37 +01:00
Vasiliy Tolstov 3d7d5ce6b4 api: add static router and improve path parser in rpc handler (#1437)
* api: add static router and improve path parser in rpc handler

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* expose metadata context key to be able to get unmodified map keys

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* server/grpc: fix jsonpb codec for protobuf msg

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* api/handler/rpc: write 204 status code when rsp is nil

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* api/handler/rpc: add check for nil response for non javascript

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-03-30 09:04:59 +01:00
Socket 8282e781e4 grpc pool should check state (#1435)
Co-authored-by: huangshaojie <huangshaojie@corp.netease.com>
2020-03-28 08:48:25 +00:00
Vasiliy Tolstov e4acc63d5f add mdns registry debug (#1434)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-03-27 22:33:49 +03:00
Asim Aslam 45ee5e9ad1 Move error for api validation to trace level (#1432)
* remove error on endpoint validation

* trace level
2020-03-27 14:01:47 +00:00
Asim Aslam b60fde0e64 Pass through source and metadata in Update and Delete calls to runtime (#1431) 2020-03-27 11:37:12 +00:00
Lars Lehtonen 011a783a9e store/cockroach: fix dropped test errors (#1419)
Co-authored-by: Asim Aslam <asim@aslam.me>
2020-03-27 10:15:37 +00:00
ben-toogood 6723d17b22 Default auth, return account secret on Inspect (#1430)
Co-authored-by: Ben Toogood <ben@micro.mu>
2020-03-27 09:54:29 +00:00
ben-toogood 47c7181d41 Default Auth: Add blank secret to account to prevent nil errors (#1429)
* Remove debug auth logs

* Default auth, return account secret on Inspect

Co-authored-by: Ben Toogood <ben@micro.mu>
2020-03-27 09:46:17 +00:00
Vasiliy Tolstov b38da6ced0 api/handler/rpc: process all methods and merge url params to json body (#1427)
* api/handler/rpc: process all methods and merge url params to json body

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* add merge json test

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-03-27 07:59:31 +00:00
ben-toogood 1a53307a78 Remove debug auth logs (#1426)
Co-authored-by: Ben Toogood <ben@micro.mu>
2020-03-26 19:00:24 +00:00
Asim Aslam e204f3e2e8 Add metadata Get method (#1425) 2020-03-26 18:50:00 +00:00
ben-toogood 329bd09f93 Fix Auth Init bug (#1424)
Co-authored-by: Ben Toogood <ben@micro.mu>
2020-03-26 18:09:51 +00:00
ben-toogood 4648fd0d09 Auth debugging (#1423)
* More auth debugging

* More auth debugging

* Increase auth debugging

Co-authored-by: Ben Toogood <ben@micro.mu>
2020-03-26 17:55:35 +00:00
ben-toogood c905df3be6 Log auth verify requests (#1422)
* More auth debugging

* More auth debugging

Co-authored-by: Ben Toogood <ben@micro.mu>
2020-03-26 17:35:28 +00:00
Asim Aslam 62f9a054a4 100mb (#1421) 2020-03-26 16:57:31 +00:00
ben-toogood 00e7804f96 Auth - Add debugging to loading rules (#1420)
* Fix auth multi-rule edgecase

* Add logging to auth rules

Co-authored-by: Ben Toogood <ben@micro.mu>
2020-03-26 16:30:31 +00:00
ben-toogood 42b6bf5bbf Fix auth multi-rule edgecase (#1418)
Co-authored-by: Ben Toogood <ben@micro.mu>
2020-03-26 15:52:48 +00:00
ben-toogood 844c456839 Refactor Auth Service Protos, Add Access Rules (#1411)
* Refactor auth/service into two protos

* Accounts Proto

* Store Prefixes

* Misc

* Tweak Protos

Co-authored-by: Ben Toogood <ben@micro.mu>
Co-authored-by: Asim Aslam <asim@aslam.me>
2020-03-26 13:12:43 +00:00
Asim Aslam 7182ca1fd0 fix server logging (#1417) 2020-03-26 13:08:06 +00:00
Vasiliy Tolstov 02839cfba5 api/handler: use http.MaxBytesReader and buffer pool (#1415)
* api/handler: use http.MaxBytesReader

protect api handlers from OOM cases

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-03-26 14:29:28 +03:00
Asim Aslam 776a7d6cd6 Update filter comment for proxy (#1416) 2020-03-26 08:05:00 +00:00
Vasiliy Tolstov beaa434610 logger: fix reading env var (#1414)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-03-25 22:00:43 +00:00
Asim Aslam 6efc5556e5 use requested service (#1413) 2020-03-25 20:59:37 +00:00
Asim Aslam 8d0826a031 Add check for k8s condition (#1412) 2020-03-25 19:32:41 +00:00
ben-toogood 378d03eb66 Tidying up auth (#1410)
* Don't clear auth rules if request fails

* Add jitter to auth service loading rules

* Remove unused error from ContextWithToken result

Co-authored-by: Ben Toogood <ben@micro.mu>
2020-03-25 18:34:13 +00:00
ben-toogood 56af826230 Update auth to pass seconds and not nanoseconds (#1409)
Co-authored-by: Ben Toogood <ben@micro.mu>
2020-03-25 17:03:45 +00:00
ben-toogood 511ebd8ec2 Fix Token Expiry Bug (#1408)
Co-authored-by: Ben Toogood <ben@micro.mu>
2020-03-25 14:40:37 +00:00
ben-toogood 1057ef6acb Add ContextWithToken (#1407)
* Add ContextWithToken

* Tidying up BearerScheme

Co-authored-by: Ben Toogood <ben@micro.mu>
2020-03-25 11:20:53 +00:00
ben-toogood 35e2a68a98 Fix auth bug restricting access to unauthorised endpoints (#1405)
Co-authored-by: Ben Toogood <ben@micro.mu>
2020-03-25 10:31:33 +00:00
ben-toogood 0e56382107 Fix service level auth, add improved error descriptions to aid with debugging (#1403)
Co-authored-by: Ben Toogood <ben@micro.mu>
2020-03-25 09:35:29 +00:00
Jake Sanders dff98355be Missing ; in SQL query 2020-03-24 23:49:09 +00:00
Vasiliy Tolstov 8100d26430 api/router/registry: use logger (#1402)
* api/router/registry: use logger

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* api/server/acme: use logger

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-03-24 20:45:11 +00:00
Jake Sanders 397a8638f4 Cockroach Store bugfix (#1401) 2020-03-24 17:16:38 +00:00
Jake Sanders eb4d2ae6aa Remove useless variable from cockroach store (#1400) 2020-03-24 15:37:30 +00:00
Jake Sanders 914340585c Trim space from env variables (#1399) 2020-03-24 14:51:43 +00:00
ben-toogood 84b4eb5404 Fix missing loop (#1398)
* WithRoles variadic args

* Load Rules

* Timer => Ticker

* Add missing for loop in auth service

Co-authored-by: Ben Toogood <ben@micro.mu>
2020-03-24 14:16:57 +00:00
ben-toogood fd664f4392 Auth load rules (#1397)
* WithRoles variadic args

* Load Rules

* Timer => Ticker

Co-authored-by: Ben Toogood <ben@micro.mu>
2020-03-24 13:48:37 +00:00
ben-toogood 86272a3064 WithRoles variadic args (#1395)
Co-authored-by: Ben Toogood <ben@micro.mu>
2020-03-24 10:18:34 +00:00
ben-toogood c1978265ab Auth Wildcard Endpoints (#1394)
* Auth Wildcard Endpoints

* Fix joinkey bug, improve tests

* Change joinKey

Co-authored-by: Ben Toogood <ben@micro.mu>
2020-03-24 09:39:33 +00:00
ben-toogood e0e77f3983 Updated auth interface (#1384)
* Updated  auth interface

* Add Rule

* Remove Rule

* Return token from Renew

* Renew => Refresh

* Implement Tokens & Default Auth Implementation

* Change default auth to noop

* Change default auth to noop

* Move token.Token to auth.Token

* Remove Token from Account

* Auth service implementation

* Decode JWT locally

* Cookie for secret

* Move string to bottom of interface definition

* Depricate auth_exclude

* Update auth wrappers

* Update go.sum

Co-authored-by: Ben Toogood <ben@micro.mu>
2020-03-23 16:19:30 +00:00
Vasiliy Tolstov 9826ddbd64 api/handler/rpc: log errors (#1390)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-03-23 10:31:35 +03:00
0987363 87617be227 Add client header to rpcRequest header; issue #957 (#1378)
Co-authored-by: Asim Aslam <asim@aslam.me>
2020-03-21 23:25:23 +00:00
Vasiliy Tolstov d559587807 client/grpc: remove json-iterator usage (#1387)
* minimize external deps and binary size
* if user wants json-iterator codec it must be used in server and
  client code. so best to use it via go-plugins

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-03-21 09:40:58 +00:00
Janos Dobronszki 9501512219 Auth util func RequestToContext (#1386) 2020-03-20 15:23:12 +00:00
Asim Aslam d2f153d795 Add type of service (#1385) 2020-03-20 12:48:12 +00:00
Asim Aslam e49be1da42 fix local runtime (#1383) 2020-03-19 22:38:37 +00:00
Jake Sanders 4c6f68d537 Implement store read cache (#1366)
* Implement store read cache

* Added cache tests and fixed a bug in memory store
2020-03-19 18:19:07 +00:00
Vasiliy Tolstov cbb958def5 config: fix panic on multiple Close() (#1374)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-03-19 12:54:59 +03:00
Asim Aslam 40ff6ddfcf sigh, further status changes (#1371) 2020-03-18 22:47:03 +00:00
Asim Aslam 5ad7c36bd4 Fix labels for k8s (#1370) 2020-03-18 22:13:21 +00:00
Asim Aslam 99c3fe2bb8 fix status parsing (#1368) 2020-03-18 21:50:52 +00:00
Asim Aslam 1bd340701b add k8s service ip to metadata (#1367)
* add k8s service ip to metadata

* go fmt

* use same port as container
2020-03-18 18:27:29 +00:00
Jake Sanders c91bf7e9e7 [WIP] Store Sync (#1365)
* Initial cache implementation

* Write queue implementation

* Accidentally started writing the storage sync service
2020-03-18 16:39:36 +00:00
Vasiliy Tolstov 41f8a8cb00 errors: add FromError func (#1362)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-03-18 03:10:38 +03:00
ben-toogood cd04111e3d Pass redirect_to param on auth (#1361)
Co-authored-by: Ben Toogood <ben@micro.mu>
2020-03-17 20:04:16 +00:00
ben-toogood 00cd2448a4 Fix bug where auth token is not set from cookie when excluded endpoint (#1360)
Co-authored-by: Ben Toogood <ben@micro.mu>
2020-03-17 19:24:10 +00:00
ben-toogood 8a41d369f2 Auth JWT ID Fix (#1359)
* Auth JWT ID Fix

* Remove unused ID in jwt claims

Co-authored-by: Ben Toogood <ben@micro.mu>
2020-03-17 16:59:57 +00:00
Jake Sanders 638c219736 Cockroach store feature completion (#1358)
* Start fixing cockroach store

* Add prefix, suffix, limit, offset for cockroachdb store
2020-03-17 16:15:23 +00:00
ben-toogood b3c631dd38 Support Wildcard Auth Excludes (#1357)
Co-authored-by: Ben Toogood <ben@micro.mu>
2020-03-17 16:03:49 +00:00
Vasiliy Tolstov ab73127063 grpc client/server fixes (#1355)
Run tests / Test repo (push) Waiting to run
* grpc client/server fixes

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-03-17 14:27:20 +03:00
Asim Aslam 03031a694d use pod phase/status (#1356) 2020-03-16 23:47:34 +00:00
li.peng 5712aafba9 fix: context cancel (#1350)
Co-authored-by: Asim Aslam <asim@aslam.me>
2020-03-16 10:45:33 +00:00
Vasiliy Tolstov ac333d9d47 client/grpc: unwrap error after call (#1352)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-03-16 13:33:38 +03:00
ben-toogood 247707f583 Return store.ErrNotFound if not found when calling over rpc (#1353)
Co-authored-by: Ben Toogood <ben@micro.mu>
2020-03-16 10:30:56 +00:00
ben-toogood d91c14eb30 grpc client error fix (#1351)
Co-authored-by: Ben Toogood <ben@micro.mu>
2020-03-16 12:53:15 +03:00
Asim Aslam ca8684a886 fix k8s issues (#1349) 2020-03-15 15:09:18 +00:00
Asim Aslam 0449138f61 fix panic (#1348) 2020-03-14 21:18:41 +00:00
Vasiliy Tolstov 609f4826b3 server: remove duplicate code (#1346)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-03-13 22:15:09 +00:00
Vasiliy Tolstov 60993e6275 config/source/service: base64 fix (#1345)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-03-13 21:44:55 +00:00
Asim Aslam e803fb0855 Runtime hacks (#1344)
* Add Args/Image to runtime

* remove the hacks
2020-03-13 18:39:59 +00:00
Vasiliy Tolstov 3543b275e0 fix log level helper (#1342)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-03-13 17:36:42 +03:00
Vasiliy Tolstov fbde872e7f Revert "server/grpc: fix ordering of register and check for registered (#1338)" (#1341)
This reverts commit 62a644ddd8.
2020-03-13 09:30:44 +00:00
Asim Aslam 078dd4eb9b fix etcd (#1340)
* fix etcd

* update go mod
2020-03-13 08:55:23 +00:00
Vasiliy Tolstov 62a644ddd8 server/grpc: fix ordering of register and check for registered (#1338)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-03-12 22:04:11 +00:00
Asim Aslam d8cfa7a295 add config to cmd (#1337)
* add config to cmd

* fix build
2020-03-12 18:47:40 +00:00
ben-toogood 47f1203e97 Add Config to service options (#1336)
Co-authored-by: Ben Toogood <ben@micro.mu>
Co-authored-by: Asim Aslam <asim@aslam.me>
2020-03-12 18:13:03 +00:00
Jake Sanders 1b4e881d74 Rewrite the store interface (#1335)
* WIP store rewrite

* Fix memory store tests

* Store hard expiry times rather than duration!

* Clarify memory test

* Add limit to store interface

* Implement suffix option

* Don't return nils from noop store

* Fix syncmap

* Start fixing store service

* wip service and cache

* Use _ for special characters in cockroachdb namespace

* Improve cockroach namespace comment

* Use service name as default store namespace

* Fixes

* Implement Store Scope

* Start fixing etcd

* implement read and write with expiry and prefix

* Fix etcd tests

* Fix cockroach store

* Fix cloudflare interface

* Fix certmagic / cloudflare store

* comment lint

* cache isn't implemented yet

* Only prepare DB staements once

Co-authored-by: Ben Toogood <ben@micro.mu>
Co-authored-by: ben-toogood <bentoogood@gmail.com>
2020-03-12 13:41:30 +00:00
ben-toogood 20ce61da5a Oauth google fixes (#1330)
* Fix Auth Headers

* Tweak Oauth to work for Google

Co-authored-by: Ben Toogood <ben@micro.mu>
Co-authored-by: Asim Aslam <asim@aslam.me>
2020-03-12 13:11:35 +00:00
chengguoqiang eef4825be4 Update etcd.go (#1334)
add leaseId to the trace log
2020-03-12 10:09:38 +00:00
Asim Aslam be9c6141f5 delete options (#1333) 2020-03-12 09:05:09 +00:00
Asim Aslam 1ca4619506 return store.ErrNotFound (#1332) 2020-03-11 23:09:42 +00:00
Asim Aslam f55493993c set namespace rather than key (#1331) 2020-03-11 22:31:24 +00:00
Vasiliy Tolstov 7b385bf163 minimize allocations in logger and tunnel code (#1323)
* logs alloc

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* fix allocs

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* fix allocs

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* tunnel allocs

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* try to fix tunnel

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* cache cipher for send

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* more logger

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* more logger

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* more logger

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* more logger

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* more logger

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* more logger

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* more logger

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-03-11 17:55:39 +00:00
Jake Sanders 4125ae8d53 Add secrets interface to config/secrets (#1325)
* Interface for secrets

* Add secretbox secrets implementation

* Start working on box

* typo

* Add asymmetric encryption implementation

* go mod tidy

* Fix review comments

Co-authored-by: Asim Aslam <asim@aslam.me>
2020-03-10 22:52:06 +00:00
ben-toogood 48b2a5c37c Fix Auth Headers (#1324)
Co-authored-by: Ben Toogood <ben@micro.mu>
2020-03-10 16:47:01 +00:00
Asim Aslam ed83c27f0e add websocket streaming to api rpc handler (#1326) 2020-03-10 15:21:43 +00:00
Vasiliy Tolstov 241614ff68 add helper function to determine logger level (#1321)
* add helper function to determine logger level

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-03-09 23:43:05 +03:00
mlboy 1a4f608ed1 add: auth add generate options Expiry for set token expires (#1319)
Co-authored-by: mlboy <ml3@meitu.com>
Co-authored-by: Asim Aslam <asim@aslam.me>
2020-03-09 17:16:31 +00:00
Vasiliy Tolstov 43b0dbb123 tunnel: reduce allocation and improve performance (#1320)
* tunnel: reduce allocation and improve performance

BenchmarkSha256Old-16 100000 156748 ns/op 11835 B/op 168 allocs/op
BenchmarkSha256Old-16 100000 156229 ns/op 11819 B/op 168 allocs/op

BenchmarkSha256New-16 100000 154751 ns/op 11107 B/op 161 allocs/op
BenchmarkSha256New-16 100000 154263 ns/op 11110 B/op 161 allocs/op

simple change lowers allocations and brings performance

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* fix

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* tunnel: reuse buf in Decrypt

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* fix unneeded conversations

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* base32 string is smaller than hex string

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-03-09 17:10:08 +00:00
ben-toogood b344171c80 URL Encode Provider.Endpoint() (#1317)
Co-authored-by: Ben Toogood <ben@micro.mu>
2020-03-09 10:21:49 +00:00
ben-toogood e3ce45495a os.Exit on log.Fatal (#1316)
* os.Exit on log.Fatal

* Fix TestOptions

Co-authored-by: Ben Toogood <ben@micro.mu>
2020-03-09 09:23:42 +00:00
Vasiliy Tolstov f01664a551 Merge pull request #1313 from micro/upstream
fix ipv6 address usage in mdns registry and util/addr
2020-03-07 23:50:03 +03:00
Vasiliy Tolstov 8ecbdc1cd6 registry/mdns: add logging for invalid endpoint
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-03-07 23:19:48 +03:00
Vasiliy Tolstov 55c19afb0b registry/mdns: fix ipv6 addr in mdns registry
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-03-07 23:17:00 +03:00
Vasiliy Tolstov 077063c212 util/addr: check ip addrs before return
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-03-07 23:13:56 +03:00
ben-toogood 9a7a65f05e Auth Provider (#1309)
* auth provider mock interface

* Auth Provider Options

* Implement API Server Auth Package

* Add weh utils

* Add Login URL

* Auth Provider Options

* Add auth provider scope and setting token in cookie

* Remove auth_login_url flag

Co-authored-by: Asim Aslam <asim@aslam.me>
Co-authored-by: Ben Toogood <ben@micro.mu>
2020-03-07 11:06:57 +00:00
Vasiliy Tolstov 8ee5607254 [WIP]: broker ErrorHandler option (#1296)
* broker ErrorHandler option

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* rewrite Event interface, add error

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* implement new interface

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* change ErrorHandler func to broker.Handler

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* fix

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-03-06 21:25:16 +00:00
Vasiliy Tolstov 11be2c68b9 util/stream: fix imports (#1310)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-03-06 21:17:57 +00:00
Vasiliy Tolstov a864f812f1 web: fix ipv6 address issue (#1308)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-03-06 18:44:56 +03:00
Asim Aslam ae60bea8d8 add stream fix (#1305) 2020-03-06 14:40:47 +00:00
Jake Sanders a851b9db7a Comment typo in gRPC subscriber (#1304) 2020-03-05 14:55:46 +00:00
Vasiliy Tolstov d807dac2a7 server/grpc: avoid panic in case of nil Header (#1303)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-03-05 17:45:31 +03:00
Vasiliy Tolstov ce2ba71002 server: subscribe to topic with own name if router not nil (#1295)
* server: subscribe to topic with own name if router not nil

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-03-05 10:29:50 +03:00
Asim Aslam 67c26c71b6 add jitter (#1298) 2020-03-04 15:37:17 +00:00
ben-toogood 9386f36a13 Exit on log.Fatal (#1297) 2020-03-04 13:46:01 +00:00
ben-toogood 6d803d9e45 Implement api/server/cors (#1294) 2020-03-04 11:40:53 +00:00
ben-toogood 6a9001bdb1 Set auth account in context (#1293) 2020-03-04 09:54:52 +00:00
Jake Sanders 3f0c28a815 Expiration is actually a unix timestamp (#1290)
* Expiration is actually a unix timestamp

* int -> int64
2020-03-03 18:15:50 +00:00
Asim Aslam 49ffc60afb Use Foo.Call on /foo (#1286)
Co-authored-by: Jake Sanders <i@am.so-aweso.me>
2020-03-03 16:47:15 +00:00
Jake Sanders beb5e80e87 Fix nil pointer dereference (#1289) 2020-03-03 13:54:56 +00:00
Jake Sanders eebd69c995 Change from renekroon/ttlcache to patrickmn/go-cache (#1288) 2020-03-03 13:35:49 +00:00
Jake Sanders bc71989e2c int64 -> time.Duration (#1287) 2020-03-03 13:15:26 +00:00
Vasiliy Tolstov 89ba602e17 logger fixes and improvements (#1285)
* fix helper fields
* add metadata output for default logger

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-03-03 11:07:37 +03:00
Jake Sanders f6102bde70 Add a cache to workers KV storage implementation (#1284)
* cloudflare-cache

* go mod tidy
2020-03-02 18:14:25 +00:00
Pieter Voorwinden 7cad77bfc0 Initialize header to prevent assignment to entry in nil map error (#1282)
Co-authored-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-03-02 19:17:26 +03:00
ben-toogood 1f2e067f71 k8s runtime - get status from pods (#1283) 2020-03-02 15:49:10 +00:00
Vasiliy Tolstov b555269b1b copy fields in helper (#1281)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-03-02 14:18:36 +00:00
ben-toogood 9200c70202 Replace validation error with regex for cockroach namespace (#1270)
Co-authored-by: Asim Aslam <asim@aslam.me>
2020-03-01 22:09:06 +00:00
Sumanth Chinthagunta d8377e09c9 feat(dockerfile): adding dumb-init to base image (#1278) 2020-02-29 21:55:15 +00:00
Vasiliy Tolstov 0754229878 broker/memory: add codec support (#1276)
allow easy testing of other services with memory broker
and also allows to more deeply simulate real brokers

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-02-29 23:00:29 +03:00
Vasiliy Tolstov 6b8930a960 add new helper method to logger (#1273)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-02-29 00:39:41 +00:00
Vasiliy Tolstov d0a978bd50 redesign logger (#1272)
* redesign logger

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-02-29 03:31:59 +03:00
ben-toogood afe6861e2f Update the k8s deployment to use metadata labels & custom source (#1271)
Run tests / Test repo (push) Waiting to run
2020-02-28 15:07:55 +00:00
ben-toogood 962567ef42 Implement config singleton (#1268)
* Implement config singleton

* Pass token in grpc request headers

* Refactor BearerScheme

* Fix typo
2020-02-28 12:58:27 +00:00
Asim Aslam e21ed3a183 gen account on base32 decode failure (#1269) 2020-02-27 16:11:05 +00:00
Vasiliy Tolstov 64a5ce9607 various fixes (#1267)
* logger: remove Panic log level

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* server/grpc: add missing Unlock in Subscribe error

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* server: minor code change

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* server/grpc: extend test suite with pub/sub testing

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* server/grpc: fix invalid check and allow subscriber error to be returned

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* server/grpc: add pubsub tests

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* client/grpc: check for nil req/rsp

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-02-26 18:34:40 +00:00
Asim Aslam d651b16acd generate pseudo accounts (#1264)
* generate pseudo accounts

* when you think you're being clever

* return garbage pseudo account when no token
2020-02-26 13:42:32 +00:00
Eric 1034837f69 Adjusting the BeforeStart () position (#1263)
Co-authored-by: Asim Aslam <asim@aslam.me>
2020-02-26 11:44:10 +03:00
Lars Lehtonen 80f2bfd5d0 config: remove unused sep variable (#1262) 2020-02-26 08:25:33 +00:00
Asim Aslam 6aaaf54275 add MICRO_AUTH_TOKEN, parse token in wrapper, preload config and othe… (#1261)
* add MICRO_AUTH_TOKEN, parse token in wrapper, preload config and other things

* fix wrapper panic
2020-02-25 22:15:44 +00:00
Di Wu 603d37b135 Set option and cli args to the service profile (#1259) 2020-02-25 16:42:42 +00:00
Eric 53c3bff819 add Panic & Panicf to logger (#1258)
* add Panic & Panicf to logger
2020-02-25 17:44:29 +03:00
ben-toogood dcf859098b Fix k8s commands for github (#1257) 2020-02-25 11:39:03 +00:00
Vasiliy Tolstov b4a743898e fix router panic (#1254)
Run tests / Test repo (push) Waiting to run
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-02-24 23:15:59 +00:00
ben-toogood f1e7ea3020 Handle non IsNotExist errors in config (#1251)
Co-authored-by: Asim Aslam <asim@aslam.me>
2020-02-24 18:07:11 +00:00
ben-toogood 5e8d5834eb Dynamic Runtime source for k8s with github packages (#1252)
* Dynamic Runtime source for k8s

* Still check for source

* Replace / with - for k8s service names

* Simplify sourceForName function
2020-02-24 17:47:47 +00:00
ben-toogood ffdf986aac Refactor auth: add token and store implementations (#1230)
* Refactor auth: add token and memory implementations

* Fix typo

* Remove memory auth (implemented already by the store implementation), revert default to noop

* Add grpc header

* Global Config

* config/global => util/config

* Rename package to remove confict

* Tweak

* Improve Error Handling
2020-02-24 15:07:27 +00:00
Jake Sanders 56f8115ea8 Rename PR job (#1250) 2020-02-24 14:16:51 +00:00
Vasiliy Tolstov 5b0175c2e5 allocations improvements and tunnel fixes (#1248)
* reduce allocations in tunnel code

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* another allocation fix

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* allocate maps with len if it known

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* allocate key for send once

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-02-24 14:15:20 +00:00
Jake Sanders 01d88601c0 Split PR and merge tests (#1249) 2020-02-24 14:11:17 +00:00
Lars Lehtonen d467236f8f broker/nats: remove unused setPublishOption() (#1234)
broker/nats: remove unused setSubscribeOption()
2020-02-24 13:49:27 +00:00
Vasiliy Tolstov 24d574ae71 server/grpc: add MaxConn option to limit max inflight requests (#1247)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-02-24 13:48:56 +00:00
Vasiliy Tolstov cf0b39eaac logger fixes (#1244)
* logger: fix race conditions

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* restore util/log for compatibility

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-02-24 13:07:40 +00:00
Vasiliy Tolstov 1f767ba18c update go modules (#1240)
Run tests / Test repo (push) Waiting to run
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-02-23 20:47:44 +00:00
Asim Aslam 915c424213 Add docker build (#1239) 2020-02-23 15:57:21 +00:00
Vasiliy Tolstov 117f56ebf7 prune util/log and user logger (#1237)
* prune util/log and user logger

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* plaintext logger

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* add newline

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-02-23 13:45:20 +00:00
Gao.QiLin ceed8942fc Update README.md change godoc => go.dev (#1236)
* Update README.md add go dev

* Update README.zh-cn.md add go dev
2020-02-22 08:56:42 +00:00
Vasiliy Tolstov d1e25e7ead add metadata set method (#1232)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-02-21 23:04:47 +03:00
Jake Sanders 7e24c0c1cf Also run tests on PR (#1233) 2020-02-21 17:57:07 +00:00
Jake Sanders ca251ba111 Switch from Travis CI to GitHub Actions (#1231)
* Create Github Action to run tests on push

* -v

* Update tests.yml

* TODO: Fix tests

* Fix colours

* Delete .travis.yml

* Update tests.yml

* builds -> build
2020-02-21 17:43:50 +00:00
Asim Aslam 116855572b Add log level helper funtions (#1229) 2020-02-21 08:43:23 +00:00
Asim Aslam ee977acfef strip SetGlobalLevel (#1228) 2020-02-21 08:28:21 +00:00
Sumanth Chinthagunta 3fa7c26946 logger with helper methods (#1216)
* support unix daemon socket

* refactor(logger): logger fields changed to map[string]interface{}

* improvement(logger): adding string to Level Parser

* improvement(logger): rename ParseLevel to GetLevel

* refactor(logger): adding basic logger

adding micro default logger, and refactor logger interface

* refactor(logger): moved basic logger to top level package

* refactor(logger): adding default logger
2020-02-21 07:57:59 +00:00
Lars Lehtonen 88457b812e tunnel: Prune Unused Functions (#1224)
* tunnel: remove unused link.setLoopback()

* tunnel: remove unused link.accept()

* tunnel: remove unused link.connect()
2020-02-20 17:05:49 +00:00
Asim Aslam 78df154a4d move log level setting to option (#1222) 2020-02-20 08:26:12 +00:00
Lars Lehtonen c7eed618c2 server/grpc: Prune Unused Code (#1220)
* server/grpc: remove unused grpcServer.newCodec()

* server/grpc: remove unused defaultRPCCodecs
2020-02-19 20:58:22 +00:00
ben-toogood 36bcd3bd82 Improve JWT Package Errors (#1206)
Co-authored-by: Asim Aslam <asim@aslam.me>
2020-02-19 09:51:43 +01:00
Asim Aslam f4118dc357 secure the grpc client (#1215)
* secure the grpc client

* make compile

* Add system cert pool

* Revert manually adding ca certs

* Tweak comment

Co-authored-by: ben-toogood <bentoogood@gmail.com>
2020-02-19 08:44:35 +00:00
Vasiliy Tolstov 58598d0fe0 fixes for safe conversation and avoid panics (#1213)
* fixes for safe convertation

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* fix client publish panic

If broker connect returns error we dont check it status and use
it later to publish message, mostly this is unexpected because
broker connection failed and we cant use it.
Also proposed solution have benefit - we flag connection status
only when we have succeseful broker connection

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* api/handler/broker: fix possible broker publish panic

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-02-18 23:05:38 +00:00
Vasiliy Tolstov 6248f05f74 add missing option to client.NewMessage (#1212)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-02-18 14:18:59 +03:00
ben-toogood aa9a0a8d23 Fix Micro Proxy nil Transport Bug (#1208) 2020-02-17 12:28:48 +03:00
ben-toogood 1e40c86dfe Ignore gRPC Proxy (#1205) 2020-02-17 08:14:45 +00:00
Asim Aslam 9696efde02 reorder auth interface (#1204) 2020-02-16 19:36:45 +00:00
Asim Aslam b3fc8be24e normalise proxy name (#1203) 2020-02-15 21:57:30 +00:00
Sumanth Chinthagunta fc5339a368 [W.I.P] refactor(logger): logger fields changed to map[string]interface{} (#1198)
* support unix daemon socket

* refactor(logger): logger fields changed to map[string]interface{}

* improvement(logger): adding string to Level Parser

* improvement(logger): rename ParseLevel to GetLevel
2020-02-15 18:19:28 +00:00
Asim Aslam 964b7dee3f add tls config to server (#1202)
* add tls config

* add TLSConfig to acme provider
2020-02-15 15:10:26 +00:00
Asim Aslam 158949d0d0 accept Listen option in grpc server (#1201) 2020-02-15 14:09:24 +00:00
Asim Aslam eed8a0bf50 delete proxy cached route before updating (#1200) 2020-02-15 12:05:22 +00:00
Asim Aslam c691d116ab when the stream errors cleanup the connection (#1199) 2020-02-15 11:35:08 +00:00
Eric cbe8b7dd09 Removed redundant spaces (#1196) 2020-02-14 10:32:02 +03:00
Asim Aslam 203486fd31 check for etcd watcher canceled value 2020-02-13 22:34:56 +00:00
Asim Aslam d9b3b17582 set dial timeout in stream 2020-02-13 18:51:32 +00:00
ben-toogood e080ecb43a Auth Improvements (#1195)
* Exclude Stats & Trace from Auth

* Update Excluded Endpoints Format

* Tweak Implementation
2020-02-13 14:07:14 +00:00
ben-toogood ea70711dd3 Exclude Stats & Trace from Auth (#1192) 2020-02-13 12:02:29 +00:00
Vasiliy Tolstov 6dc942bc19 client/grpc: fix panic on invalid message (#1191)
* client/grpc: fix panic on invalid message
* travis: disable lint and race for now

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-02-13 14:57:21 +03:00
Janos Dobronszki d76baf59de Trace type is now being recorded (#1188) 2020-02-12 10:57:17 +00:00
Vasiliy Tolstov 79ad1e6fe3 various fixes for broker and messaging in server (#1187)
* provide broker disconnect messages in server

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* broker/eats: another fix

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-02-11 18:41:23 +00:00
Vasiliy Tolstov 2764de9a1a broker/eats: broker disconnect fix (#1186)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-02-11 15:46:50 +00:00
Asim Aslam d1d6eada98 parse url encoded form in rpc handler (#1183)
* parse url encoded form in rpc handler

* Remove comment
2020-02-11 11:27:16 +00:00
ben-toogood 4a03183481 Return a 401 error on invalid auth tokens (#1184) 2020-02-11 11:22:22 +00:00
Asim Aslam 8ea84ac3eb Fix router panic for nil watcher 2020-02-10 15:38:41 +00:00
ben-toogood 4401c12e6c Auth Wrapper (#1174)
* Auth Wrapper

* Tweak cmd flag

* auth_excludes => auth_exclude

* Make Auth.Excludes variadic

* Use metadata.Get (passes through http and http2 it will go through various case formats)

* fix auth wrapper auth.Auth interface initialisation

Co-authored-by: Asim Aslam <asim@aslam.me>
2020-02-10 08:26:28 +00:00
Vasiliy Tolstov c706afcf04 logger helper to pass down it via context (#1180)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-02-09 21:26:46 +00:00
Lars Lehtonen ca1d0b94c3 config/cmd: remove 8 unused variables (#1175) 2020-02-08 11:19:10 +00:00
Vasiliy Tolstov 67acd9288b config/source/cli: fix tests (#1179)
* config/source/cli: fix tests
* skip mdns test in travis

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-02-08 02:45:32 +03:00
Vasiliy Tolstov 0bf6c9fc08 config/source/cli: fix default flag value loading (#1178)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-02-08 02:14:34 +03:00
Vasiliy Tolstov 99807a680c strip Micro-Topic header from incoming context in client.Call (#1177)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-02-07 22:09:52 +00:00
Vasiliy Tolstov f0f7f860d6 add some docs (#1176)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-02-07 21:48:24 +00:00
Asim Aslam ef537270ad Don't store traces for Debug endpoints 2020-02-07 20:58:03 +00:00
Asim Aslam c7f075d157 rename file 2020-02-07 14:00:27 +00:00
Asim Aslam 812ea78604 Fix runtime deadlock 2020-02-07 14:00:09 +00:00
Asim Aslam 0755084a59 fix deadlock 2020-02-07 13:55:55 +00:00
ben-toogood fe7f5a4134 Runtime Retries Limit (#1163)
* Implement Runtime Retries

* Remove Debug

* Action Feedback

* Refactor Retries

* Fix WithRetires Typo
2020-02-07 12:02:41 +00:00
ben-toogood 19c454ec4b Fix Local Runtime Default Command (#1173)
* Auth API Proto

* Fix local runtime bug

* Add Platform Proto

* Restructuring
2020-02-07 11:39:26 +00:00
Asim Aslam 0e9b4c26a4 import with braces 2020-02-06 21:39:08 +00:00
Asim Aslam d40b13a045 mux to mtx 2020-02-06 21:37:17 +00:00
Asim Aslam 4079b22c1e reorder logger methods 2020-02-06 21:36:33 +00:00
Shu xian fdfb2bc4c1 [WIP] logger first (#1161)
* logger first

* log->logger

* update comment

* add context in Options

* add Fields

* remove logfi

* add field encode

* add common Field Types

* update logger field
2020-02-06 21:35:46 +00:00
Asim Aslam dbeb7cfe9c remove errors import 2020-02-06 18:45:12 +00:00
Asim Aslam 512df2628f trim source url if its set to github.com/ 2020-02-06 18:34:16 +00:00
Janos Dobronszki 92571db693 Tracing: traces now correctly form a tree (#1170)
* First cut of trace

* Dial it back yo

* Defensive programming
2020-02-06 17:22:16 +00:00
ben-toogood 16552620e0 Runtime Custom Source (Part 2) (#1169) 2020-02-06 16:16:01 +00:00
Ben Toogood 5414195dc3 Add Args 2020-02-06 12:31:54 +00:00
Ben Toogood 0591760932 Arg => Args 2020-02-06 12:17:16 +00:00
Ben Toogood 48b9f3f5e9 Fix 2020-02-06 11:28:34 +00:00
Ben Toogood e46278a766 Test 2020-02-06 11:24:56 +00:00
Ben Toogood 2925b1615c Fix 2020-02-06 11:15:30 +00:00
Ben Toogood fc4191c647 Fix 2020-02-06 11:12:40 +00:00
Ben Toogood 111126c780 Debugging 2020-02-06 11:00:14 +00:00
Ben Toogood 54371bba6a Debugging 2020-02-06 10:55:41 +00:00
Ben Toogood c28737e88e Debugging 2020-02-06 10:54:11 +00:00
Ben Toogood c7d922fac2 Debugging 2020-02-06 10:49:01 +00:00
Ben Toogood f8e696bd30 Debugging 2020-02-06 10:44:12 +00:00
Ben Toogood 6aef28dad2 Runtime set service source 2020-02-06 10:33:23 +00:00
Vasiliy Tolstov 7105e4099c pass micro errors from grpc server to grpc client (#1167)
* pass micro errors from grpc server to grpc client

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* wrap micro errors.Error to grpc status

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-02-06 10:18:33 +00:00
Ben Toogood f0762bbb6b Improve Logging 2020-02-06 10:16:32 +00:00
Ben Toogood 243c6a4246 Debug 2020-02-06 10:08:56 +00:00
Ben Toogood 9983aea928 Tidying Up 2020-02-06 09:29:27 +00:00
Ben Toogood aa58a9749b Action Asim's Feedback 2020-02-06 09:17:10 +00:00
ben-toogood d8110b70a3 Runtime custom docker img (#1168)
* Add DeploymentOptions to K8s Client

* WithBaseImage for  Runtime

* Revert Change

* Fix sequencing
2020-02-06 08:52:25 +00:00
Vasiliy Tolstov a44dc90d45 fix ctx.Done issue #720 (#1166)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-02-05 21:13:14 +00:00
Shu xian 12181bd441 fix LevelInfo > LevelWarn (#1162) 2020-02-05 18:16:57 +00:00
Ben Toogood 8d44f7226f Merge branch 'master' of https://github.com/micro/go-micro 2020-02-05 13:59:51 +00:00
ben-toogood bf747a86f4 Runtime (#1160)
* Add String to Runtime interface

* Setup Dynamic Runtime Configuration
2020-02-05 13:59:35 +00:00
Lars Lehtonen 4333f00a43 runtime/kubernetes: remove unused constants (#1159) 2020-02-04 21:02:05 +00:00
Vasiliy Tolstov 7ab3a31ac4 update micro/cli, tidy mod (#1156)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-02-03 23:29:44 +00:00
Ben Toogood a1d5d6831f Add String to Runtime interface 2020-02-03 15:56:16 +00:00
ben-toogood 1b9cabd654 Update Micro Auth Protocol Buffer to use V2 (#1155) 2020-02-03 08:26:57 +00:00
ben-toogood d621548120 Auth (#1147)
Implement the Auth interface, with JWT and service implementations.

* Update Auth Interface

* Define Auth Service Implementation

* Support Service Auth

* Add Auth Service Proto

* Remove erronious files

* Implement Auth Service Package

* Update Auth Interface

* Update Auth Interface. Add Validate, remove Add/Remove roles

* Make Revoke interface more explicit

* Refactor serializing and deserializing service accounts

* Fix srv name & update interface to be more explicit

* Require jwt public key for auth

* Rename Variables (Resource.ID => Resource.Name & ServiceAccount => Account)

* Implement JWT Auth Package

* Remove parent, add ID

* Update auth imports to v2. Add String() to auth interface
2020-02-03 08:16:02 +00:00
tpam28 449bcb46fe New backoff (#1153)
* new backoff function

* use backoff from util/backoff

* remove reset atemts

* change comment

* fmt
2020-02-02 20:32:55 +00:00
Asim Aslam 079102ea59 Merge branch 'master' of ssh://github.com/micro/go-micro 2020-02-02 19:50:09 +00:00
Asim Aslam a9d371e727 fatal on command error 2020-02-02 19:49:59 +00:00
Asim Aslam 27efbc8779 Merge pull request #1150 from unistack-org/grpc_race
fix map race condition in grpc server
2020-02-01 00:10:46 +00:00
Vasiliy Tolstov efb59d9709 fix map race condition in grpc server
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-02-01 02:52:53 +03:00
Asim Aslam 003f00b483 Merge branch 'master' of ssh://github.com/micro/go-micro 2020-01-30 23:24:54 +00:00
Asim Aslam 0be22c98c6 add tracing 2020-01-30 23:24:46 +00:00
Asim Aslam bafedf1aad Merge pull request #1149 from alrs/remove-unused-kubernetes-variable
runtime/kubernetes: remove unused name variable
2020-01-30 17:30:43 +00:00
Lars Lehtonen 98d55545fd runtime/kubernetes: remove unused name variable 2020-01-30 09:25:50 -08:00
Asim Aslam 5f6271b044 Merge pull request #1148 from tpam28/master
fix test and description
2020-01-30 17:09:41 +00:00
Evgeniy 87753ad289 format results in TestBacloff 2020-01-30 20:08:03 +03:00
Evgeniy ffb9da0230 fix test and description 2020-01-30 19:43:03 +03:00
Asim Aslam 50ac642666 Merge pull request #1146 from tpam28/master
exponentialBackoff was changed from power function to exponential
2020-01-30 14:35:17 +00:00
Evgeniy f6fcfcb8fc exponentialBackoff was changed from power function to exponential function 2020-01-30 17:25:07 +03:00
Asim Aslam 21e0932339 Merge pull request #1144 from unistack-org/v2
fix import paths for v2 release
2020-01-30 11:46:29 +00:00
Vasiliy Tolstov f23638c036 fix import paths for v2 release
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-01-30 14:44:40 +03:00
Asim Aslam 2b1e0a6fd6 go mod tidy 2020-01-30 10:33:40 +00:00
Asim Aslam 0889b814bb Merge pull request #1143 from crufter/bump-dep
Bump dep to fix platform web using new debug.Stats proto fields
2020-01-30 10:31:12 +00:00
Janos Dobronszki a648c0d99c Bump dep to fix platform web using new debug.Stats proto fields 2020-01-30 10:27:21 +00:00
Asim Aslam a291af59c4 Merge pull request #1142 from micro/tracing
Fix null tracer bug
2020-01-30 07:55:58 +00:00
Ben Toogood d9f12731e1 Fix null tracer bug 2020-01-30 07:53:31 +00:00
Asim Aslam 4a838a8210 Merge branch 'master' of ssh://github.com/micro/go-micro 2020-01-29 23:14:16 +00:00
Asim Aslam 5969cc358e nats-e => eats 2020-01-29 23:14:05 +00:00
Asim Aslam 9f1a7e1139 Merge pull request #1127 from Allenxuxu/master
handle Loader.Load  return value error
2020-01-29 22:44:29 +00:00
Asim Aslam dc257f5066 update to fix tracer 2020-01-29 22:43:40 +00:00
Asim Aslam 49b86c56e3 go fmt 2020-01-29 22:40:43 +00:00
Asim Aslam 1be8258721 fix initialisation 2020-01-29 22:39:31 +00:00
Asim Aslam b2980aecb7 fix debug handler in proxy 2020-01-29 22:31:57 +00:00
Asim Aslam de3c3b27b2 Merge pull request #1140 from micro/tracing
Tracing by Ben Toogood
2020-01-29 22:28:49 +00:00
Micro a09eea8d4d Update the Debug Handler to use the servers tracer 2020-01-29 16:05:58 +00:00
Micro 62c067adcd Refactor debug/trace ready for Jaeger 2020-01-29 15:45:11 +00:00
Asim Aslam 59f6ca5564 Merge pull request #1139 from alrs/prune-unused-config-reader-func
config/reader/json: remove unused newValue()
2020-01-28 19:50:03 +00:00
Lars Lehtonen 895aa896bc config/reader/json: remove unused newValue() 2020-01-28 11:38:55 -08:00
Asim Aslam 74762edc42 Merge pull request #1138 from printfcoder/master
cockroach store supports URL connection string
2020-01-28 17:59:49 +00:00
shu xian 101017a29c cockroach supports URL connection string 2020-01-29 00:47:41 +08:00
Shu xian c725b4c797 Merge pull request #3 from micro/master
merge
2020-01-29 00:45:27 +08:00
Asim Aslam 1108cc5e91 Merge pull request #1136 from unistack-org/flags
update micro/cli to urfave/cli/v2 and fix go-micro
2020-01-26 19:12:06 +00:00
Asim Aslam 6a9f5fac61 fire send in a go routine to prevent blocking other requests 2020-01-25 23:16:00 +00:00
Vasiliy Tolstov e6a34bcbe7 update micro/cli to urfave/cli/v2 and fix go-micro
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-01-25 15:57:08 +03:00
Asim Aslam 1d00f2f771 add trace handler 2020-01-24 22:02:35 +00:00
Asim Aslam 4a6570a772 trace wrapper 2020-01-24 21:58:29 +00:00
Asim Aslam a997a86e49 add trace context 2020-01-24 21:44:48 +00:00
Asim Aslam 2d28ff72d7 add trace 2020-01-24 21:32:07 +00:00
Asim Aslam 2b1844971c go fmt 2020-01-24 21:31:57 +00:00
Asim Aslam 49cc022ca2 add trace to handler 2020-01-24 21:29:29 +00:00
Asim Aslam 8d2dc8a822 trace Read endpoint 2020-01-24 21:24:51 +00:00
Asim Aslam eeb6944ce5 Merge pull request #1133 from alrs/drop-unused-broker-code
broker: drop unused registryKey variable
2020-01-23 21:57:58 +00:00
Lars Lehtonen add78f2967 broker: drop unused registryKey variable 2020-01-23 12:51:57 -08:00
Shu xian bd6a5af2b5 Merge pull request #2 from micro/master
merge
2020-01-23 22:17:54 +08:00
Asim Aslam ae08e9c106 check if event is nil 2020-01-23 12:41:22 +00:00
Asim Aslam 77c2a021da Add event id to router events 2020-01-23 11:44:06 +00:00
Asim Aslam 1c19678d04 Update proto Service => Config 2020-01-23 11:37:54 +00:00
Asim Aslam 6d636b7ab3 whoa bad commit, bad asim 2020-01-22 17:07:56 +00:00
Asim Aslam 009c598049 Change version to latest 2020-01-22 17:03:38 +00:00
Asim Aslam 5cceb00df2 Merge pull request #1131 from micro/router-refactor
refactor and cleanup some router code
2020-01-22 16:54:20 +00:00
Asim Aslam 3e24276eb1 fix break 2020-01-22 16:44:34 +00:00
Asim Aslam 29c1076950 refactor and cleanup some router code 2020-01-22 16:33:31 +00:00
Asim Aslam 8dbacb34f8 Merge pull request #1118 from printfcoder/master
add mucp for config/source
2020-01-21 22:35:35 +00:00
Asim Aslam 8b306780ee Merge pull request #1130 from micro/net-noloop
avoid connecting to self
2020-01-21 15:05:33 +00:00
Asim Aslam 9f7d374691 avoid connecting to self 2020-01-21 12:36:05 +00:00
Asim Aslam a18e53f028 Merge branch 'master' of ssh://github.com/micro/go-micro 2020-01-20 21:31:16 +00:00
Asim Aslam 2208839027 Merge pull request #1129 from alrs/remove-unused-server-var
server: remove unused invalidRequest
2020-01-20 18:24:42 +00:00
Lars Lehtonen 7a17a221ff server: remove unused invalidRequest 2020-01-20 10:09:27 -08:00
Shu xian 8e1ff80b9e Merge pull request #1 from micro/master
merge
2020-01-20 20:08:21 +08:00
shu xian 94bb0f4c08 watch supports path 2020-01-20 18:31:18 +08:00
Allenxuxu dbe209ebe4 Merge branch 'master' of https://github.com/micro/go-micro 2020-01-20 08:37:34 +08:00
Asim Aslam fa0d884cfe fix bad import 2020-01-19 23:31:09 +00:00
Asim Aslam ed2bd68d28 fix break in router service 2020-01-19 23:22:41 +00:00
Asim Aslam 97928e88f8 stop watcher 2020-01-19 23:15:57 +00:00
Asim Aslam 04cf86070c close stream 2020-01-19 22:55:57 +00:00
Asim Aslam 9df19e826e cancel stream 2020-01-19 22:53:56 +00:00
Asim Aslam 3f3c1919f4 strip certain plugins 2020-01-19 17:56:59 +00:00
Asim Aslam d918694346 reorganise runtime 2020-01-19 17:47:27 +00:00
Asim Aslam 54fb61bba4 Move proto to service/ 2020-01-19 17:31:24 +00:00
Asim Aslam fac75866d9 Move pool to util 2020-01-19 17:30:49 +00:00
Asim Aslam a47ff65529 remove mock client 2020-01-19 17:24:22 +00:00
Asim Aslam 093bcedfe7 remove http broker 2020-01-19 17:21:55 +00:00
Asim Aslam 7b6d560bec Update README.md 2020-01-19 13:55:23 +00:00
Asim Aslam 43aa4e23bd update readme 2020-01-19 13:51:31 +00:00
Asim Aslam bdd9ec560b strip sub comments 2020-01-19 13:47:14 +00:00
Asim Aslam 0c03bf064b only connect broker if there are subscribers 2020-01-19 13:45:28 +00:00
Asim Aslam 9a8c1b7ab8 update broker 2020-01-19 13:35:23 +00:00
Asim Aslam e1ca40c1fc go fmt 2020-01-19 13:32:30 +00:00
Asim Aslam e75b99f89c go fmt 2020-01-19 13:32:24 +00:00
Allenxuxu ee7304a795 NewConfig return value error 2020-01-19 16:42:05 +08:00
Allenxuxu a82fd19209 handle Loader.Load return value error 2020-01-19 16:31:02 +08:00
Asim Aslam 1983d607f3 set nats-e 2020-01-19 01:47:30 +00:00
Asim Aslam 10093a0ea2 set to nats-e 2020-01-19 01:29:00 +00:00
Asim Aslam fc08a9146c Add broker comments on server subscribe 2020-01-19 01:16:36 +00:00
Asim Aslam cafd280718 Default to grpc in registry service for now 2020-01-19 01:13:14 +00:00
Asim Aslam 11b104677a Shift embedded nats to the default 2020-01-19 00:55:01 +00:00
Asim Aslam 105596a0e5 use mucp server 2020-01-18 20:48:08 +00:00
Asim Aslam 0a37767127 Fix service registration with registry service 2020-01-18 19:53:51 +00:00
Asim Aslam 31e195bac7 strip image pull policy always 2020-01-18 18:37:38 +00:00
Asim Aslam bdf1d20f4e extract an ip that can be advertised in embedded nats 2020-01-18 15:39:26 +00:00
shu xian 8d6f82707a update to standard name convention 2020-01-18 23:16:23 +08:00
Asim Aslam 058fd8adbf trace 1 2020-01-18 10:20:46 +00:00
Asim Aslam 13d1d2fa08 hard stop if graceful stop fails after 1 second 2020-01-18 10:18:23 +00:00
Asim Aslam e666d0b807 add missing commit 2020-01-18 02:28:44 +00:00
Asim Aslam 39d7938405 Extract k8s run error 2020-01-18 02:13:24 +00:00
Asim Aslam 65df711b01 move nats local logic 2020-01-18 01:29:53 +00:00
Asim Aslam fd6eb23307 do not wait to stop 2020-01-18 00:58:27 +00:00
Asim Aslam fb3927fb8c Merge pull request #1126 from milosgajdos83/metric-update
Update route metric when receiving Sync routes
2020-01-17 18:29:55 +00:00
Milos Gajdos 891af703be Update route metric when receiving Sync routes 2020-01-17 18:24:36 +00:00
Asim Aslam 474472eedd Merge pull request #1124 from milosgajdos83/flush-advert-query
Use the same logic for advertising routes in Router and Network
2020-01-17 16:49:11 +00:00
Milos Gajdos 23d65145e6 Use the same logic for advertising routes in Router and Network
router.Query() allows to query the routes with given router.Strategy.
It uses the same logic as was implemented in flushRoutes but the code
was never updated. This way we are consistent across both router and
network packages.
2020-01-17 16:25:18 +00:00
shu xian 9ea4919b9b rename mucp source directory to service 2020-01-17 23:53:33 +08:00
Asim Aslam f78e30770e Merge pull request #1123 from milosgajdos83/sync-metric
Update route metric before sending the Sync message
2020-01-17 15:44:49 +00:00
Milos Gajdos bf9f319cdf Update route metric before sending the Sync message 2020-01-17 15:38:28 +00:00
shu xian ad28b72dd3 rename mucpSource to service 2020-01-17 23:27:41 +08:00
Asim Aslam 8425ae77f8 Merge pull request #1122 from micro/blocking
don't block forever
2020-01-17 15:24:03 +00:00
Asim Aslam d7b9b2713b don't block forever 2020-01-17 15:23:10 +00:00
Asim Aslam be788415ad minor runtime fixes 2020-01-17 14:14:47 +00:00
shu xian a03791c581 set DefaultClient 2020-01-17 21:32:00 +08:00
Asim Aslam ee922a3da6 Merge pull request #1121 from milosgajdos83/no-routes-found
Continue processing Sync if no routes were returned from router Query
2020-01-17 13:05:47 +00:00
Milos Gajdos 624f1c1980 Continue processing Sync if no routes were returned from router Query 2020-01-17 12:58:13 +00:00
Milos Gajdos 607a226e34 Updated debug logs to make them less verbose 2020-01-17 12:14:56 +00:00
Asim Aslam bac1bbfd97 Merge pull request #1120 from milosgajdos83/remove-solicit
Remove Solicitation from the network
2020-01-16 20:02:05 +00:00
Milos Gajdos 7f9b3b5556 Remove Solicitation from the network
Instead, when a new peer is discovered it is sent a sync message i.e. we
do the full sync when discovering peers
2020-01-16 19:43:10 +00:00
Asim Aslam ba12513199 Merge pull request #1119 from milosgajdos83/sync-best-routes-only
Send only best routes via Sync. Only apply best routes.
2020-01-16 18:17:26 +00:00
Milos Gajdos 8fcfbc0d20 Strip unnecessary continue statement 2020-01-16 17:33:53 +00:00
Milos Gajdos 472186c1be Code consistency. Small bug fix. 2020-01-16 17:04:04 +00:00
Milos Gajdos 60c05bd899 Find the best routes in the routes we would advertise based on Strategy 2020-01-16 16:53:39 +00:00
Milos Gajdos 793e6013e5 Advertise routes with configured strategy. Simplify Sync apply logic 2020-01-16 16:42:23 +00:00
shu xian 071ab7aede add mucp for config/source 2020-01-17 00:10:15 +08:00
Milos Gajdos eda8b00f84 Send only best routes via Sync. Only apply best routes. 2020-01-16 16:08:49 +00:00
Asim Aslam eac2ab3c28 Merge pull request #1117 from micro/scheduler
Switch notifier to scheduler
2020-01-16 13:41:13 +00:00
Asim Aslam 76fba34c2f Merge pull request #1116 from milosgajdos83/query-strategy
QueryStrategy to allow querying routes based on Advertising Strategy
2020-01-16 13:39:39 +00:00
Asim Aslam 491a42d352 Switch notifier to scheduler 2020-01-16 13:34:04 +00:00
Milos Gajdos 5e85194a13 QueryStrategy to allow querying routes based on Advertising Strategy 2020-01-16 12:48:36 +00:00
Asim Aslam 689ae7cfc7 Storing tunnel.Session rather than transport.Client 2020-01-16 00:28:58 +00:00
Asim Aslam 19dbd77402 fix net masking in listed routes 2020-01-16 00:12:38 +00:00
Asim Aslam b194b3adc9 Merge pull request #1115 from micro/net-mask
mask the route before sending
2020-01-15 23:13:53 +00:00
Asim Aslam 33a9b3bc17 mask the route before sending 2020-01-15 23:06:58 +00:00
Asim Aslam 6562154573 Fix the next panic 2020-01-15 21:38:37 +00:00
Asim Aslam b32ebddf85 update nlopes/slack dep 2020-01-15 21:22:07 +00:00
Asim Aslam b3e3dac975 Merge branch 'master' of ssh://github.com/micro/go-micro 2020-01-15 21:02:58 +00:00
Asim Aslam f20e4daa60 fix rand panic 2020-01-15 21:02:53 +00:00
Asim Aslam f67d87e99d Merge pull request #1114 from milosgajdos83/network-backward-compatibility
Fixed bug:m network.proto backwards compatibility unmarshal
2020-01-15 19:57:57 +00:00
Milos Gajdos 36928b716c Fixed bug:m network.proto backwards compatibility unmarshal 2020-01-15 19:45:43 +00:00
Asim Aslam 7c7b0ced5f Merge pull request #1104 from milosgajdos83/network-hackery
[WIP] Network hackery
2020-01-14 20:28:32 +00:00
Milos Gajdos c67ef7e017 Bug fix: skip sending sync message if the peer is not in our graph 2020-01-14 19:37:50 +00:00
Milos Gajdos dcd925f1e5 Code cleanup; Indentation. 2020-01-14 18:48:42 +00:00
Milos Gajdos 0ea56a5ffe Fixed tests 2020-01-14 18:22:58 +00:00
Milos Gajdos 821fda41ae Added Status method to network.Node fixed random segfaults. 2020-01-14 18:12:36 +00:00
Asim Aslam 1d311ab457 Embedded NATS Broker (#1110)
* if the address is produced by a default route don't hash it

* embedded nats

* fix url parsing

* don't override help

* add ready flag
2020-01-14 13:23:16 +00:00
Asim Aslam b699d969e4 if the address is produced by a default route don't hash it (#1108) 2020-01-14 11:20:13 +00:00
Milos Gajdos 994d371ff1 Removed redundant comments. Add proper PruneStalePeers test. 2020-01-14 10:49:34 +00:00
Milos Gajdos a91dad04ee Increment node error count and prune when Max limit is hit 2020-01-13 22:22:12 +00:00
Milos Gajdos b4261e8cf9 Updated log and comments 2020-01-13 20:14:30 +00:00
Milos Gajdos efcac3d009 Define tunnel errors 2020-01-13 20:14:30 +00:00
Milos Gajdos 770c7686ba Fix nasty bug when graph action may not have been executed in some
branches
2020-01-13 20:14:30 +00:00
Milos Gajdos 11904e1137 Regular sync with network every 5 minutes. Apply routes before peering. 2020-01-13 20:14:29 +00:00
Milos Gajdos 1e009e52dd Avoid having the same log statements in initNodes and resolveNodes 2020-01-13 20:14:29 +00:00
Milos Gajdos bf42c028fb Added sync message. Refactored connect flow. Adverts are gossipped.
This commit adds a Sync message which is sent as a reply to Connect
message. This should in theory speed up convergence of a (re)connecting
node.

We respond to Sync message by sending a peer message back to the peer
origin of the Sync message. We consequently update our routing table and
peer graph with the data sent in via Sync message.

We now gossip advertse to up to 3 randomly selected peers instead of
sending a multicast message to the network.

Equally, Solicitation i.e. full table adverts are gossipped to a
randomly selected peer. If that fails we send a multicast message to the
network.
2020-01-13 20:14:29 +00:00
Milos Gajdos 0a4bd02503 Add RefreshSync method for Sync bookkeeping 2020-01-13 20:14:29 +00:00
Milos Gajdos 63edfaa852 Added Sync message
Sync message will be sent between peers when a new node connects/joins
the network
2020-01-13 20:14:29 +00:00
Milos Gajdos 802cc8239a Send solicit message properly. Updated comments. 2020-01-13 20:14:29 +00:00
Matthew Costa 75b1a62af3 Replace service prefix with FQDN style prefix (#1107)
* Replace service prefix with FQDN style prefix

According to the k8s documentation, the label and annotation prefixes should be in the format of a FQDN, with dot separated labels of no more than 63 characters. The current label and annotation paramteres are rejected by the k8s api, most likely because they have two forward slashes in them.

* Use go.micro as service and annotation prefix
2020-01-12 14:37:12 +00:00
Maarten Bezemer 50b20413d3 RPC stream client/server mutex fix (#884)
* Unlock RPC client while actually receiving a message

As receiving a message might block for a long time, unblocking the client allows to let it send messages in the meanwhile without using 'tricks'

* Unlock RPC server while actually receiving a message

As receiving a message might block for a long time, unblocking the client allows to let it send messages in the meanwhile without using 'tricks'

* Protect Close() against race conditions

* Concurrency and Sequence tests
2020-01-12 09:13:14 +00:00
Shu xian fa5b3ee9d9 config/reader.Values add Set for specific path merge (#1099)
* add Set for specific path merge

* add Set

* add Del
2020-01-11 20:50:09 +00:00
Asim Aslam f50a50eeb3 go fmt 2020-01-10 21:54:36 +00:00
Asim Aslam e1e6199743 normalise runtime service status 2020-01-10 21:54:28 +00:00
Asim Aslam 61dd2b8489 Merge branch 'master' of ssh://github.com/micro/go-micro 2020-01-10 19:13:59 +00:00
Asim Aslam 6ca298c61d set default store, fix store options bug, add String method 2020-01-10 19:13:55 +00:00
Vasiliy Tolstov f4fb923fb2 pass additional context for broker subscribe (#1105)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-01-10 15:04:15 +00:00
shikbupt 32a2005f6d add option for web service signal handler (#1091) 2020-01-10 14:25:28 +00:00
Asim Aslam 37d1139a57 ensure we close the grpc stream (#1098)
* ensure we close the grpc stream

* use g.Close

* use closed bool flag for checking connection close
2020-01-09 17:00:14 +00:00
Asim Aslam a90a74c9e2 Change the store interface to remove variadic args (#1095) 2020-01-08 22:23:14 +00:00
Milos Gajdos 78aed5beed Fixed tunnel race conditions. (#1094) 2020-01-08 14:48:38 +00:00
Milos Gajdos 59fccb82ec Updated comments. Tiny cleanup changes. (#1093) 2020-01-08 13:18:11 +00:00
Asim Aslam 048065fe96 support ability to set store, address and namespace via flags and env vars (#1092) 2020-01-08 12:11:31 +00:00
Asim Aslam 0b8ff3a8bb fix grpc json streaming by setting content sub type (#1089) 2020-01-07 18:37:34 +00:00
Asim Aslam 1892bd05a5 only add api endpoint metadata if it exists (#1087) 2020-01-06 22:22:36 +00:00
Asim Aslam be6e8a7c78 add store to defaults (#1086) 2020-01-06 17:44:32 +00:00
Asim Aslam df9055f69c continue to process messages even after the connection is closed 2020-01-03 20:43:53 +00:00
Asim Aslam 649dd235c3 Merge branch 'master' of ssh://github.com/micro/go-micro 2020-01-03 19:46:24 +00:00
Asim Aslam 1af82df8b1 Check link is grpc 2020-01-03 19:46:14 +00:00
Eagle Wu 7098e59b5c remove ignore error in method publish (#1075) 2020-01-03 17:24:19 +00:00
Shu xian 31362bc331 prevent resource leak (#1080) 2020-01-03 13:31:47 +00:00
Asim Aslam 4e2339749c Merge branch 'master' of ssh://github.com/micro/go-micro 2020-01-02 21:19:50 +00:00
Asim Aslam 9cecf2e097 make grpc proxy streaming work 2020-01-02 21:11:25 +00:00
Lars Lehtonen fe9c68238f runtime/kubernetes: remove unused name variable (#1078) 2020-01-02 20:42:46 +00:00
Asim Aslam 225b17559b fix log streaming 2020-01-02 18:23:43 +00:00
Asim Aslam e697912ee5 don't panic on nil 2020-01-01 21:56:29 +00:00
Asim Aslam 6358b9277d don't write anything if theres no data 2019-12-31 22:58:14 +00:00
Asim Aslam 45c986c5f1 don't marshal frame values 2019-12-31 21:36:22 +00:00
Asim Aslam fa01ff6604 update ctx test 2019-12-31 13:53:48 +00:00
Asim Aslam fe1e018e8e update wrapper test 2019-12-31 13:45:49 +00:00
Asim Aslam 60ea537bbc upper case the metadata 2019-12-31 13:37:29 +00:00
Asim Aslam 488dc31743 log when starting the service 2019-12-31 12:07:52 +00:00
Asim Aslam b6915f0898 set grpc by default (#1070) 2019-12-30 18:33:21 +00:00
Asim Aslam 04dfe4e867 fix breaking test 2019-12-30 17:39:02 +00:00
Asim Aslam d8fe030a4b go fmt 2019-12-30 17:29:57 +00:00
Asim Aslam f40d4578d5 go fmt 2019-12-30 17:29:45 +00:00
Asim Aslam e0078bbcd5 Remove use of config/cmd in api 2019-12-30 17:29:20 +00:00
Asim Aslam c145f355dd Moving to gRPC by default (#1069)
* Step 1

* Fix the test panics
2019-12-29 21:07:55 +00:00
Vasiliy Tolstov 943445270f fix registry check issue (#1067)
fix #1066

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2019-12-28 11:11:46 +00:00
Asim Aslam 61cde4a9f4 Kubernetes Registry (#1064)
* add teh k8s registry

* add k8s reg config/cmd

* go mod update
2019-12-27 20:08:46 +00:00
jamsonzan 22aa7d14b3 support streams pool for grpc (#1062)
* Update grpc_pool.go

* Update options.go

* Update grpc.go

* Update grpc_pool_test.go

* streams pool for grpc

* use busy list to speed up allocate while pool is very busy

* fix idle bug
2019-12-27 12:25:58 +00:00
Eagle Wu a09b6729cc Fix missing recover while occur panic in handler (#1063) 2019-12-27 10:53:11 +00:00
Asim Aslam 2fe64001c0 Start runtime services inline 2019-12-24 17:51:30 +00:00
Asim Aslam 14c9c412cd Move and rename 2019-12-24 17:45:17 +00:00
Asim Aslam 361fdfba04 move around k8s api 2019-12-24 17:42:22 +00:00
Asim Aslam 5c8d1ae2b9 Update k8s log options 2019-12-24 17:33:05 +00:00
Asim Aslam 81e20160f5 reorder 2019-12-23 08:49:53 +00:00
Asim Aslam ef95b28e3d add Write method to config source 2019-12-23 08:42:57 +00:00
shikbupt 1781542964 fix etcd LogConfig bug (#1056) 2019-12-23 07:29:13 +00:00
Asim Aslam 45208992b5 NewLog 2019-12-20 23:36:16 +00:00
Asim Aslam 847a01df82 Cleanup k8s logs 2019-12-20 23:34:08 +00:00
Jake Sanders ce33e3b072 Kubernetes logging (#1054)
* wip

* Implementation of Kubernetes Logger

* Missing file

* Skip test in Travis
2019-12-20 23:16:05 +00:00
Asim Aslam ae12fd1021 update crap logging 2019-12-19 18:25:22 +00:00
Asim Aslam 95ae2688a2 add formatters 2019-12-19 12:29:03 +00:00
Asim Aslam 2bcfb85613 Add log Format option 2019-12-19 12:20:33 +00:00
Asim Aslam d52a111735 add requests/errors to stats 2019-12-18 18:36:42 +00:00
Asim Aslam d4bec24eb7 Add os log buffer 2019-12-18 17:06:29 +00:00
Asim Aslam 2338e7c9d2 Cleanup go mod 2019-12-18 16:12:25 +00:00
Asim Aslam f0e841595c move to structured logging 2019-12-18 16:02:11 +00:00
Asim Aslam a82af19d43 strip newline 2019-12-18 15:19:20 +00:00
Asim Aslam 5d7254e79a fix the os logger 2019-12-18 15:06:25 +00:00
Asim Aslam 7c21a1b92a go fmt 2019-12-18 15:06:02 +00:00
Asim Aslam 587f64a87a Merge pull request #1051 from micro/event
publisher => event
2019-12-18 15:04:38 +00:00
Asim Aslam cb9c4c3aef publisher => event 2019-12-17 23:05:46 +00:00
Asim Aslam dda96cb87e Merge pull request #976 from micro/auth
First interface for auth
2019-12-17 21:38:11 +00:00
Asim Aslam ebae497a72 use service rather than resource 2019-12-17 21:37:20 +00:00
Asim Aslam 515014fbeb update with resource 2019-12-17 21:27:05 +00:00
Asim Aslam e9efcbe8dc strip logger 2019-12-17 18:34:21 +00:00
Asim Aslam 5a52593e66 go fmt 2019-12-17 18:24:00 +00:00
Asim Aslam c61e12d5ee add event proto for runtiem 2019-12-17 18:17:32 +00:00
Asim Aslam c2d59c1f4d Move logger 2019-12-17 18:16:45 +00:00
Jake Sanders 812fe9e640 Merge pull request #1049 from micro/kubernetes-logging
Kubernetes logging
2019-12-17 17:44:24 +00:00
Jake Sanders f95bccce84 Use UTC in tests 2019-12-17 17:36:01 +00:00
Jake Sanders 81e7edd666 Adhere to new interfaces 2019-12-17 17:24:01 +00:00
Asim Aslam 46fd205eda rename files 2019-12-17 17:08:38 +00:00
Jake Sanders c2b307e5bb Merge branch master of https://github.com/micro/go-micro into kubernetes-logging 2019-12-17 17:08:31 +00:00
Jake Sanders b7ac62f7d2 Merge branch 'master' of https://github.com/micro/go-micro into kubernetes-logging 2019-12-17 17:06:07 +00:00
Asim Aslam 50d5c6402b Merge pull request #1048 from micro/logging
Move stream to interface
2019-12-17 17:05:13 +00:00
Asim Aslam d2a3fd0b04 Move stream to interface 2019-12-17 16:56:55 +00:00
Jake Sanders 51f4bc6d56 Add logs to Interface 2019-12-17 16:30:09 +00:00
Jake Sanders c3607c23e7 Fix after merge 2019-12-17 16:27:17 +00:00
Jake Sanders 34b1c403bb Merge branch 'master' of https://github.com/micro/go-micro into kubernetes-logging 2019-12-17 16:13:36 +00:00
Asim Aslam 91e057440d Merge pull request #1047 from micro/decruft-logger
Decruft logger
2019-12-17 16:13:20 +00:00
Jake Sanders 53ca742c66 Update the util/kubernetes client to retrieve logs 2019-12-17 16:09:51 +00:00
Asim Aslam b35dfb1086 fix further breaks 2019-12-17 15:56:49 +00:00
Asim Aslam d502e2f58a fix breaks 2019-12-17 15:46:09 +00:00
Asim Aslam bc30efcf70 Decruft the debug logger interface 2019-12-17 15:38:03 +00:00
Jake Sanders 0415ead504 First commit for Kubernetes logger 2019-12-17 12:11:26 +00:00
Jake Sanders e95f44d3f8 Move runtime/kubernetes/client to util/kubernetes/client 2019-12-17 11:32:38 +00:00
Asim Aslam 0489ae91e9 Merge pull request #1021 from unistack-org/registry_check
add RegisterCheck web server option for internal health checks
2019-12-17 08:49:00 +00:00
Asim Aslam 4e02f444fd Merge pull request #1024 from unistack-org/server
add server Context option to pass own context
2019-12-17 08:48:39 +00:00
Asim Aslam 6027a81f06 Update router comments 2019-12-17 08:28:45 +00:00
Asim Aslam 01f0e70213 add some commented out stuff 2019-12-16 17:37:11 +00:00
Asim Aslam cb15fadcee go fmt 2019-12-16 17:36:47 +00:00
Asim Aslam 1c8d15fe4b Merge pull request #1046 from micro/storefix
Fix cockroachdb store implementation
2019-12-16 17:24:53 +00:00
Jake Sanders 55f5937c8b Remove debug 2019-12-16 17:16:10 +00:00
Jake Sanders 56619f2745 Fix cockroachdb store implemetation 2019-12-16 17:11:13 +00:00
Asim Aslam 0b59e2ce3d Merge pull request #1028 from Astone-Chou/fix
named return value for error defer modify.
2019-12-16 15:39:58 +00:00
Asim Aslam 1ea6390eae Add proxy string method 2019-12-16 15:18:20 +00:00
Asim Aslam 303adca500 rename postgres to cockroach 2019-12-16 15:09:59 +00:00
Asim Aslam 03700ae6c0 Replace proxy options 2019-12-16 14:55:47 +00:00
Asim Aslam a1ddfa827e Merge pull request #1045 from micro/store-options
change store options
2019-12-16 14:46:15 +00:00
Asim Aslam 59751c02e6 change store options 2019-12-16 14:38:51 +00:00
Jake Sanders e8e112144f Create database should take the name of the database 2019-12-16 14:15:30 +00:00
Asim Aslam 59246e0412 Merge pull request #1044 from micro/store-namespace
change use of store namespace/prefix in sql store
2019-12-16 12:20:57 +00:00
Asim Aslam 0131e9468f change use of store namespace/prefix in sql store 2019-12-16 12:13:18 +00:00
Asim Aslam d5951f1d7c Merge pull request #1042 from ZGeomantic/feat-client-mock
support ctx as input params, error as output for MockClient.Call
2019-12-15 15:12:17 +00:00
Asim Aslam f33b562c16 Merge pull request #1043 from jamsonzan/branch0
comment
2019-12-15 10:50:52 +00:00
jamsonzan 572fe58314 comment 2019-12-15 15:05:19 +08:00
gemantic 5602b93d7a support ctx as input params, error as output for MockClient.Call 2019-12-14 10:36:12 +08:00
Asim Aslam 64e438a8d4 Merge pull request #1038 from micro/tun
Next level tunnel optimisation
2019-12-13 15:34:03 +00:00
Asim Aslam b0b6b8fce2 final updates 2019-12-13 15:27:47 +00:00
Asim Aslam 417a05db60 Merge pull request #1039 from xpunch/etcdLogConfig
Etcd log config
2019-12-13 09:23:54 +00:00
johnson 11e42aac69 etcd can set log config
default log level is info, which will log o log of unused logs
2019-12-13 11:22:05 +08:00
potato 885ba8f905 Merge pull request #6 from micro/master
Pull latest go-micro
2019-12-13 11:10:29 +08:00
Asim Aslam caa74d1b5f fix build 2019-12-12 23:29:44 +00:00
Asim Aslam f6b4a9da1c strip some code 2019-12-12 23:20:31 +00:00
Asim Aslam 74c5102e41 strip a couple things 2019-12-12 21:49:39 +00:00
Asim Aslam 7bd50cd251 fix more broken cruft 2019-12-12 17:10:32 +00:00
Asim Aslam df728aaddd remove go routines from tunnel, fire network messages in go routines 2019-12-12 13:34:08 +00:00
Asim Aslam ae934c19f1 fix tunnel test 2019-12-12 13:04:34 +00:00
Asim Aslam e260cc4a24 save cruft 2019-12-12 12:27:46 +00:00
Asim Aslam 631faff7b8 Merge pull request #1035 from alrs/fix-grpc-test-goroutines
Fix service/grpc Test Goroutines
2019-12-11 16:39:22 +00:00
Lars Lehtonen fd531349d7 service/grpc: t.Fatal out of TestGRPCTLSService() goroutine 2019-12-11 08:29:23 -08:00
Lars Lehtonen 27bab29e3c service/grpc: t.Fatal out of TestGRPCService() goroutine 2019-12-11 08:29:14 -08:00
Asim Aslam 27af221fd2 batch metric updates 2019-12-11 15:23:08 +00:00
Asim Aslam 6e28e7a86f Save current state of the world 2019-12-11 14:37:03 +00:00
Asim Aslam ff69d46c98 strip some cruft from config/cmd 2019-12-10 18:12:29 +00:00
Asim Aslam e966944ae5 sort resolved node list in network by lowest priority 2019-12-10 17:57:04 +00:00
Asim Aslam 8da77a3ddc use fixed port names for runtime k8s 2019-12-10 14:05:05 +00:00
Asim Aslam 8289dbabc4 Merge pull request #1034 from micro/strip-handlers
Strip handlers
2019-12-10 11:54:06 +00:00
Asim Aslam d50f30d743 strip handlers 2019-12-10 11:46:13 +00:00
Asim Aslam f8533551a4 move debug to trace for network peer refresh 2019-12-10 09:09:24 +00:00
Asim Aslam 7e46ff5d92 strip some more logging down 2019-12-10 09:08:03 +00:00
Asim Aslam 6b1eef5354 Merge branch 'master' of ssh://github.com/micro/go-micro 2019-12-09 22:56:33 +00:00
Asim Aslam b29da80539 Move a few things around 2019-12-09 22:56:26 +00:00
Asim Aslam a725ab2c94 Merge pull request #1032 from jankremlacek/patch-1
nlopes/slack dep update to fix broken unmarshal
2019-12-09 21:17:34 +00:00
Jan Kremlacek 1582aa1572 proper go.mod, go.sum 2019-12-09 22:08:57 +01:00
Jan Kremlacek 5352d53346 nlopes/slack dep update to fix broken unmarshal
About a month ago Slack introduced the updated structure of RTM messages which resulted in an inability to unmarshal received msg (original issue: https://github.com/nlopes/slack/issues/630). It's not an issue of micro itself, but of the github.com/nlopes/slack lib. The fix was already merged into master (https://github.com/nlopes/slack/pull/618), but the lib has not been released in any new version.

Thus so I propose to update directly to the commit:

go get github.com/nlopes/slack@d06c2a2b3249b44a9c5dee8485f5a87497beb9ea

The MicroBot does now work now with any Slack client newer than around a month old.
2019-12-09 21:52:28 +01:00
Asim Aslam 7d884eff9d Merge pull request #1031 from alrs/fix-web-test-goroutines
web: fix test goroutines
2019-12-09 18:03:07 +00:00
Lars Lehtonen c9af88184b web: fix test goroutine in TestService() 2019-12-09 09:44:14 -08:00
Lars Lehtonen f25ad35f0a web: fix test goroutine in TestTLS() 2019-12-09 09:28:42 -08:00
Asim Aslam 55ab44c8be Merge branch 'master' of ssh://github.com/micro/go-micro 2019-12-09 09:32:33 +00:00
Asim Aslam 59c1680594 Move Debug to Trace in router 2019-12-09 09:32:17 +00:00
Asim Aslam b804303aa0 Merge pull request #1029 from Astone-Chou/lint_fix_fix
fix tiny error in linting fixes
2019-12-09 07:47:46 +00:00
Astone 55a15ecf12 fix tiny error in linting fixes 2019-12-09 11:18:45 +08:00
Astone caa1bcf9fe named return value for error defer modify. 2019-12-09 11:08:21 +08:00
Asim Aslam e2b2a30668 add net/http/pprof profiler 2019-12-08 20:31:16 +00:00
Asim Aslam a9be1288d2 Merge pull request #1026 from micro/tun
Network & Tunnel refactor
2019-12-08 16:01:46 +00:00
Asim Aslam 679214e598 just return filtered routes 2019-12-08 15:39:45 +00:00
Asim Aslam 6064e1426c fix some potential go routine leaks 2019-12-08 15:02:54 +00:00
Asim Aslam d28a868e46 Fix network startup connect 2019-12-08 14:37:17 +00:00
Asim Aslam 398acc67ca fix broken test 2019-12-08 13:45:24 +00:00
Asim Aslam ce578800d0 n.initNodes 2019-12-08 12:17:31 +00:00
Asim Aslam 6307d6ba51 further cleanup of tunnel/network 2019-12-08 12:12:20 +00:00
Asim Aslam 283c85d256 done 2019-12-08 00:53:55 +00:00
Asim Aslam 9bd0fb9125 save changes 2019-12-07 23:28:39 +00:00
Asim Aslam c445aed6b1 Cleanup and speedup network convergence along with direct messaging for connect and solicit 2019-12-07 19:54:29 +00:00
Asim Aslam 1d8c66780e save working solution 2019-12-06 00:18:40 +00:00
Asim Aslam 219efd27e9 Optimise the multicast to use one session in the tunnel 2019-12-05 23:11:42 +00:00
Asim Aslam ac9001ac74 advert ttl inline with router table tick 2019-12-05 17:50:32 +00:00
Asim Aslam 2896614595 Merge pull request #1025 from milosgajdos83/router-knobs
Changed a few router knobs to avoid storms ⛈
2019-12-05 17:50:02 +00:00
Milos Gajdos bca12a7003 Changed a few router knobs to avoid storms ⛈ 2019-12-05 17:11:17 +00:00
Vasiliy Tolstov 1c5a4c470f add server Context option to pass own context
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2019-12-05 19:37:03 +03:00
Asim Aslam 744b19d625 Merge pull request #1023 from milosgajdos83/dead-code
Fixing dead code and go vet moaning
2019-12-05 16:18:13 +00:00
Milos Gajdos 5865e89bed Fixing dead code and go vet moaning 2019-12-05 16:10:49 +00:00
Asim Aslam 3a10b1cdde Merge pull request #1022 from milosgajdos83/tunnel-races
This PR fixes various tunnel race conditions
2019-12-05 15:59:29 +00:00
Milos Gajdos 5db7514a91 This PR fixes various tunnel race conditions 2019-12-05 15:50:32 +00:00
Vasiliy Tolstov a957e90ca8 add RegisterCheck web server option for internal health checks
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2019-12-05 17:28:11 +03:00
Asim Aslam 18cf025056 Merge pull request #1020 from Allenxuxu/master
Avoid excessive memory usage
2019-12-05 11:56:44 +00:00
Allenxuxu b55b7d6b20 replace map with list 2019-12-05 19:29:48 +08:00
Asim Aslam 26b5d1994a Merge pull request #1019 from tboerger/no-newlin
No newlines at end of log messages
2019-12-05 10:08:16 +00:00
Thomas Boerger 30aec5b872 No newlines at end of log messages
Log messages should not end with a new line, this should be entirely
handled by the underlying log library.

Signed-off-by: Thomas Boerger <thomas@webhippie.de>
2019-12-05 10:56:45 +01:00
Asim Aslam b0626089f3 Merge pull request #1016 from unistack-org/lint
lint fixes mostly for prealloc also remove deadcode from grpc client
2019-12-05 08:33:52 +00:00
Asim Aslam af3d4e595f in memory stats buffer 2019-12-05 00:08:46 +00:00
Asim Aslam 40c09eed1c Logs to Log 2019-12-05 00:01:17 +00:00
Asim Aslam fe46e7a9e9 Logs to Log 2019-12-04 23:58:29 +00:00
Asim Aslam 78647c7027 add timestamp to stats 2019-12-04 23:51:07 +00:00
Asim Aslam 26755f86b1 Merge pull request #1018 from micro/debug-service
Debug service
2019-12-04 14:40:58 +00:00
Asim Aslam 898848795b tab indent 2019-12-04 12:28:16 +00:00
Asim Aslam 24efbe6a41 Move debug handler to service dir 2019-12-04 12:27:30 +00:00
Asim Aslam 97433f716f add service name to debug proto 2019-12-04 12:02:44 +00:00
Asim Aslam 5200febaea add stats debug interface 2019-12-04 11:53:20 +00:00
Vasiliy Tolstov a1eaf9cc20 linting fixes
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2019-12-04 00:22:02 +03:00
Asim Aslam 3f8af8c1e0 Merge branch 'master' of ssh://github.com/micro/go-micro 2019-12-03 20:32:10 +00:00
Asim Aslam becaeefcba Revert. DO NOT peer solicit until we know better 2019-12-03 20:32:02 +00:00
Vasiliy Tolstov 7d5bdcf993 fix pointer dereference in memory registry
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2019-12-03 23:05:03 +03:00
Asim Aslam 81a7cf458c Merge pull request #1013 from unistack-org/linting
add golanglint-ci
2019-12-03 16:57:00 +00:00
Asim Aslam a4ea61334b Merge pull request #1015 from milosgajdos83/router-race
Fix router race condition
2019-12-03 16:55:56 +00:00
Asim Aslam 3fbba9f83d Merge pull request #1014 from milosgajdos83/memreg-race
Fix memory registry race
2019-12-03 16:51:36 +00:00
Milos Gajdos 4a11a4c546 Fix router race condition 2019-12-03 15:22:54 +00:00
Milos Gajdos 265233517e Fix memory registry race 2019-12-03 14:53:07 +00:00
Vasiliy Tolstov c581ceb1dc add golanglint-ci
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2019-12-03 16:31:43 +03:00
Asim Aslam bb1a1358b7 Merge pull request #1012 from Astone-Chou/lint
improve code quality
2019-12-03 13:10:04 +00:00
Astone 29fb58db39 improve code quality 2019-12-03 20:59:02 +08:00
Asim Aslam b6f0164501 Merge branch 'master' of ssh://github.com/micro/go-micro 2019-12-03 08:11:46 +00:00
Asim Aslam 2c0801fc1c couple bug fixes in tunnel 2019-12-03 08:11:36 +00:00
Asim Aslam 34c92f4964 Merge pull request #1011 from Astone-Chou/master
optimize: a better way for return error
2019-12-03 07:48:21 +00:00
Astone f9b900b2ca optimize: a better way for return error 2019-12-03 12:47:29 +08:00
Asim Aslam b5d65305db Merge pull request #1009 from unistack-org/panics
recover panics
2019-12-02 23:30:17 +00:00
Vasiliy Tolstov b8e96f45d4 add recovery in case of panics
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2019-12-03 02:25:40 +03:00
Vasiliy Tolstov 90f9b0d0c9 initialize client options context if not provided
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2019-12-03 01:35:59 +03:00
Asim Aslam 972c0989af Merge pull request #1008 from micro/connect-fast
Optimizations to connect fast
2019-12-02 19:09:56 +00:00
Asim Aslam 5f04fd58ab optimizations to connect fast 2019-12-02 18:48:19 +00:00
Asim Aslam da04aa8ae8 Switch to AdvertiseLocal by default 2019-12-02 17:36:20 +00:00
Asim Aslam 62bf0df864 Merge pull request #1007 from micro/ultra-hacks
ultra hacks to make debug handler work in proxy
2019-12-02 15:11:56 +00:00
Asim Aslam 91e9c0cb62 ultra hacks to make debug handler work in proxy 2019-12-02 14:55:35 +00:00
Asim Aslam 3356b83f24 register debug handler 2019-12-01 21:04:09 +00:00
Asim Aslam 795ec509fd Merge branch 'master' of ssh://github.com/micro/go-micro 2019-12-01 19:43:45 +00:00
Asim Aslam 93d66afe8c fix that broken logic 2019-12-01 19:43:36 +00:00
Asim Aslam c840cee404 A variety of fixes to try combat the multicast issue 2019-12-01 19:36:16 +00:00
Milos Gajdos e48cce6485 Merge pull request #1005 from milosgajdos83/nano-seconds
Time resolution change to be in line with debug/handler.Handler
2019-12-01 18:39:59 +00:00
Milos Gajdos b2ecd93404 Time resolution change to be in line with debug/handler.Handler 2019-12-01 18:33:08 +00:00
Asim Aslam 2928c66624 Merge pull request #1004 from milosgajdos83/debug-logs
[WIP] Debug logs
2019-12-01 17:40:40 +00:00
Milos Gajdos 4613a820ca Small refactoring og logs
* log.Write now accepts log.Record
* we stream last 10 records first
* regenerate proto because of the above
2019-12-01 13:16:44 +00:00
Milos Gajdos ecdadef633 Added hack support for logs streaming cruft 2019-12-01 13:16:44 +00:00
Milos Gajdos 7f1dea72f2 Simplified Logs RPC. Cleaned up code. Added comments. 2019-12-01 13:16:44 +00:00
Milos Gajdos 612f872f76 Server should not close the stream when done 2019-12-01 13:16:44 +00:00
Milos Gajdos 13d2a9ec7a Register proto handler properly 2019-12-01 13:16:44 +00:00
Milos Gajdos 9fab47ecdb Added DefaultLog variables 2019-12-01 13:16:44 +00:00
Milos Gajdos 265e8ade05 Embed DebugHandler proto 2019-12-01 13:16:44 +00:00
Milos Gajdos 60e0e81523 Added debug/service to grab the logs from a service 2019-12-01 13:16:43 +00:00
Milos Gajdos b01357058a Regenerate proto cruft 2019-12-01 13:16:43 +00:00
Milos Gajdos 7deafbc5ce Added ReadOptions; Changed proto; Reimplemented Log(er) 2019-12-01 13:16:43 +00:00
Milos Gajdos 9e177be560 Embed logger into debug.Handler 2019-12-01 13:16:43 +00:00
Milos Gajdos ee9776e7b2 Added debug.Logger interface 2019-12-01 13:16:43 +00:00
Milos Gajdos 3f7f2afc7b Dont be stupid -- stream does not require pointer. 2019-12-01 13:16:43 +00:00
Milos Gajdos 4e965e4ce5 First commit. Modified proto. Added empty handler method. 2019-12-01 13:16:43 +00:00
Asim Aslam 6f1c30aef5 remove unused value in router 2019-11-30 21:39:03 +00:00
Asim Aslam 00bbb3ac61 revert some protocol changes for now 2019-11-30 21:20:33 +00:00
Asim Aslam ce1942c578 why didn't we think of this before...single service name for http broker 2019-11-30 21:00:36 +00:00
Asim Aslam df7169c9f2 Merge branch 'master' of ssh://github.com/micro/go-micro 2019-11-30 01:16:53 +00:00
Asim Aslam 5e59db4c6d revert mdns timeout 2019-11-30 01:16:32 +00:00
Asim Aslam 25b3fda25b Merge pull request #1002 from micro/tun-fix
fix bug in the tunnel which causes multicast connections to be closed
2019-11-30 01:16:12 +00:00
Asim Aslam 9678daeafa fix bug in the tunnel which causes multicast connections to be closed 2019-11-30 01:14:40 +00:00
Asim Aslam 9ed257f151 Merge pull request #1001 from micro/storm
Changes for the storm
2019-11-29 17:33:23 +00:00
Asim Aslam 107124e5dc Changes for the storm 2019-11-29 17:27:29 +00:00
Asim Aslam ce4acfa892 fix type filtering for k8s runtime 2019-11-29 13:05:18 +00:00
Asim Aslam 6bf4828296 triple the mdns timeout 2019-11-29 13:05:07 +00:00
Asim Aslam 76b4e78a6a fix command to accept variadic args 2019-11-29 11:55:25 +00:00
Asim Aslam 8b6475b8d4 Merge pull request #1000 from micro/runtime-type
Support service types in runtime
2019-11-29 11:46:21 +00:00
Asim Aslam c3ed83dfba Support service types in runtime 2019-11-29 11:35:00 +00:00
Asim Aslam 114bc1e18b Merge pull request #995 from micro/rpc-leak
Fix rpc go routine leak
2019-11-27 17:24:19 +00:00
Asim Aslam af94899b54 Fix rpc go routine leak 2019-11-27 17:12:07 +00:00
Asim Aslam 266b6dbc64 add debug buffer time based access 2019-11-27 13:57:19 +00:00
Asim Aslam 5932dd753c Merge pull request #981 from unistack-org/subscriber
subscriber recovery
2019-11-27 10:28:51 +00:00
Vasiliy Tolstov 86a6328254 subscriber recovery
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2019-11-27 13:21:20 +03:00
Asim Aslam 0d33c029a9 Merge pull request #994 from milosgajdos83/validator-regexp
Remove validator regexp as its no longer needed.
2019-11-27 08:10:00 +00:00
Milos Gajdos 8ecd2381a4 Remove validator regexp as its no longer needed. 2019-11-26 23:10:45 +00:00
Asim Aslam 7318807dce Merge pull request #993 from micro/k8s-fixes
Add fixes for label selector and skipping things that don't match
2019-11-26 22:32:58 +00:00
Asim Aslam 811275be26 Add fixes for label selector and skipping things that don't match 2019-11-26 22:28:08 +00:00
Asim Aslam 3f3fd38601 Add spec.template.metadata.annotations to the k8s template 2019-11-26 18:14:49 +00:00
Asim Aslam 44dd0b1302 Merge pull request #991 from micro/k8s-update
Patch spec template annotations and use event timestmap
2019-11-26 17:38:56 +00:00
Asim Aslam 6475c1f3ad Patch spec template annotations and use event timestmap 2019-11-26 17:33:41 +00:00
Asim Aslam deabf0b8c9 fix entry into nil map 2019-11-26 14:56:23 +00:00
Asim Aslam 04ee4b04ad Merge pull request #990 from micro/buffer
Add debug/buffer package as a simple ring buffer
2019-11-26 14:27:39 +00:00
Asim Aslam 2892686c5f Merge pull request #988 from micro/k8s-update
Change the k8s runtime notifier update to get the deployment and upda…
2019-11-26 14:21:42 +00:00
Asim Aslam 8ee31a63f1 Add debug/buffer package as a simple ring buffer 2019-11-26 14:20:45 +00:00
Asim Aslam 4e363da91f Merge pull request #989 from micro/proto
Regenerate the protos
2019-11-26 13:57:49 +00:00
Asim Aslam 8b63df7a98 regenerate the protos 2019-11-26 13:53:33 +00:00
Asim Aslam b06854b0d5 Change the k8s runtime notifier update to get the deployment and update build 2019-11-26 13:49:52 +00:00
Jake Sanders 39bf71376a Add some more issue templates (#987)
* Add some more issue templates

* Update bug_report.md

* Update bug_report.md
2019-11-26 11:48:14 +00:00
Jake Sanders 12d9c5b187 Merge pull request #986 from micro/bug-report-template
Create Bug Report Issue Template
2019-11-26 11:25:42 +00:00
Jake Sanders d2eba3f8f9 Create Bug Report Issue Template
To encourage users to provide context with bug reports
2019-11-26 11:17:32 +00:00
Milos Gajdos 19f2f8b161 Merge pull request #982 from xmlking/master
go-micro docker now includes unprivileged user
2019-11-26 10:54:18 +00:00
Sumanth Chinthagunta d41185eb84 go-micro docker now includes unprivileged user 2019-11-25 18:42:24 -08:00
Asim Aslam c420fa2dec Merge pull request #979 from milosgajdos83/tunnel-encrypt
[WIP] Tunnel encryption
2019-11-25 19:12:24 +00:00
Asim Aslam db03a564fb Merge pull request #980 from unistack-org/issue-940
grpc client goroutine leak fix
2019-11-25 19:10:34 +00:00
Vasiliy Tolstov 9763820c75 grpc client goroutine leak fix
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2019-11-25 22:02:24 +03:00
Milos Gajdos 9095b99f6b Token has been stripped; Headers are encrypted 2019-11-25 18:56:00 +00:00
Asim Aslam 080363e8c4 The mega cruft proxy PR (#974)
* the mega cruft proxy PR

* Rename broker id

* add protocol=grpc

* fix compilation breaks

* Add the tunnel broker to the network

* fix broker id

* continue to be backwards compatible in the protocol
2019-11-25 16:31:43 +00:00
Asim Aslam 252667398e Update the runtime for k8s name formatting and move Get to Read endpoint (#978)
* Update the runtime for k8s name formatting and move Get to Read endpoint

* strip regex validation
2019-11-25 16:31:14 +00:00
Milos Gajdos f82c267d81 Encrypt session communication 2019-11-25 15:37:38 +00:00
Milos Gajdos 61fe552ac4 First commit: Outline of tunnel encryption code 2019-11-25 14:58:12 +00:00
Asim Aslam 7013e7467f Undefined time 2019-11-25 09:33:30 +00:00
Asim Aslam dbc537007d First interface for auth 2019-11-25 09:30:26 +00:00
Asim Aslam 95045be83d Merge branch 'master' of ssh://github.com/micro/go-micro 2019-11-23 22:50:45 +00:00
Asim Aslam 52ccd900c7 reorder service struct fields 2019-11-23 22:50:13 +00:00
罗泽轩 64a251d69a improve the syncMap.Iterate test to make it 100% reproducible (#970)
* improve the syncMap.Iterate test to make it 100% reproducible

* rename store/mocks/Store.go

* rename mocks/store to mock/store
2019-11-23 14:13:17 +00:00
Asim Aslam cae4148594 Fix platform specific os/process build 2019-11-23 08:25:56 +00:00
Milos Gajdos 38e29c5101 Svc metadata (#972)
* Added service metadata

* Added metadata to runtime service

* Add Annotations metadata to service metadata

* Add micro/micro as default service owners

* Update runtime/kubernetes/client/kubernetes.go

Change comment

Co-Authored-By: Jake Sanders <i@am.so-aweso.me>
2019-11-22 17:10:00 +00:00
Milos Gajdos 8dc3fb964e Pass source of service to Deployment API; render templates properly (#969)
* Pass source of service to Deployment API; render templates properly

* Enable Go modules by default. Honor runtime.Service.Exec

* Make sure you remove go.mod and go.sum
2019-11-21 17:31:13 +00:00
Asim Aslam 212144d658 fix windows compilation error 2019-11-21 11:19:52 +00:00
Milos Gajdos 11d81221cc Runtime service implementation (#965) 2019-11-20 14:54:42 +00:00
Milos Gajdos 55252cbc32 Fix the router test; get rid of time dependency (#964) 2019-11-20 14:53:12 +00:00
Asim Aslam c87a58db0a add ability to set web icon 2019-11-20 12:43:43 +00:00
Vasiliy Tolstov 49d73faa5f return error to caller on grpc server request processing (#962)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2019-11-20 10:28:30 +00:00
Vasiliy Tolstov da6c1be607 dont panic on missing headers in broker event (#963)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2019-11-20 07:55:47 +00:00
Milos Gajdos 94d409b180 Change DefaultImage to micro/go-micro 2019-11-19 20:49:01 +00:00
Milos Gajdos d6e97c5970 Service.Exec is a slice of strings (#960) 2019-11-19 19:36:29 +00:00
Asim Aslam 64d5a528ca fix broken build 2019-11-19 16:55:33 +00:00
Milos Gajdos 538d3752f9 Added Dockerfile for go-micro (#959) 2019-11-19 16:50:31 +00:00
Asim Aslam fb5b358ae2 fix mdns test 2019-11-19 16:50:16 +00:00
Milos Gajdos 6a0082741c Packager is now builder (#958) 2019-11-19 16:09:43 +00:00
Shu xian 5744050943 api event supports for GET url params (#956) 2019-11-18 16:37:45 +00:00
Asim Aslam 168cc06827 increase timeout on travis 2019-11-18 12:58:06 +00:00
Asim Aslam fa01cadc35 lower the mdns timeout to 10ms (#955) 2019-11-18 12:50:51 +00:00
Asim Aslam 342c29de7d fix TestMemoryRegistryTTLConcurrent test 2019-11-16 21:13:06 +00:00
Asim Aslam eeed493766 move test data 2019-11-16 18:52:27 +00:00
Asim Aslam 90d7a87914 Move wrapper internally since its not top level relevant 2019-11-16 18:48:24 +00:00
Erik Hollensbe a1c6cdf193 Now specify HandleSignal as an option to toggle signal handling. (#948)
Signed-off-by: Erik Hollensbe <github@hollensbe.org>
2019-11-16 11:13:34 +00:00
Erik Hollensbe bec13a45cd Attempt to fix the timing error in the memory concurrency test (#952)
Only shows in travis

Signed-off-by: Erik Hollensbe <github@hollensbe.org>
2019-11-16 11:11:13 +00:00
Erik Hollensbe 4107733453 Memory registry from #801 with additional tweaks (#951)
* PoC: memory registry using maps instead of slice madness

* Updated proto and handlers. Fixed tests across codebase.

* Implemented ttl pruning for memory registry

* Added extensive memory registry tests

* Squased a bunch of bugs

* Proto indent; memory.Registry.String() returns "memory"

* Write a test to prove memory registry TTLs are busted

Signed-off-by: Erik Hollensbe <github@hollensbe.org>

* Additional memory testing and fixups:

* DefaultTTL removed
* When TTL == 0, it is automatically removed from expiry conditions
* Additional improvements to new tests

Signed-off-by: Erik Hollensbe <github@hollensbe.org>
2019-11-16 10:55:11 +00:00
Milos Gajdos 97c1300f53 [WIP] Micro Runtime (#947)
* Add Get() and GetOptions.

* Removed watcher. Outline of client. YAML templates

* Added default service and deployment templates and types

* Added API tests and cleaned up errors.

* Small refactoring. Template package is no more.

* Ripped out existing code in preparation to small rework

* Reshuffled the source code to make it organized better

* Create service and deployment in kubernetes runtime

* Major cleanup and refactoring of Kubernetes runtime

* Service now handles low level K8s API calls across both K8s deployment
an service API objects
* Runtime has a task queue that serves for queueing runtime action
requests
* General refactoring

* No need for Lock in k8s service

* Added kubernetes runtime env var to default deployment

* Enable running different versions of the same service

* Can't delete services through labels

* Proto cruft. Added runtime.CreateOptions implementation in proto

* Removed proxy service from default env variables

* Make service name mandatory param to Get method

* Get Delete changes from https://github.com/micro/go-micro/pull/945

* Replaced template files with global variables

* Validate service names before sending K8s API request

* Refactored Kubernetes API client. Fixed typos.

* Added client.Resource to make API resources more explicit in code
2019-11-15 13:41:40 +00:00
mirwaisx 0af8be35bb -bugfix #889 set body corretly in case of missing content-type (#950) 2019-11-15 13:03:45 +00:00
Asim Aslam a91b3f3e8b windows specific os tag 2019-11-15 08:20:05 +00:00
Asim Aslam 383658edf2 Fix a runtime deadlock as well as fixing some graceful exiting issues (#945) 2019-11-14 14:26:21 +00:00
Asim Aslam 16754a7477 Set theme jekyll-theme-architect 2019-11-14 11:55:07 +00:00
Asim Aslam 58b25d7241 Update CNAME 2019-11-14 11:54:16 +00:00
Asim Aslam 1c7d44282e Set theme jekyll-theme-minimal 2019-11-14 11:17:02 +00:00
Asim Aslam 8e9eef794f Set theme jekyll-theme-minimal 2019-11-14 11:15:50 +00:00
Asim Aslam 920c026f14 Create CNAME 2019-11-14 11:01:36 +00:00
Asim Aslam 946c76cb03 Delete CNAME 2019-11-14 11:01:27 +00:00
Asim Aslam 43d11a9b8d Create CNAME 2019-11-14 10:50:51 +00:00
Asim Aslam 9f481542f3 Fix a codec race by locking the buffers. Include a buffer pool for perf. (#941)
* Fix a codec race by locking the buffers. Include a buffer pool for perf.

* Read Lock on buffer Read
2019-11-13 11:05:53 +00:00
Asim Aslam cffa5b6b50 Make use of cloudflare 1.0.0.1 by default to resolve addresses 2019-11-12 15:46:30 +00:00
Asim Aslam 8867539d78 Update FUNDING.yml 2019-11-12 12:35:09 +00:00
Asim Aslam 671408b3a5 Create FUNDING.yml 2019-11-12 12:27:51 +00:00
Lars Lehtonen bdb62e8ed1 store/postgresql: fix dropped error (#938) 2019-11-12 07:54:33 +00:00
Asim Aslam 72522a869a fix endpoint extractor panic 2019-11-11 17:37:48 +00:00
Asim Aslam fd5c29addc Add the ability to only advertise local routes or don't advertise at all (#932)
* Add the ability to only advertise local routes or don't advertise at all

* Reorder processing to shortcircuit no advertising
2019-11-11 15:28:37 +00:00
Asim Aslam 65b1283459 add metadata.Get(context, key) as short hand 2019-11-11 09:13:02 +00:00
Huang.X 5ffe367cae fix# Change the Log level and add WarnLevel (#935)
* fix# Change the Log level and add WarnLevel

* fix# Change the Log level and add WarnLevel
2019-11-11 07:57:13 +00:00
Till Knuesting 5ae3e179b9 preallocated slices (#934) 2019-11-11 00:03:51 +00:00
Vasiliy Tolstov c696a859be fix data race for server Wait option (#931)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2019-11-09 21:52:41 +00:00
Asim Aslam 174b01ca29 update link in readme 2019-11-09 16:20:54 +00:00
Asim Aslam c433de80cd Update go mod 2019-11-09 15:44:52 +00:00
Asim Aslam f2b4c07a00 Merge branch 'master' of ssh://github.com/micro/go-micro 2019-11-09 15:37:54 +00:00
Asim Aslam 929ffdcc42 Update readme 2019-11-09 15:37:30 +00:00
Lars Lehtonen 5aa28dfb0d store/cloudflare: fix dropped error (#930) 2019-11-09 15:18:51 +00:00
Asim Aslam a9e8fc6039 Don't set stream unless its true 2019-11-09 10:32:52 +00:00
Milos Gajdos 0b1e6d7eaf Simplified k8s API Body watcher code and test. (#923) 2019-11-08 15:57:32 +00:00
Milos Gajdos 1ffa289d39 Make build timestamp parsing errors clearer (#929) 2019-11-08 15:57:07 +00:00
Milos Gajdos 68419cc024 Patch deployment spec metadata (#928) 2019-11-08 14:12:03 +00:00
Vasiliy Tolstov 8227206208 use service id in profile file name (#925)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2019-11-08 09:11:55 +00:00
Milos Gajdos 6f28852e1b K8s list deployments (#921)
* Outline of ListDeployments method

* Added implementation of DeploymentList
2019-11-07 07:44:57 +00:00
Asim Aslam 0e3550229b update readme 2019-11-06 22:04:02 +00:00
Asim Aslam f9400ba713 update readme 2019-11-06 22:03:35 +00:00
Asim Aslam ce080d76c6 add debug/profile package (#920)
* add debug/profile package

* set service+version for profile
2019-11-06 19:36:04 +00:00
Asim Aslam 254045e9f3 Remove go routines for mdns watcher and cache registry (#919) 2019-11-06 15:49:40 +00:00
Milos Gajdos b84134581c Flap detection vol2 (#915)
* We now purge flapping routes before regular tick processes them

* Updated comments

* Record the timestamp as soon as you receive the event

* Set route Address to routing table test

* Fixed a bunch of deadlocks. Added basic Router tests.
2019-11-05 17:44:24 +00:00
Till Knuesting f67c5e779f preallocated slices (#917) 2019-11-05 17:43:12 +00:00
Milos Gajdos 4a694c9d02 Change flap detection configuration (#914)
* Change flap detection configuration

* Make PenaltyHalfLife a float, not int 🤦‍♂️

* Lower event suppression to 200
2019-11-04 19:01:52 +00:00
Till Knuesting 24b8d2a315 preallocating slices (#904)
* preallocated some slices when size is known

* gofmt

* gofmt
2019-11-04 10:33:53 +00:00
Asim Aslam 2f3c251b00 Recovery should be < 500 2019-11-03 17:10:00 +00:00
Asim Aslam c1b0a968ae Augment the router penalty and decay as a hack fix (#912)
* Augment the router penalty and decay as a hack fix

* increase recovery cost
2019-11-03 16:29:10 +00:00
Asim Aslam 81e9298be6 Merge branch 'master' of ssh://github.com/micro/go-micro 2019-11-03 16:12:24 +00:00
Asim Aslam 45cd14c4b7 Suppress log messages 2019-11-03 16:12:17 +00:00
罗泽轩 8579c8b321 avoid deadlock in syncMap.Iterate (#909)
Previously, when syncMap iterates a list of records which have the same
content in different order, a deadlock might happen. By enforcing a certain
order, the deadlock can be avoided.
2019-11-03 08:18:48 +00:00
罗泽轩 bd37e67839 fix a typo in sync/lock/memory package (#910) 2019-11-03 08:17:01 +00:00
Asim Aslam d3151f1f0f Merge branch 'master' of ssh://github.com/micro/go-micro 2019-11-02 23:13:10 +00:00
Asim Aslam c45ea62ea8 Do not deregister services in the monitor unless Reap is called 2019-11-02 23:13:01 +00:00
Yang Shi c14bf5dc4e improve the log of panic recovering (#906) 2019-11-02 23:08:54 +00:00
Asim Aslam 292da40886 runtime handler/proto placeholder 2019-11-02 22:54:35 +00:00
Milos Gajdos 6f7702a093 [WIP] K8s update and runtime package changes (#895)
* First commit: outline of K8s runtime package

* Added poller. Added auto-updater into default runtime

* Added build and updated Poller interface

* Added comments and NewRuntime that accepts Options

* DefaultPoller; Runtime options

* First commit to add Kubernetes cruft

* Add comments

* Add micro- prefix to K8s runtime service names

* Get rid of import cycles. Move K8s runtime into main runtime package

* Major refactoring: Poller replaced by Notifier

POller has been replaced by Notifier which returns a channel of events
that can be consumed and acted upon.

* Added runtime configuration options

* K8s runtime is now Kubernetes runtime in dedicated pkg. Naming kung-fu.

* Fix typo in command.

* Fixed typo

* Dont Delete service when runtime stops.

runtime.Stop stops services; no need to double-stop

* Track runtime services

* Parse Unix timestamps properly

* Added deployments into K8s client. Debug logging
2019-11-02 13:25:10 +00:00
Asim Aslam a94a95ab55 Merge pull request #908 from hb-chen/fix-907
fix-907
2019-11-02 08:59:14 +00:00
Hobo86 e8d2f207d8 fix-907
web service need modify registry service nodes while register interval
2019-11-02 16:39:56 +08:00
Asim Aslam bd1918900e Merge pull request #901 from micro/sqlstore
Implementation of PostgreSQL for micro store
2019-11-01 15:48:47 +00:00
Asim Aslam cf3af68e31 Merge pull request #903 from tegk/gofmt
used gofmt with -s flag on whole project
2019-11-01 15:25:53 +00:00
Jake Sanders 15e3b9b4c0 Let people connect with just a hostname 2019-11-01 15:16:05 +00:00
Asim Aslam 107a7ab07f Merge pull request #902 from micro/runtime-panic
Fix panic caused when ctrl+c a non started service
2019-11-01 15:12:33 +00:00
Asim Aslam e9dfccc616 Fix panic caused when ctrl+c a non started service 2019-11-01 15:08:01 +00:00
tegk f88518d994 used gofmt with -s flag on whole project 2019-11-01 15:07:53 +00:00
Jake Sanders ee35fe61af update go.mod for postgres 2019-11-01 14:13:47 +00:00
Jake Sanders dee63b2b2c Implementation of postgres store 2019-11-01 14:13:21 +00:00
Asim Aslam 0aa01b2ebf Output the build error in plugin 2019-11-01 08:33:14 +00:00
Asim Aslam f089a89e8a Merge pull request #897 from micro/route-filtering
add ability to filter routes based on headers
2019-11-01 08:15:23 +00:00
Asim Aslam 174fbde049 add ability to filter routes based on headers 2019-10-31 22:34:06 +00:00
Asim Aslam 967d7ecda7 fix runtime panic 2019-10-31 22:30:21 +00:00
Asim Aslam fb76755684 Merge branch 'master' of ssh://github.com/micro/go-micro 2019-10-31 17:22:45 +00:00
Asim Aslam cf593e7c50 fix link panic 2019-10-31 17:22:38 +00:00
Asim Aslam 74286c2939 Merge pull request #893 from yandd/master
fix rcache ttl
2019-10-30 21:31:08 +00:00
yandd f9c639af4e fix rcache ttl 2019-10-30 14:01:51 +08:00
Asim Aslam dab0f3223f Add Update/List endpoints to runtime 2019-10-29 12:29:21 +00:00
Asim Aslam d89256d8d5 add network resolver record priority field 2019-10-28 15:31:46 +00:00
Asim Aslam 99b410c81b fix metadata test 2019-10-25 23:28:43 +01:00
Asim Aslam 92b7d2db3b Rename to Merge 2019-10-25 23:27:59 +01:00
Asim Aslam 20c6c36bc4 Merge pull request #883 from xmlking/master
PatchContext method added
2019-10-25 23:23:37 +01:00
Asim Aslam 1f626a55ed Merge pull request #887 from micro/collapse-routes
hash address based on service name + node address
2019-10-25 23:12:56 +01:00
Asim Aslam b42d242ec1 hash address based on service name + node address 2019-10-25 23:06:49 +01:00
Asim Aslam 51922c1763 Refresh route metrics in the proxy 2019-10-25 22:46:43 +01:00
Sumanth Chinthagunta 1c6b85e05d AppendContext with overwrite flag 2019-10-25 08:27:28 -07:00
Asim Aslam e85863d6cc Merge pull request #886 from micro/tunnel-error
Don't error where the connection is not unicast
2019-10-25 15:48:09 +01:00
Asim Aslam 5d7bf53f78 don't error where the connection is not unicast 2019-10-25 15:41:37 +01:00
Asim Aslam 44c0f1946d Merge pull request #882 from micro/link-state
A few changes for the network / tunnel link state
2019-10-25 14:28:43 +01:00
Asim Aslam 1c9ada6413 Reorder setChannel method 2019-10-25 14:24:37 +01:00
Asim Aslam c170189efb We need the message back to set the link 2019-10-25 14:22:38 +01:00
Asim Aslam 3831199600 Use best link in tunnel, loop waiting for announce and accept messages, cleanup some code 2019-10-25 14:16:22 +01:00
Sumanth Chinthagunta 1f658cfbff adding PatchContext - this will create new context with original + patch metadata 2019-10-24 17:51:54 -07:00
Asim Aslam f26d470db1 A few changes for the network / tunnel link state 2019-10-24 17:51:41 +01:00
Asim Aslam f5b8a12106 Merge pull request #880 from milosgajdos83/tunnel-sessionlink
Make sure we pick some link when Dialling
2019-10-24 16:14:32 +01:00
Milos Gajdos 494eb13534 Make sure we pick some link when Dialling 2019-10-24 16:07:31 +01:00
Asim Aslam 4db1e09798 change options to be trimmed down 2019-10-23 23:12:45 +01:00
Asim Aslam 232c8ac7a1 More cleanup of store cf 2019-10-23 23:10:44 +01:00
Asim Aslam 68d0efbeaa Move api types in cf store 2019-10-23 22:57:11 +01:00
Asim Aslam 70aaca9876 further cleanup 2019-10-23 22:54:55 +01:00
Asim Aslam 3ce71e12ff Don't recall vals everywhere 2019-10-23 22:51:08 +01:00
Asim Aslam fb3d729681 sync map uses store list 2019-10-23 22:35:28 +01:00
Asim Aslam d65658c890 Update options usage in store/api 2019-10-23 22:31:36 +01:00
Asim Aslam 3fc04f4dff fixup some acme related things 2019-10-23 22:15:15 +01:00
Asim Aslam 82f94c7861 Change store.Sync to store.List 2019-10-23 22:05:39 +01:00
Asim Aslam ecac392dbe unexport api response/message in cloudflare store 2019-10-23 21:54:37 +01:00
Asim Aslam 4e5a568063 races, race conditions everywhere 2019-10-23 21:24:31 +01:00
Asim Aslam 87de2ecaa0 Merge pull request #876 from milosgajdos83/peerlink-route-metric
Peerlink route metric
2019-10-23 20:31:21 +01:00
Milos Gajdos 4f1dd3f965 Fixed a small messup when printing logs 2019-10-23 20:01:45 +01:00
Milos Gajdos 71122836b8 Use event.Route.Link for getting the route metrics 2019-10-23 19:55:01 +01:00
Milos Gajdos b67be88952 Check for local links and empty gateways 2019-10-23 19:48:26 +01:00
Asim Aslam 83b232ae26 Merge pull request #879 from micro/cloudflareexpiry
Throw away cloudflare-go library and reimplement workers KV
2019-10-23 17:44:13 +01:00
Milos Gajdos 776284b187 Make sure you dont overflow MaxInt64 2019-10-23 17:42:04 +01:00
Jake Sanders 53ee4ee482 goodbye cloudflare-go 2019-10-23 17:33:20 +01:00
Milos Gajdos 35729092e0 Unexport network.Message 2019-10-23 17:32:45 +01:00
Jake Sanders 4f5db08238 Remove cloudflare-go and reimplement workers KV 2019-10-23 17:31:15 +01:00
Milos Gajdos 68789af4ea Prune peerlinks of pruned nodes 2019-10-23 17:29:03 +01:00
Milos Gajdos b3d4a7f740 If no link found, return max possible value 2019-10-23 16:51:22 +01:00
Milos Gajdos f4f178c130 Set metric on egress. Increment metric on ingress. 2019-10-23 16:51:22 +01:00
Milos Gajdos 1ff65e140a Change router.Route metric to int64. Set the route metric properly 2019-10-23 16:51:22 +01:00
Milos Gajdos 326156671d Set route metric to link Length 2019-10-23 16:51:22 +01:00
Milos Gajdos 6353b2b894 Keep track of peer links 2019-10-23 16:51:22 +01:00
Asim Aslam caca93f65b Merge pull request #877 from micro/tun-delay
Tunnel Delay and link buffers
2019-10-23 16:49:18 +01:00
Asim Aslam bf4a73d5c0 Close the socket in the link 2019-10-23 16:39:26 +01:00
Asim Aslam fe180148a1 rearrange where we account for errors and data sent 2019-10-23 16:15:39 +01:00
Asim Aslam 842fc01568 add send/recv queues for link 2019-10-23 16:05:21 +01:00
Asim Aslam d4832e8f34 Remove consul registry (#818) 2019-10-23 15:53:28 +01:00
Asim Aslam 5ac5865154 add comment 2019-10-23 10:55:53 +01:00
Asim Aslam f07a6ac29b Merge pull request #875 from micro/tun-measure
Measure roundtrip times on link
2019-10-22 21:20:57 +01:00
Asim Aslam d64f8c665e add rate measure 2019-10-22 19:38:29 +01:00
Asim Aslam 407694232a Measure roundtrip times on link 2019-10-22 18:43:09 +01:00
Asim Aslam 418b8648bb Merge pull request #874 from micro/tun-metrics
Add placeholders for link metrics
2019-10-22 17:03:07 +01:00
Asim Aslam 85e273afa5 reorder methods 2019-10-22 17:02:22 +01:00
Asim Aslam ab9fa20a50 Update comments 2019-10-22 16:53:47 +01:00
Asim Aslam 4fddd69229 Add placeholders for link metrics 2019-10-22 16:50:00 +01:00
Asim Aslam 317cf76566 Merge pull request #872 from micro/round-robin
Round robin routes we've sorted by metric
2019-10-22 11:58:44 +01:00
Asim Aslam f792fac1cc Round robin routes we've sorted by metric 2019-10-22 11:53:49 +01:00
Asim Aslam a89d1edc41 fix divide by zero bug 2019-10-19 08:11:05 +01:00
Asim Aslam d3140c0fc2 Merge pull request #867 from milosgajdos83/rlock-mess
Avoid recursive RLock()
2019-10-18 11:35:08 +01:00
Milos Gajdos 3d5d9be02a Avoid recursive calls to RLock()
Topology calls itsel recursively invoking RLock. This, according to go
documentation is wrong. This commit moves the body of Topology function
to a non-thread safe unexported function to keep locsk at check!
2019-10-18 11:26:43 +01:00
Asim Aslam 5c38f38dd9 No need to lock here since Topology read locks and makes copies 2019-10-18 11:26:43 +01:00
Asim Aslam 63fd8b9d1b Merge pull request #864 from micro/strip-topic
strip topic from http broker subscribe service name
2019-10-17 18:48:46 +01:00
Asim Aslam 3aedea4c56 strip topic from http broker subscribe service name 2019-10-17 18:37:37 +01:00
Asim Aslam 0da9dff077 Merge pull request #863 from micro/certmagice2e
E2E tests for certmagic ACME provider
2019-10-17 16:42:33 +01:00
Jake Sanders 05774f2c76 Don't touch go.mod 2019-10-17 16:35:09 +01:00
Jake Sanders 4885bba2ac E2E tests for certmagic ACME provider
* Actually set the CA
* Fix the certmangic.storage interface to return the correct error type
* Write an e2e test for certmagic against the let's encrypt staging CA
2019-10-17 16:31:02 +01:00
Asim Aslam 9d559848c2 Merge pull request #862 from milosgajdos83/tunnel-cleanup
Cleanup of tunnel.Dial(). Clean up network channel processors
2019-10-16 21:19:30 +01:00
Milos Gajdos 2ae583ce94 Cleanup of tunnel dial code. Clean up network channel processors 2019-10-16 20:44:22 +01:00
Asim Aslam 7c1e22b607 Merge pull request #861 from micro/certmagicstorage
Distributed storage for certmagic
2019-10-16 14:10:02 +01:00
Jake Sanders 7d2afa34a0 Implementation and tests for certmagic.Storage interface 2019-10-16 12:58:14 +01:00
Jake Sanders a6e95d389f Implementation of certmagic storage using micro's store and sync packages 2019-10-15 19:32:20 +01:00
Asim Aslam b1d5dc20fa Merge pull request #860 from micro/tunnel-mode
Tunnel mode
2019-10-15 16:14:38 +01:00
Asim Aslam be5093798b Use DialMode/ListenMode 2019-10-15 16:08:38 +01:00
Asim Aslam 3759c9c091 Merge pull request #859 from milosgajdos83/handle-channel-conn-errors
Handle tunnel session Accept errors gracefully
2019-10-15 16:05:19 +01:00
Milos Gajdos 4936a2e1a5 Exponential backoff for failed accept connections 2019-10-15 15:58:33 +01:00
Asim Aslam ca934951ad Use multicast on network/control channels 2019-10-15 15:57:13 +01:00
Asim Aslam ca18089382 Fix bugs related to needing to send Broadcast 2019-10-15 15:55:08 +01:00
Asim Aslam 7b1f5584ab Tunnel mode 2019-10-15 15:40:04 +01:00
Milos Gajdos fed5af68e6 Handle Accept errors gracefully.
Originally when Accept fails we log the error and let the program flow
continue. This can lead to us spawning handling connection go routines
on nil connections which in turn leads to Go panics.
2019-10-15 15:07:28 +01:00
Asim Aslam fdfeb437f9 Merge pull request #856 from micro/cloudflare
Cloudflare Store implementation for workers KV
2019-10-15 14:29:34 +01:00
Jake Sanders a46133f059 cloudflare workers KV Store implementation 2019-10-15 12:35:45 +01:00
Jake Sanders 9bd0a8f3b5 Update go.mod for cloudflare 2019-10-15 12:35:20 +01:00
Asim Aslam 44b794722e rcache becomes cache 2019-10-14 22:39:26 +01:00
Asim Aslam 247249050b move mutex to memory 2019-10-14 22:38:22 +01:00
Asim Aslam b1fed01752 add network name to node 2019-10-14 22:26:23 +01:00
Asim Aslam df1e680256 Merge pull request #854 from micro/lock-http
Lock http
2019-10-14 22:01:25 +01:00
Asim Aslam 854b01c20c Add acquire/release to http path 2019-10-14 21:52:18 +01:00
Asim Aslam 745299bce5 add http lock implementation 2019-10-14 21:39:25 +01:00
Asim Aslam 607fdb3fcb Merge pull request #852 from micro/mutex
add mutex lock implementation
2019-10-14 15:23:59 +01:00
Asim Aslam a1342c23fb add mutex lock implementation 2019-10-14 15:17:25 +01:00
Asim Aslam 1cea2f5bba Merge pull request #850 from micro/acmetypo
TLS -> ToS
2019-10-14 12:10:55 +01:00
Jake Sanders a1b4786682 TLS -> ToS 2019-10-14 12:04:49 +01:00
Asim Aslam b701da6d69 Merge pull request #849 from micro/connect-init
Connect init
2019-10-13 18:40:11 +01:00
Asim Aslam f77df51f60 Support reconnects 2019-10-13 18:36:22 +01:00
Asim Aslam d6c6e7815e Spaces not tabs 2019-10-13 12:40:53 +01:00
Asim Aslam 01492997ea add Network.Init method 2019-10-13 12:38:13 +01:00
Asim Aslam 174f1b857c Network handler moves to service/handler 2019-10-13 12:37:56 +01:00
Asim Aslam 5029d80e68 add Network.Connect handler and network/metadata fields to node 2019-10-13 12:37:39 +01:00
Asim Aslam b59c5a4488 move network handler to service/handler 2019-10-13 12:37:13 +01:00
Asim Aslam f7f65b82e6 Cleanup registry handler/service 2019-10-13 12:23:13 +01:00
Asim Aslam 2e47fdc6f5 Check the node map to avoid dupes in resolved nodes 2019-10-12 20:26:06 +01:00
Asim Aslam 18ea19a122 Regenerate go.mod 2019-10-12 12:04:55 +01:00
Asim Aslam 4d75b936f8 Merge pull request #846 from theophanous/master
fix: bumped quic-go version to v0.12.1
2019-10-11 18:24:45 +01:00
Peter Theophanous 62aaa72715 fix: bumped quic-go version to v0.12.1 2019-10-11 18:16:56 +01:00
Asim Aslam 8c344ed55b Merge pull request #839 from theophanous/master
bumped quic-go version to v0.12.1
2019-10-11 17:26:48 +01:00
Peter Theophanous db843c8d87 reset orig 2019-10-11 17:15:20 +01:00
Asim Aslam dd7677e6cc Add nil check for acme provider 2019-10-11 16:52:57 +01:00
Asim Aslam a4f0dd8939 Merge pull request #845 from micro/certmagic
Implementation of CertMagic as the ACME provider
2019-10-11 16:52:21 +01:00
Jake Sanders 591e87448b Travis doesn't let us bind :443 2019-10-11 16:47:12 +01:00
Jake Sanders 09a202ccf0 Merge branch 'master' of https://github.com/micro/go-micro into certmagic 2019-10-11 16:25:28 +01:00
Jake Sanders 723c17fdd7 Implementation of certmagic as an ACME provider 2019-10-11 16:25:15 +01:00
Jake Sanders 9bd96d4cc1 Update go.mod for ACME changes 2019-10-11 16:24:25 +01:00
Asim Aslam 9bfe4d9bf7 Merge pull request #844 from micro/store
Store service implementation
2019-10-11 14:49:44 +01:00
Asim Aslam 76eee089e3 Add store service client 2019-10-11 14:44:42 +01:00
Asim Aslam cfa2b668e2 go fmt 2019-10-11 14:44:34 +01:00
Asim Aslam a96f6adf07 store handler implementation 2019-10-11 14:08:50 +01:00
Asim Aslam 49fe5d9fd5 Merge pull request #843 from milosgajdos83/dead-code
Clean up dead tunnel code
2019-10-11 11:15:29 +01:00
Milos Gajdos 21469a0427 Clean up dead tunnel code
Running go vet on tunnel package returns:
$ go vet ./...
./default.go:929:2: unreachable code
./link.go:104:2: unreachable code
./listener.go:184:2: unreachable code
./session.go:241:2: unreachable code
2019-10-11 11:02:45 +01:00
Asim Aslam e351e9518f Merge pull request #842 from milosgajdos83/cache-status
Check cache status error
2019-10-11 10:55:35 +01:00
Milos Gajdos fc89c9831e heck cache status error 2019-10-11 10:47:42 +01:00
Peter Theophanous 5e5d57d954 bumped quic-go version to v0.12.1 2019-10-10 22:23:33 +01:00
Asim Aslam 98e1f2c2d3 Merge pull request #838 from micro/etcd
Use etcd serializable option
2019-10-10 19:22:10 +01:00
Asim Aslam 59a3e7d4f4 Use etcd serializable option 2019-10-10 19:16:31 +01:00
Asim Aslam 1be6ec9b3c Merge pull request #837 from milosgajdos83/prune-dead-router-peers
Prune routes from routers that are not in your peer graph
2019-10-10 16:12:56 +01:00
Milos Gajdos f6931f3da7 Prune routes from routers that are not in your peer graph 2019-10-10 15:28:27 +01:00
Asim Aslam b2f99a27b7 Visit all the nodes in flatten 2019-10-10 14:35:11 +01:00
Asim Aslam 1f5ebf330d Merge pull request #836 from micro/prune-address
Prune the peer address
2019-10-10 11:43:19 +01:00
Asim Aslam 0dee11e006 Prune the peer address 2019-10-10 11:25:28 +01:00
Asim Aslam b55018eaa1 Merge pull request #833 from orbli/patch-1
Add dialoptions and calloptions
2019-10-10 07:40:48 +01:00
orb li 77108771db Conceptual deliverable 2019-10-10 13:55:16 +08:00
Asim Aslam 5a6e73d4a8 Merge pull request #835 from milosgajdos83/router-strategy
Router strategy
2019-10-09 19:18:59 +01:00
Milos Gajdos 7a4bff4e9f Changed names of some variables. 2019-10-09 19:08:24 +01:00
Milos Gajdos d5ce96da24 Avoid locking on reading strategy for now 2019-10-09 18:19:48 +01:00
Milos Gajdos 837597fe6f Make Optimal strategy default. Collapse routing tables based on strategy 2019-10-09 17:24:38 +01:00
Milos Gajdos 96e564e402 Add router advertisement Strategy option to router. 2019-10-09 17:24:38 +01:00
Asim Aslam fe94237448 Update router querying method (#834)
* Add address to router query options. Drop Query interface for QueryOptions

* Cleanup isMatch function

* Update network proto
2019-10-09 17:13:52 +01:00
Jake Sanders 107b7419b7 Start abstracting away the ACME provider (#830)
* Start abstracting away the ACME provider

* Move ACME to interface with sub-package implementations

* Addressing comments

* Library -> Provider

* Missed a couple of Library -> Provider

* One more Library -> Provider

* remove constants
2019-10-09 16:42:05 +01:00
orb li 226d55d752 Adding dependency 2019-10-09 16:48:45 +08:00
orb li 88ef785127 Add dialoptions and calloptions 2019-10-09 15:56:39 +08:00
Asim Aslam 44473f954f Merge pull request #829 from milosgajdos83/limit-net-connections
Limit the number of outbound connections to MaxConnections
2019-10-08 15:56:45 +01:00
Milos Gajdos fe5846603a Only limit the number of nodes returned by network resolver. 2019-10-08 15:48:52 +01:00
Milos Gajdos 61800fb7d7 Fix typo: MaxCconnections -> MaxConnections 2019-10-08 15:15:50 +01:00
Milos Gajdos ec2fbde979 Limit the number of outbound connections to MaxConnections
This commit also fixes control channel shenanigans:
- recover error in control channel accept
2019-10-08 14:48:04 +01:00
Asim Aslam b886dd4b8f Merge pull request #828 from micro/net-lookup
Use dns resolver on peer nodes
2019-10-08 10:36:04 +01:00
Asim Aslam 94adeebed4 Use dns resolver on peer nodes 2019-10-08 09:25:23 +01:00
Asim Aslam d043ca15c1 Merge pull request #827 from micro/resolver
Add dns net.LookupHost resolver!
2019-10-08 09:08:34 +01:00
Asim Aslam ad823d5177 Add dns net.LookupHost resolver! 2019-10-08 09:04:13 +01:00
Asim Aslam 89d71417f5 Merge pull request #825 from milosgajdos83/net-chan-nodes
Recover net channel Accept() errors. Init tunnel nodes before tunnel.Connect()
2019-10-07 20:29:45 +01:00
Milos Gajdos 9d9683b6f9 Recover net channel Accept errors. Init tunnel nodes before Connect 2019-10-07 19:09:04 +01:00
Asim Aslam 0edcd5c8dc Merge pull request #824 from micro/tunnel
wait for response on accept message
2019-10-07 18:33:00 +01:00
Asim Aslam 2e1432d5dc wait for response on accept message 2019-10-07 18:29:49 +01:00
Asim Aslam e4f8b5de70 Merge pull request #823 from micro/list-services
Support listing full service info in etcd
2019-10-07 16:15:30 +01:00
Asim Aslam e9dcff49e0 Support listing full service info in etcd 2019-10-07 16:11:52 +01:00
Asim Aslam fa6590f999 Merge pull request #822 from micro/service
Add Name to Service
2019-10-07 08:43:07 +01:00
Asim Aslam fd8a0fb2f5 Update internal service definition 2019-10-07 08:34:15 +01:00
Asim Aslam b594547408 Add service Name 2019-10-07 08:32:28 +01:00
Asim Aslam 2c00e726b6 Decode and hash the existing node 2019-10-06 13:43:41 +01:00
Asim Aslam 68a3fc7996 Merge pull request #820 from micro/etcd-reg
Fix etcd registry lease processing and suppression
2019-10-06 10:03:38 +01:00
Asim Aslam 2fb2d7145e Fix etcd registry lease processing and suppression 2019-10-06 09:54:26 +01:00
Asim Aslam 6fe9f2a958 Merge pull request #815 from micro/broker
Add broker service implementation
2019-10-04 17:23:29 +01:00
Asim Aslam 86984a8a8a Extend the stream timeout 2019-10-04 16:44:21 +01:00
Asim Aslam cfb846ee7e Fix race in cache 2019-10-04 16:40:21 +01:00
Asim Aslam e36960612a go fmt 2019-10-04 16:40:16 +01:00
Asim Aslam 04320d69ff Fix and comment broker service 2019-10-04 16:30:03 +01:00
Asim Aslam c4b6d0f3a8 fix major deadlock in registry cache 2019-10-04 16:29:56 +01:00
Asim Aslam 3c6b6553fb Use peerAddress as the thing to listen on 2019-10-03 18:35:54 +01:00
Asim Aslam d5658ab0b0 Merge pull request #816 from micro/net-advertise
Advertise your peer address as advertised address
2019-10-03 17:42:11 +01:00
Asim Aslam 2244eb8597 Advertise your peer address as advertised address 2019-10-03 17:37:29 +01:00
Asim Aslam 05eacd74c8 Add logging for broker handler 2019-10-03 17:30:37 +01:00
Asim Aslam b80654bf7e Add broker service to config/cmd 2019-10-03 16:22:26 +01:00
Asim Aslam 0941a0f031 Merge pull request #814 from milosgajdos83/etcd-port
Append a port to address if it does not exist
2019-10-03 16:20:43 +01:00
Asim Aslam 4de346920f Add broker service implementation 2019-10-03 16:19:02 +01:00
Milos Gajdos b8815dff14 Append a port to address if it does not exist 2019-10-03 16:16:25 +01:00
Asim Aslam b1163b9dee Fix breaking import 2019-10-03 11:26:24 +01:00
Asim Aslam af5d7a3420 Move the remaining consul cruft to go-plugins 2019-10-03 11:22:35 +01:00
Asim Aslam b5f33b2aaa Rename Dump to Sync 2019-10-03 09:56:25 +01:00
Asim Aslam a9c85eda68 Merge pull request #813 from micro/store
Move out consul sync/lock and store. Move data/store to store
2019-10-03 09:51:21 +01:00
Asim Aslam b5ca40a91a Move out consul sync/lock and store. Move data/store to store 2019-10-03 09:46:20 +01:00
Asim Aslam b81bb07afc Merge pull request #812 from micro/gossip
Remove gossip registry
2019-10-03 09:36:14 +01:00
Asim Aslam 8d2b12258f Remove gossip registry 2019-10-03 09:29:48 +01:00
Asim Aslam 31026da2a1 Update etcd.go
Use /micro/registry as the etcd key prefix
2019-10-02 20:33:59 +01:00
Asim Aslam 1129803bcb Merge pull request #810 from milosgajdos83/etcd
First commit to add etcd registry support
2019-10-02 20:27:38 +01:00
Milos Gajdos 25148af44c First commit to add etcd registry support 2019-10-02 18:56:53 +01:00
Asim Aslam 36675aff1e Merge pull request #809 from micro/log-prefix
Add ability to set log prefix
2019-10-02 17:47:27 +01:00
Asim Aslam b6db0d2663 Add ability to set log prefix 2019-10-02 17:42:34 +01:00
Asim Aslam 2370fb1209 Set gateway to node address rather than id 2019-10-02 15:52:31 +01:00
Asim Aslam 519e8a7213 Merge pull request #808 from micro/net-address
Hash the network address
2019-10-02 15:27:07 +01:00
Asim Aslam 308424488b Hash the network address 2019-10-02 15:22:44 +01:00
Asim Aslam 5d77ce9e9b Rename rcache file to cache 2019-10-02 12:35:20 +01:00
Asim Aslam 9eb6262168 Merge pull request #807 from unistack-org/fixup
some spelling fixes in memory and gossip registry
2019-10-02 10:47:59 +01:00
Vasiliy Tolstov b722798caa some spelling fixes in memory and gossip registry
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2019-10-02 03:54:04 +03:00
Asim Aslam 0cf7b70423 Merge pull request #806 from milosgajdos83/go-mod-shrink
Update go.mod
2019-10-01 20:13:26 +01:00
Milos Gajdos 03b8ceab5c Update go.mod 2019-10-01 19:33:23 +01:00
Asim Aslam e8a53610f1 Update go mod to use 1.13 2019-10-01 19:09:29 +01:00
Asim Aslam e48155118f Update go mod 2019-10-01 18:55:03 +01:00
potato f933457cc1 Merge pull request #5 from micro/master
pull request from go-micro
2019-09-30 17:22:51 +08:00
1200 changed files with 134124 additions and 35027 deletions
+31
View File
@@ -0,0 +1,31 @@
# EditorConfig for go-micro
# https://editorconfig.org
root = true
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
[*.go]
indent_style = tab
indent_size = 4
[*.{yml,yaml}]
indent_style = space
indent_size = 2
[*.{json,proto}]
indent_style = space
indent_size = 2
[*.md]
trim_trailing_whitespace = false
indent_style = space
indent_size = 2
[Makefile]
indent_style = tab
+2
View File
@@ -0,0 +1,2 @@
github: asim
custom: ["https://go-micro.dev/support"]
+51
View File
@@ -0,0 +1,51 @@
---
name: Bug report
about: Create a report to help us improve
title: '[BUG] '
labels: bug
assignees: ''
---
## Describe the bug
A clear and concise description of what the bug is.
## To Reproduce
Steps to reproduce the behavior:
1. Create service with '...'
2. Configure plugin '...'
3. Run command '...'
4. See error
## Expected behavior
A clear and concise description of what you expected to happen.
## Code sample
```go
// Minimal reproducible code
```
## Environment
- Go Micro version: [e.g. v5.3.0]
- Go version: [run `go version`]
- OS/Platform: [e.g. Ubuntu 22.04, macOS 14, Docker]
- Plugins/Integrations: [e.g. consul registry, nats broker, redis cache]
## Logs
```
Paste relevant logs here (use -v flag for verbose output)
```
## Checklist
- [ ] I've searched existing issues and this is not a duplicate
- [ ] I've provided a minimal code sample that reproduces the issue
- [ ] I've included my environment details
- [ ] I've checked the documentation
## Additional context
Add any other context about the problem here.
## Helpful Resources
- [Troubleshooting Guide](https://github.com/micro/go-micro/tree/master/internal/website/docs/getting-started.md)
- [Examples](https://github.com/micro/go-micro/tree/master/examples)
- [API Reference](https://pkg.go.dev/go-micro.dev/v5)
- [Discord Community](https://discord.gg/G8Gk5j3uXr)
@@ -0,0 +1,23 @@
---
name: Commercial Support / Consulting
about: Inquire about paid support, consulting, training, or a retainer
title: '[SUPPORT] '
labels: commercial-support
assignees: asim
---
## What are you building?
A short description of your project and how you're using (or planning to use) Go Micro.
## What do you need?
- [ ] Production support / retainer (priority fixes, direct line, response SLA)
- [ ] Consulting (integration, architecture, agent design)
- [ ] Training / onboarding for a team
- [ ] Sponsored feature or fix
- [ ] Not sure yet — let's talk
## Scale & timeline
Team size, where you're running it, and any timeline that matters.
## Anything else?
Links, context, constraints. For anything you'd rather keep private, become a [sponsor](https://github.com/sponsors/asim) and message directly.
+11
View File
@@ -0,0 +1,11 @@
blank_issues_enabled: true
contact_links:
- name: 🔒 Report a vulnerability
url: https://github.com/micro/go-micro/security/advisories/new
about: Privately disclose security vulnerabilities to the maintainers.
- name: 💖 Sponsor Go Micro
url: https://github.com/sponsors/asim
about: Fund ongoing development and see your name or logo on the project.
- name: 📖 Documentation
url: https://go-micro.dev/docs
about: Guides, examples, and the full reference.
+42
View File
@@ -0,0 +1,42 @@
---
name: Feature request
about: Suggest an idea for this project
title: '[FEATURE] '
labels: enhancement
assignees: ''
---
## Is your feature request related to a problem?
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
## Describe the solution you'd like
A clear and concise description of what you want to happen.
## Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
## Use case
Describe how this feature would be used in practice. What problem does it solve?
**Example:**
```go
// Show how the feature would be used
```
## Implementation ideas (optional)
If you have thoughts on how this could be implemented, share them here.
## Additional context
Add any other context, code examples, or screenshots about the feature request here.
## Checklist
- [ ] I've searched existing issues and this is not a duplicate
- [ ] I've checked the roadmap and this isn't already planned
- [ ] I've provided a clear use case
- [ ] I'd be willing to submit a PR for this feature (optional)
## Helpful Resources
- [Roadmap](https://github.com/micro/go-micro/blob/master/ROADMAP.md)
- [Contributing Guide](https://github.com/micro/go-micro/blob/master/CONTRIBUTING.md)
- [Architecture Docs](https://github.com/micro/go-micro/tree/master/internal/website/docs/architecture.md)
- [Discord Community](https://discord.gg/G8Gk5j3uXr)
+61
View File
@@ -0,0 +1,61 @@
---
name: Performance issue
about: Report a performance problem or regression
title: '[PERFORMANCE] '
labels: performance
assignees: ''
---
## Performance Issue
**Symptom:**
Describe the performance problem (e.g., high latency, memory leak, CPU usage)
**Expected Performance:**
What performance did you expect?
## Benchmarks
Please provide benchmarks or profiling data:
```bash
# CPU profiling
go test -cpuprofile=cpu.prof -bench=.
# Memory profiling
go test -memprofile=mem.prof -bench=.
# Results
```
**Before/After comparison (if applicable):**
- Before: X req/sec, Y ms latency
- After: X req/sec, Y ms latency
## Code Sample
```go
// Minimal code that demonstrates the performance issue
```
## Environment
- Go Micro version: [e.g. v5.3.0]
- Go version: [run `go version`]
- Hardware: [e.g. 4 CPU, 8GB RAM]
- OS: [e.g. Ubuntu 22.04]
- Load: [e.g. 1000 req/sec, 100 concurrent connections]
## Profiling Data
Attach pprof profiles if available:
- CPU profile
- Memory profile
- Goroutine dump
## Additional Context
Add any other context about the performance issue.
## Resources
- [Performance Guide](https://github.com/micro/go-micro/tree/master/internal/website/docs/performance.md)
- [Benchmarking](https://pkg.go.dev/testing#hdr-Benchmarks)
+31
View File
@@ -0,0 +1,31 @@
---
name: Question
about: Ask a question about using Go Micro
title: '[QUESTION] '
labels: question
assignees: ''
---
## Your question
A clear and concise question about Go Micro usage.
## What have you tried?
Describe what you've already attempted or researched.
## Code sample (if applicable)
```go
// Your code here
```
## Context
Provide any additional context that might help answer your question.
## Resources you've checked
- [ ] [Getting Started Guide](https://github.com/micro/go-micro/tree/master/internal/website/docs/getting-started.md)
- [ ] [Examples](https://github.com/micro/go-micro/tree/master/internal/website/docs/examples)
- [ ] [API Documentation](https://pkg.go.dev/go-micro.dev/v5)
- [ ] Searched existing issues
## Helpful links
- [Documentation](https://github.com/micro/go-micro/tree/master/internal/website/docs)
- [Plugins Guide](https://github.com/micro/go-micro/tree/master/internal/website/docs/plugins.md)
+32
View File
@@ -0,0 +1,32 @@
# North Star
The direction the loop aligns every increment to. Depth lives in
[`internal/docs/THESIS.md`](../../internal/docs/THESIS.md); this is the short,
operative version the planner and builder read each run.
## Mission
Make building an **agent** as easy as building a **service**, on one runtime.
Go Micro is a holistic agent harness and service framework encapsulating the
lifecycle of **services → agents → workflows** — pluggable, progressive, and
AI-native by default.
## Right now — developer adoption
The framework's depth is strong; the **on-ramp** is the gap. Weight the developer
experience — a walkable first-agent tutorial, discoverable examples, docs
wayfinding, install friction, debugging, the 0→1 and 0→hero path — **at least as
highly as internal hardening**. A developer succeeding on their first agent
matters more right now than another conformance/observability/interop increment.
Do not let the queue fill entirely with internal depth work.
## Guardrails
- One concern per PR; small and reversible.
- The gate is green CI (`go build`, `go test`, `golangci-lint`, `make harness`),
not human review — keep the suite strong; the loop is only as good as its evaluator.
- **Off-limits without a human** (surface as notes, never auto-merge): breaking
public-API changes, brand/positioning/marketing copy, new dependencies,
architectural rewrites, product-default changes with broad behavioral impact.
- Stay on `claude/*` / `codex/*` branches; base PRs on `master`. See
[`CODEX.md`](../../CODEX.md) and [`internal/docs/CONTINUOUS_IMPROVEMENT.md`](../../internal/docs/CONTINUOUS_IMPROVEMENT.md).
+28
View File
@@ -0,0 +1,28 @@
# Priorities
The ranked work queue for the autonomous improvement loop. The
**architecture-review** pass (the *architect*) owns this file: each run it turns
the [roadmap](../../ROADMAP.md) plus an internal scan (gaps in the
services → agents → workflows lifecycle, API coherence, drift, tech debt, test and
DX friction) into a single ordered list — highest-value first — and links each
item to a tracking issue. The hourly **continuous-improvement** pass works the
**top item whose issue is still open**. So the architect decides *what*, and the
increment loop *builds* it.
**Reading / editing.** An item is done when its linked issue closes (the increment
that builds it adds `Closes #<issue>`). Roadmap phase (Now → Next → Later) is the
primary ordering; internal findings are interleaved by value, not kept in a
separate list. The human can reorder this list — or the issues — at any time to
redirect the loop; direction always wins.
**Off-limits to the loop** (the architect proposes these as notes, never as queue
items the loop can auto-merge): brand/positioning copy, breaking public-API
changes, architectural rewrites. Those go to the human.
## Work queue (ranked)
1. **Stabilize AtlasCloud agent conformance marker retry** ([#4348](https://github.com/micro/go-micro/issues/4348)) — The durable-agent checkpoint issue has shipped, so the highest-value open Now-phase gap is the live provider conformance failure found in Harness (E2E): AtlasCloud completes the tool/delegate path but can omit the required conformance marker after retry. Fixing this protects the cross-provider promise behind first-agent trust without broad API or architecture change.
2. **Trace agent RunInfo in OpenTelemetry spans** ([#4315](https://github.com/micro/go-micro/issues/4315)) — After the live conformance regression is stable, the highest Next-phase operability gap is connecting existing run metadata to traces so real agent runs can be debugged across steps, tool calls, delegation, failures, services, and flows without inventing a new surface.
_Seeded by Claude Code from the roadmap + open issues; thereafter maintained by the
architecture-review pass._
+14
View File
@@ -0,0 +1,14 @@
<!--
The BUILDER prompt — go-micro's continuous-improvement increment. Editable
policy; the workflow prepends the agent @mention and substitutes __ISSUE__
before posting. Keep __ISSUE__ literal.
-->
Run one continuous-improvement increment per `internal/docs/CONTINUOUS_IMPROVEMENT.md`, aligned to the North Star in `.github/loop/NORTH_STAR.md` (the services → agents → workflows lifecycle, with developer adoption as the current goal).
PICK THE WORK FROM THE QUEUE: read `.github/loop/PRIORITIES.md` and take the highest-ranked item whose linked issue is still OPEN — that is your task, and its issue number is the one you close. If `PRIORITIES.md` is missing or every listed item's issue is already closed, fall back to the single highest-value roadmap / open-issue / improvement-radar item yourself.
Implement it, and VERIFY `go build ./...`, `go test ./...`, and `golangci-lint run ./...`.
Open the PR YOURSELF from the shell — do NOT use the make_pr tool (in this environment it only records metadata and never creates a PR). Create a uniquely-named branch under the `codex/` prefix: `git switch -c codex/increment-__ISSUE__`, then `git push -u origin codex/increment-__ISSUE__`, then `gh pr create --base master --label codex --title "<title>" --body "<body; include 'Closes #<the priority issue you built>' so it leaves the queue, and 'Closes #__ISSUE__' for this run's tracker>"`. Finally enable auto-merge so GitHub merges it once CI is green: `gh pr merge --squash --auto --delete-branch`.
One concern per PR. Stay out of breaking public API and brand/positioning copy — surface those as notes for the human instead.
+14
View File
@@ -0,0 +1,14 @@
<!--
The COHERENCE prompt — go-micro's DevRel pass (public-surface coherence +
CHANGELOG upkeep + changelog blog). Editable policy; the workflow prepends the
agent @mention and substitutes __ISSUE__ before posting. Keep __ISSUE__ literal.
-->
Act as DevRel for go-micro. Do these, in order.
COHERENCE AUDIT. Audit the public surface — `README.md`, `internal/website/` (landing `index.html` + `docs/`), and the blog under `internal/website/blog/` — for coherence with the North Star in `.github/loop/NORTH_STAR.md` (an agent harness and service framework; the services → agents → workflows lifecycle). Look for: places where README / website / docs contradict each other, are stale, or describe behavior that has since changed (cross-check against the code and recently merged PRs); whether the README is crisp and leads with the harness positioning; and one to three genuinely blog-worthy items from recently shipped work.
CHANGELOG UPKEEP (safe factual task — goes in the auto-merged PR). Keep `CHANGELOG.md` living, in Keep-a-Changelog format with newest content at the top under `## [Unreleased]`. Enumerate PRs merged to master since the last update (`gh pr list --state merged --base master --limit 60 --json number,title,mergedAt,labels`) and add a concise, user-facing entry for each genuine change not yet recorded under the right `### Added` / `### Changed` / `### Fixed` / `### Documentation` subheading — SKIP internal loop/CI/priorities-refresh churn. If a new `vX.Y.Z` tag was cut since the last run (`git fetch --tags --force`), rename `## [Unreleased]` to `## [X.Y.Z] - <Month YYYY>` and open a fresh empty `## [Unreleased]` above it. Do not invent entries.
CHANGELOG BLOG POST (blog voice — do NOT auto-merge). If, and only if, enough user-facing work has accumulated since the last changelog post to be worth reading (roughly a week's worth; not a near-empty post every day), draft a short "What's new in Go Micro" post as the next-numbered file in `internal/website/blog/`, mirroring the latest post's frontmatter and prev-nav, and add an entry at the top of `internal/website/blog/index.html`. Base it strictly on the CHANGELOG.
THEN: (A) post a findings report as a comment on this issue (#__ISSUE__) — what's aligned, what drifted, what you fixed, the CHANGELOG entries added, and whether you drafted a blog post (and why/why not). (B) Open ONE auto-merging PR for the SAFE factual work only — coherence/crispness fixes AND the CHANGELOG update (NOT brand/positioning rewrites, NOT the blog post): `git switch -c codex/coherence-__ISSUE__`, `git push -u origin codex/coherence-__ISSUE__`, `gh pr create --base master --label codex --title "<title>" --body "<summary, Closes #__ISSUE__>"`, then `gh pr merge --squash --auto --delete-branch`. (C) If you drafted a changelog blog post, open it as a SEPARATE PR (`codex/coherence-blog-__ISSUE__`, title prefixed `blog:`) and do NOT enable auto-merge — leave it for the human. Same for any brand/positioning copy. Do not use the make_pr tool.
+16
View File
@@ -0,0 +1,16 @@
<!--
The PLANNER prompt — go-micro's "architect / founder lens". Editable policy;
the workflow prepends the agent @mention and substitutes __ISSUE__ (this run's
tracking issue) before posting. Keep __ISSUE__ literal.
-->
Act as the architect — the founder lens — for go-micro, running continuously alongside the builders. Hold the whole picture: how the harness, the framework, and the developer UX fit together, what is in flight and what just merged, what to prioritize next, and what is missing or has drifted.
(1) TRACK STATE — scan recently merged PRs and open `codex` PRs/issues to see what shipped and what is being built right now, so the queue reflects reality (drop done items, don't re-queue in-flight work).
(2) ASSESS against the North Star in `.github/loop/NORTH_STAR.md` — lead with its Mission (*make building an agent as easy as building a service, on one runtime*) and re-derive alignment from the CANON: the blog under `internal/website/blog`, the `README`, and the website (read these, don't rely on the North Star alone), then `ROADMAP.md` (Now → Next → Later). Judge every priority against the mission: does it make the services → agents → workflows lifecycle simpler, more cohesive, and more operable? CURRENT GOAL — developer adoption: weight the on-ramp (walkable first-agent tutorial, discoverable examples, docs wayfinding, install friction, debugging, 0→1 and 0→hero) at least as highly as internal hardening; do not let the queue fill entirely with internal depth work. Look at coherence and seams across the core packages (agent, ai, flow, gateway/mcp, gateway/a2a, model, server, store, registry) and the dev inner loop (scaffold → run → chat → inspect → deploy). Flag drift in either direction: work drifting from the mission, or the North Star/website drifting from the lived story in the blog.
(3) MAINTAIN THE QUEUE in `.github/loop/PRIORITIES.md` — a SINGLE ordered list, highest-value first, each item linking a scoped, CI-verifiable issue (#N); roadmap phase is the primary ordering, internal findings (cohesion gaps, DX friction, missing pieces) interleaved by value. For any prioritized gap with no issue, file one: `gh issue create --label codex --label enhancement --title "<scoped task>" --body "<goal, scope, acceptance criteria>"`.
OUTPUT: post a concise assessment as a comment on this issue (#__ISSUE__) — what shipped, what's in flight, the top risks/gaps, and the reasoning behind the ranking. If the ranking actually changed, open ONE PR for `.github/loop/PRIORITIES.md`: `git switch -c codex/planner-__ISSUE__`, `git push -u origin codex/planner-__ISSUE__`, `gh pr create --base master --label codex --title "<title>" --body "<summary, Closes #__ISSUE__>"`, then `gh pr merge --squash --auto --delete-branch`. If the queue is already accurate, just close this issue (`gh issue close __ISSUE__`).
Do NOT make breaking public-API or architectural changes yourself — surface those in the assessment as notes for the human, never as auto-merged changes. Open the PR yourself from the shell with `gh`; do not use the make_pr tool (it is a no-op stub).
+30
View File
@@ -0,0 +1,30 @@
<!--
The SECURITY prompt — go-micro's security audit. Editable policy; the workflow
prepends the agent @mention and substitutes __ISSUE__ before posting. Keep
__ISSUE__ literal.
Deliberately conservative: it does NOT auto-merge fixes, and it does NOT publish
exploit details in public issues (responsible disclosure).
-->
Act as the security reviewer for go-micro. Audit for real, exploitable vulnerabilities — skip theoretical or lint-style noise.
GO-MICRO ATTACK SURFACE — weight these:
- **MCP gateway** (`gateway/mcp`) and **A2A gateway** (`gateway/a2a`) — untrusted input from agents/tools: auth/scope enforcement, injection into downstream RPC, SSRF via tool/agent URLs, rate-limit/circuit-breaker bypass, info leak in errors.
- **x402 payments** (`wrapper/x402`) — payment verification and settlement: signature/mandate validation, replay, budget-reservation races, facilitator auth (CDP bearer) handling, amount/network confusion.
- **Auth** (`auth/jwt`, `wrapper/auth`) — token validation, algorithm confusion, scope/priority rule bypass, missing checks on endpoints.
- **AI providers** (`ai/*`) — base-URL and endpoint handling: SSRF via config-controlled `BaseURL`, API keys leaking into logs/errors, TLS verification.
- **Agent tool loop** (`agent/`) — prompt injection reaching real tool calls, guardrail (`MaxSteps`/`LoopLimit`/`ApproveTool`) bypass, delegate/plan side effects.
- **Trust boundaries** — `server` RPC handlers, `broker` consumers, `store`/`registry` inputs, `transport` TLS defaults (v6 verifies by default — confirm nothing regressed).
- **The loop itself** — `.github/workflows/loop-*.yml`: the `CODEX_TRIGGER_TOKEN` PAT must never be echoed/leaked; workflow inputs must not enable script injection.
- **Dependencies** — run `govulncheck ./...` (install if needed) and inspect `go.mod` for known CVEs.
DEDUPE against open issues first.
HOW TO REPORT:
- **Known/public dependency CVEs**: file a `security` issue referencing the CVE + module; you MAY open a PR bumping to the patched version. Do NOT enable auto-merge.
- **Novel, exploitable vulnerabilities in this code** (not yet public): do NOT post an exploit or PoC in a public issue. File a CONCISE `security` + `needs-human` issue naming the class, location (file/function), and impact only — and note it should go through GitHub private vulnerability reporting. Do NOT open a public fix PR that reveals it.
- **Low-risk hardening**: a normal `security` issue is fine.
NEVER auto-merge a security change. Never weaken a control to make a test pass. Architectural/breaking fixes → `needs-human` with the tradeoff.
Post a summary as a comment on this issue (#__ISSUE__) — findings by severity, what you filed, what needs a human — then close it (`gh issue close __ISSUE__`). If you open a dependency-bump PR: `git switch -c loop/security-__ISSUE__`, `git push -u origin loop/security-__ISSUE__`, `gh pr create --base master --label codex --label security --title "<title>" --body "<summary, Closes #__ISSUE__>"` — then STOP, do NOT run `gh pr merge --auto`. Do not use the make_pr tool.
+14
View File
@@ -0,0 +1,14 @@
<!--
The TRIAGE prompt — go-micro's CI-failure feedback path. Editable policy; the
workflow prepends the agent @mention and substitutes __ISSUE__ (this tracking
issue) and __RUNURL__ (the failed run) before posting. Keep both literal.
-->
Triage the failed CI run at __RUNURL__. It may be the linter (Lint), the unit/integration tests (Run Tests), or the provider-conformance harness (Harness (E2E)).
Read the logs and root-cause each distinct failure. DEDUPE against open issues — if a failure matches an existing issue, comment "recurred" there instead of filing a duplicate.
For each genuine, self-contained defect, file a scoped issue (`gh issue create --label codex --label enhancement --title "<scoped fix>" --body "<root cause, where, acceptance criteria>"`) so the increment loop builds it and the next CI/harness run verifies it. A lint or test failure on master is a real regression — file it so it is fixed promptly; do NOT ignore it.
IGNORE only genuine transient flakes — live-model latency, provider outages, rate limits, network timeouts with no code cause (mostly relevant to the harness). Anything needing a breaking or architectural change: file it as `needs-human` and describe it, rather than auto-queuing it as a routine fix.
Close this issue (`gh issue close __ISSUE__`) when triage is done. Open any PR yourself from the shell with `gh`; do not use the make_pr tool.
+116
View File
@@ -0,0 +1,116 @@
name: Harness (E2E)
# Runs the end-to-end harnesses for agents, services, flows, and provider
# conformance. The default job uses deterministic mock LLMs and needs no
# secrets. A second job runs the same harnesses against the live provider set and
# skips providers whose secrets are absent, so scheduled conformance
# remains safe in no-key forks while still failing configured providers that drift.
on:
push:
branches: ["**"]
pull_request:
branches: ["**"]
schedule:
- cron: "17 * * * *" # hourly, so real-model conformance keeps pace with the dev/loop velocity
workflow_dispatch:
inputs:
providers:
description: "Comma-separated providers for live conformance (default: all supported)"
required: false
default: "anthropic,openai,gemini,groq,minimax,mistral,together,atlascloud"
harnesses:
description: "Comma-separated harnesses for live conformance"
required: false
default: "agent,universe,agent-flow,plan-delegate,a2a-stream-fallback"
require_configured:
description: "Fail selected live providers that do not have repository secrets"
required: false
type: boolean
default: false
jobs:
harness:
name: Harnesses (mock LLM)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: stable
cache: true
- name: Build
run: go build ./...
- name: 0→1 and 0→hero developer-flow harness
run: make harness
harness-live:
name: Provider harnesses (live LLM conformance)
runs-on: ubuntu-latest
# Only on the hourly schedule or a manual run — never automatically on
# every push/PR, so changes don't quietly burn API credits. Trigger it
# by hand (Actions → Harness → Run workflow) when changing the agent,
# flow, or AI internals and you want a real-model check.
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: stable
cache: true
- name: Provider conformance against live models
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
GROQ_API_KEY: ${{ secrets.GROQ_API_KEY }}
MINIMAX_API_KEY: ${{ secrets.MINIMAX_API_KEY }}
MISTRAL_API_KEY: ${{ secrets.MISTRAL_API_KEY }}
TOGETHER_API_KEY: ${{ secrets.TOGETHER_API_KEY }}
ATLASCLOUD_API_KEY: ${{ secrets.ATLASCLOUD_API_KEY }}
# Atlas Cloud's default chat model was failing the agent/tool-use
# conformance harnesses; run it against a stronger tool-use model.
# Override with an Actions variable ATLASCLOUD_MODEL if the exact
# catalog id differs (Atlas uses org/model ids).
ATLASCLOUD_MODEL: ${{ vars.ATLASCLOUD_MODEL || 'minimaxai/minimax-m3' }}
run: |
PROVIDERS="${{ github.event.inputs.providers || 'anthropic,openai,gemini,groq,minimax,mistral,together,atlascloud' }}"
HARNESSES="${{ github.event.inputs.harnesses || 'agent,universe,agent-flow,plan-delegate,a2a-stream-fallback' }}"
REQUIRE_CONFIGURED="${{ github.event.inputs.require_configured || 'false' }}"
args=(
-providers "$PROVIDERS"
-harnesses "$HARNESSES"
-summary-json provider-conformance-summary.json
-summary-markdown provider-conformance-summary.md
-capabilities-markdown provider-capabilities.md
)
if [ "$REQUIRE_CONFIGURED" = "true" ]; then
args+=( -require-configured )
fi
go run ./internal/harness/provider-conformance "${args[@]}"
- name: Publish provider conformance summary
if: always()
run: |
if [ -f provider-conformance-summary.md ]; then
cat provider-conformance-summary.md >> "$GITHUB_STEP_SUMMARY"
fi
if [ -f provider-capabilities.md ]; then
{
echo
echo "## Registered provider capabilities"
echo
cat provider-capabilities.md
} >> "$GITHUB_STEP_SUMMARY"
fi
- name: Upload provider conformance summary
if: always()
uses: actions/upload-artifact@v4
with:
name: provider-conformance
path: |
provider-conformance-summary.json
provider-conformance-summary.md
provider-capabilities.md
if-no-files-found: ignore
+30
View File
@@ -0,0 +1,30 @@
name: Lint
on:
push:
branches:
- "**"
pull_request:
types:
- opened
- reopened
- synchronize
branches:
- "**"
jobs:
golangci:
name: golangci-lint
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.24
check-latest: true
cache: true
- name: golangci-lint
uses: golangci/golangci-lint-action@v8
with:
version: v2.5.0
+60
View File
@@ -0,0 +1,60 @@
name: "Loop: Builder"
# Generated by `micro loop init`. A dispatch role of the autonomous loop: on a
# cadence it opens a fresh tracking issue and posts the instruction in
# .github/loop/prompts/builder.md to the agent (@codex).
#
# The workflow is the MECHANISM; that prompt file is the editable POLICY —
# change what this role does by editing the prompt, not this YAML. A FRESH
# issue per run is deliberate: agents derive the PR branch name from the
# triggering issue, so reusing one tracker collapses every run onto one branch.
#
# Gated on CODEX_TRIGGER_TOKEN: the agent ignores @mentions from the
# github-actions bot, so dispatch posts as a real user (a PAT). No token → no-op.
on:
workflow_dispatch: {}
schedule:
- cron: "29 * * * *"
permissions:
issues: write
concurrency:
group: loop-builder
cancel-in-progress: false
jobs:
dispatch:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4 # needed to read the prompt file
- name: Dispatch builder
env:
GH_TOKEN: ${{ secrets.CODEX_TRIGGER_TOKEN || github.token }}
HAS_TOKEN: ${{ secrets.CODEX_TRIGGER_TOKEN != '' }}
REPO: ${{ github.repository }}
RUN_NUMBER: ${{ github.run_number }}
run: |
if [ "$HAS_TOKEN" != "true" ]; then
echo "CODEX_TRIGGER_TOKEN is not set — skipping (the agent ignores bot @mentions)."
exit 0
fi
PROMPT=".github/loop/prompts/builder.md"
if [ ! -f "$PROMPT" ]; then
echo "missing $PROMPT — run 'micro loop init'." >&2
exit 1
fi
ISSUE_URL=$(gh issue create --repo "$REPO" \
--title "Loop: build increment #$RUN_NUMBER" \
--body "Autonomous builder pass. Direction: .github/loop/NORTH_STAR.md; queue: .github/loop/PRIORITIES.md.")
ISSUE_NUM="${ISSUE_URL##*/}"
echo "Opened issue #$ISSUE_NUM — dispatching builder."
# The prompt file is the policy; strip its editorial <!-- --> header and
# substitute the tracking issue number (__ISSUE__) at runtime.
{
echo "@codex"
echo
sed -e '/<!--/,/-->/d' -e "s/__ISSUE__/$ISSUE_NUM/g" "$PROMPT"
} > "$RUNNER_TEMP/loop-body.md"
gh issue comment "$ISSUE_NUM" --repo "$REPO" --body-file "$RUNNER_TEMP/loop-body.md"
+60
View File
@@ -0,0 +1,60 @@
name: "Loop: Coherence"
# Generated by `micro loop init`. A dispatch role of the autonomous loop: on a
# cadence it opens a fresh tracking issue and posts the instruction in
# .github/loop/prompts/coherence.md to the agent (@codex).
#
# The workflow is the MECHANISM; that prompt file is the editable POLICY —
# change what this role does by editing the prompt, not this YAML. A FRESH
# issue per run is deliberate: agents derive the PR branch name from the
# triggering issue, so reusing one tracker collapses every run onto one branch.
#
# Gated on CODEX_TRIGGER_TOKEN: the agent ignores @mentions from the
# github-actions bot, so dispatch posts as a real user (a PAT). No token → no-op.
on:
workflow_dispatch: {}
schedule:
- cron: "0 7 * * *"
permissions:
issues: write
concurrency:
group: loop-coherence
cancel-in-progress: false
jobs:
dispatch:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4 # needed to read the prompt file
- name: Dispatch coherence
env:
GH_TOKEN: ${{ secrets.CODEX_TRIGGER_TOKEN || github.token }}
HAS_TOKEN: ${{ secrets.CODEX_TRIGGER_TOKEN != '' }}
REPO: ${{ github.repository }}
RUN_NUMBER: ${{ github.run_number }}
run: |
if [ "$HAS_TOKEN" != "true" ]; then
echo "CODEX_TRIGGER_TOKEN is not set — skipping (the agent ignores bot @mentions)."
exit 0
fi
PROMPT=".github/loop/prompts/coherence.md"
if [ ! -f "$PROMPT" ]; then
echo "missing $PROMPT — run 'micro loop init'." >&2
exit 1
fi
ISSUE_URL=$(gh issue create --repo "$REPO" \
--title "Loop: coherence review #$RUN_NUMBER" \
--body "Autonomous coherence pass. Direction: .github/loop/NORTH_STAR.md; queue: .github/loop/PRIORITIES.md.")
ISSUE_NUM="${ISSUE_URL##*/}"
echo "Opened issue #$ISSUE_NUM — dispatching coherence."
# The prompt file is the policy; strip its editorial <!-- --> header and
# substitute the tracking issue number (__ISSUE__) at runtime.
{
echo "@codex"
echo
sed -e '/<!--/,/-->/d' -e "s/__ISSUE__/$ISSUE_NUM/g" "$PROMPT"
} > "$RUNNER_TEMP/loop-body.md"
gh issue comment "$ISSUE_NUM" --repo "$REPO" --body-file "$RUNNER_TEMP/loop-body.md"
+60
View File
@@ -0,0 +1,60 @@
name: "Loop: Planner"
# Generated by `micro loop init`. A dispatch role of the autonomous loop: on a
# cadence it opens a fresh tracking issue and posts the instruction in
# .github/loop/prompts/planner.md to the agent (@codex).
#
# The workflow is the MECHANISM; that prompt file is the editable POLICY —
# change what this role does by editing the prompt, not this YAML. A FRESH
# issue per run is deliberate: agents derive the PR branch name from the
# triggering issue, so reusing one tracker collapses every run onto one branch.
#
# Gated on CODEX_TRIGGER_TOKEN: the agent ignores @mentions from the
# github-actions bot, so dispatch posts as a real user (a PAT). No token → no-op.
on:
workflow_dispatch: {}
schedule:
- cron: "59 * * * *"
permissions:
issues: write
concurrency:
group: loop-planner
cancel-in-progress: false
jobs:
dispatch:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4 # needed to read the prompt file
- name: Dispatch planner
env:
GH_TOKEN: ${{ secrets.CODEX_TRIGGER_TOKEN || github.token }}
HAS_TOKEN: ${{ secrets.CODEX_TRIGGER_TOKEN != '' }}
REPO: ${{ github.repository }}
RUN_NUMBER: ${{ github.run_number }}
run: |
if [ "$HAS_TOKEN" != "true" ]; then
echo "CODEX_TRIGGER_TOKEN is not set — skipping (the agent ignores bot @mentions)."
exit 0
fi
PROMPT=".github/loop/prompts/planner.md"
if [ ! -f "$PROMPT" ]; then
echo "missing $PROMPT — run 'micro loop init'." >&2
exit 1
fi
ISSUE_URL=$(gh issue create --repo "$REPO" \
--title "Loop: planning review #$RUN_NUMBER" \
--body "Autonomous planner pass. Direction: .github/loop/NORTH_STAR.md; queue: .github/loop/PRIORITIES.md.")
ISSUE_NUM="${ISSUE_URL##*/}"
echo "Opened issue #$ISSUE_NUM — dispatching planner."
# The prompt file is the policy; strip its editorial <!-- --> header and
# substitute the tracking issue number (__ISSUE__) at runtime.
{
echo "@codex"
echo
sed -e '/<!--/,/-->/d' -e "s/__ISSUE__/$ISSUE_NUM/g" "$PROMPT"
} > "$RUNNER_TEMP/loop-body.md"
gh issue comment "$ISSUE_NUM" --repo "$REPO" --body-file "$RUNNER_TEMP/loop-body.md"
+76
View File
@@ -0,0 +1,76 @@
name: "Loop: Release"
# Generated by `micro loop init`. Cuts the next PATCH tag
# (vMAJOR.MINOR.PATCH+1) when the default branch has new commits
# since the latest such tag, and pushes it with a PAT (CODEX_TRIGGER_TOKEN) so any
# tag-triggered release workflow fires. Minor/major bumps stay with a human.
#
# The tag MUST be pushed with a PAT, not the default GITHUB_TOKEN: a tag pushed
# by GITHUB_TOKEN does not trigger other workflows (Actions blocks that recursion).
on:
workflow_dispatch: {}
schedule:
- cron: "0 23 * * *"
permissions:
contents: read
concurrency:
group: loop-release
cancel-in-progress: false
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # need full history + all tags
# Do NOT persist the default GITHUB_TOKEN as a git credential: it would
# be sent on the PAT push below and override it, so the tag push would
# authenticate as github-actions[bot] and 403. Letting the PAT in the
# push URL be the only credential is the whole point.
persist-credentials: false
- name: Cut the next patch tag if there are new commits
env:
RELEASE_TOKEN: ${{ secrets.CODEX_TRIGGER_TOKEN }}
REPO: ${{ github.repository }}
run: |
if [ -z "$RELEASE_TOKEN" ]; then
echo "CODEX_TRIGGER_TOKEN is not set — skipping."
exit 0
fi
git fetch --tags --force
LATEST=$(git tag --list 'v*.*.*' --sort=-v:refname | head -1)
if [ -z "$LATEST" ]; then
echo "no vMAJOR.MINOR.PATCH tag found — aborting so nothing weird gets tagged."
exit 1
fi
echo "latest tag: $LATEST"
COUNT=$(git rev-list --count "$LATEST"..HEAD)
echo "commits since $LATEST: $COUNT"
if [ "$COUNT" -eq 0 ]; then
echo "no new commits since $LATEST — no release."
exit 0
fi
ver="${LATEST#v}"
major="${ver%%.*}"
rest="${ver#*.}"
minor="${rest%%.*}"
patch="${rest#*.}"
case "$major.$minor.$patch" in
[0-9]*.[0-9]*.[0-9]*) ;;
*) echo "unexpected tag shape: $LATEST" ; exit 1 ;;
esac
NEXT="v${major}.${minor}.$((patch + 1))"
echo "cutting: $NEXT ($COUNT commits since $LATEST)"
git config user.name "loop release bot"
git config user.email "noreply@users.noreply.github.com"
git tag -a "$NEXT" -m "Release $NEXT — automated patch ($COUNT commits since $LATEST)"
git push "https://x-access-token:${RELEASE_TOKEN}@github.com/${REPO}.git" "$NEXT"
echo "Pushed $NEXT."
+60
View File
@@ -0,0 +1,60 @@
name: "Loop: Security"
# Generated by `micro loop init`. A dispatch role of the autonomous loop: on a
# cadence it opens a fresh tracking issue and posts the instruction in
# .github/loop/prompts/security.md to the agent (@codex).
#
# The workflow is the MECHANISM; that prompt file is the editable POLICY —
# change what this role does by editing the prompt, not this YAML. A FRESH
# issue per run is deliberate: agents derive the PR branch name from the
# triggering issue, so reusing one tracker collapses every run onto one branch.
#
# Gated on CODEX_TRIGGER_TOKEN: the agent ignores @mentions from the
# github-actions bot, so dispatch posts as a real user (a PAT). No token → no-op.
on:
workflow_dispatch: {}
schedule:
- cron: "0 6 * * 1"
permissions:
issues: write
concurrency:
group: loop-security
cancel-in-progress: false
jobs:
dispatch:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4 # needed to read the prompt file
- name: Dispatch security
env:
GH_TOKEN: ${{ secrets.CODEX_TRIGGER_TOKEN || github.token }}
HAS_TOKEN: ${{ secrets.CODEX_TRIGGER_TOKEN != '' }}
REPO: ${{ github.repository }}
RUN_NUMBER: ${{ github.run_number }}
run: |
if [ "$HAS_TOKEN" != "true" ]; then
echo "CODEX_TRIGGER_TOKEN is not set — skipping (the agent ignores bot @mentions)."
exit 0
fi
PROMPT=".github/loop/prompts/security.md"
if [ ! -f "$PROMPT" ]; then
echo "missing $PROMPT — run 'micro loop init'." >&2
exit 1
fi
ISSUE_URL=$(gh issue create --repo "$REPO" \
--title "Loop: security review #$RUN_NUMBER" \
--body "Autonomous security pass. Direction: .github/loop/NORTH_STAR.md; queue: .github/loop/PRIORITIES.md.")
ISSUE_NUM="${ISSUE_URL##*/}"
echo "Opened issue #$ISSUE_NUM — dispatching security."
# The prompt file is the policy; strip its editorial <!-- --> header and
# substitute the tracking issue number (__ISSUE__) at runtime.
{
echo "@codex"
echo
sed -e '/<!--/,/-->/d' -e "s/__ISSUE__/$ISSUE_NUM/g" "$PROMPT"
} > "$RUNNER_TEMP/loop-body.md"
gh issue comment "$ISSUE_NUM" --repo "$REPO" --body-file "$RUNNER_TEMP/loop-body.md"
+57
View File
@@ -0,0 +1,57 @@
name: "Loop: Triage"
# Generated by `micro loop init`. The feedback path of the evaluator: when a CI
# workflow (Harness (E2E), Lint, Run Tests) fails on a non-PR run, dispatch the agent
# (@codex) with the instruction in .github/loop/prompts/triage.md
# to root-cause the failure and file scoped fix issues back into the queue — so
# failures become fixes with no human in the middle. Gated on CODEX_TRIGGER_TOKEN.
on:
workflow_run:
workflows: ["Harness (E2E)", "Lint", "Run Tests"]
types: [completed]
permissions:
issues: write
concurrency:
group: loop-triage
cancel-in-progress: false
jobs:
triage:
# Only real failures on branch pushes/schedules — not PR-run failures, which
# the PR author already sees.
if: ${{ github.event.workflow_run.conclusion == 'failure' && github.event.workflow_run.event != 'pull_request' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4 # needed to read the prompt file
- name: Dispatch triage
env:
GH_TOKEN: ${{ secrets.CODEX_TRIGGER_TOKEN || github.token }}
HAS_TOKEN: ${{ secrets.CODEX_TRIGGER_TOKEN != '' }}
REPO: ${{ github.repository }}
RUN_ID: ${{ github.event.workflow_run.id }}
RUN_URL: ${{ github.event.workflow_run.html_url }}
WORKFLOW_NAME: ${{ github.event.workflow_run.name }}
run: |
if [ "$HAS_TOKEN" != "true" ]; then
echo "CODEX_TRIGGER_TOKEN is not set — skipping."
exit 0
fi
PROMPT=".github/loop/prompts/triage.md"
if [ ! -f "$PROMPT" ]; then
echo "missing $PROMPT — run 'micro loop init'." >&2
exit 1
fi
ISSUE_URL=$(gh issue create --repo "$REPO" \
--title "Loop: triage failed run $RUN_ID ($WORKFLOW_NAME)" \
--body "The '$WORKFLOW_NAME' workflow failed on a non-PR run: $RUN_URL")
ISSUE_NUM="${ISSUE_URL##*/}"
echo "Opened issue #$ISSUE_NUM — dispatching triage."
{
echo "@codex"
echo
sed -e '/<!--/,/-->/d' -e "s/__ISSUE__/$ISSUE_NUM/g" -e "s#__RUNURL__#$RUN_URL#g" "$PROMPT"
} > "$RUNNER_TEMP/loop-body.md"
gh issue comment "$ISSUE_NUM" --repo "$REPO" --body-file "$RUNNER_TEMP/loop-body.md"
+51
View File
@@ -0,0 +1,51 @@
name: goreleaser
on:
push:
tags:
- 'v*.*.*'
permissions:
contents: write
id-token: write
packages: write
attestations: write
jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
-
name: Set up Go
uses: actions/setup-go@v5
with:
go-version: stable
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
-
name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v7
with:
distribution: goreleaser
version: '~> v2'
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+75
View File
@@ -0,0 +1,75 @@
name: Run Tests
on:
push:
branches:
- "**"
pull_request:
types:
- opened
- reopened
- synchronize
branches:
- "**"
jobs:
unittests:
name: Unit Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.24
check-latest: true
cache: true
- name: Get dependencies
run: |
go install github.com/kyoh86/richgo@latest
go get -v -t -d ./...
- name: Run tests
id: tests
run: richgo test -v -race -cover ./...
env:
IN_TRAVIS_CI: yes
RICHGO_FORCE_COLOR: 1
etcd-integration:
name: Etcd Integration Tests
runs-on: ubuntu-latest
permissions:
contents: read
services:
etcd:
image: quay.io/coreos/etcd:v3.5.2
env:
ETCD_LISTEN_CLIENT_URLS: http://0.0.0.0:2379
ETCD_ADVERTISE_CLIENT_URLS: http://0.0.0.0:2379
ports:
- 2379:2379
options: >-
--health-cmd "etcdctl endpoint health"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.24
check-latest: true
cache: true
- name: Get dependencies
run: |
go install github.com/kyoh86/richgo@latest
go get -v -t -d ./...
- name: Wait for etcd
run: |
timeout 30 bash -c 'until curl -s http://localhost:2379/health; do sleep 1; done'
- name: Run etcd integration tests
run: richgo test -v -race ./registry/etcd/...
env:
ETCD_ADDRESS: localhost:2379
IN_TRAVIS_CI: yes
RICHGO_FORCE_COLOR: 1
+51
View File
@@ -0,0 +1,51 @@
# Sample workflow for building and deploying a Jekyll site to GitHub Pages
name: Deploy Jekyll with GitHub Pages dependencies preinstalled
on:
# Runs on pushes targeting the default branch
push:
branches: ["master"]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
# Build job
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Build with Jekyll
uses: actions/jekyll-build-pages@v1
with:
source: ./internal/website
destination: ./_site
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
# Deployment job
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
+35 -1
View File
@@ -1,6 +1,10 @@
# Develop tools
/.vscode/
/.idea/
/.trunk
# VS Code workspace files (keep settings for consistency)
/.vscode/*
!/.vscode/settings.json
# Binaries for programs and plugins
*.exe
@@ -29,8 +33,38 @@ _cgo_export.*
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
coverage.html
# vim temp files
*~
*.swp
*.swo
# go work files
go.work
go.work.sum
# Build artifacts
dist/
bin/
# Example binaries (go build in examples/)
examples/**/server/server
examples/**/client/client
examples/mcp/documented/documented
examples/mcp/hello/hello
# IDE-specific files
.DS_Store
/micro
# Built example/harness binaries (go build ./path/... drops these at repo root)
/plan-delegate
/agent-plan-delegate
/micro-mcp-gateway
/agent-ollama
# Local Jekyll / Bundler artifacts
internal/website/.bundle/
internal/website/_site/
internal/website/.jekyll-cache/
+63
View File
@@ -0,0 +1,63 @@
version: "2"
run:
timeout: 5m
tests: true
linters:
# Start from the standard set (errcheck, govet, ineffassign, staticcheck,
# unused) and add a few low-noise, high-value linters on top.
default: standard
enable:
- bodyclose
- misspell
- unconvert
- usestdlibvars
settings:
errcheck:
exclude-functions:
- (*encoding/json.Encoder).Encode
- (net/http.ResponseWriter).Write
- fmt.Fprintf
- fmt.Fprint
- fmt.Fprintln
misspell:
locale: US
staticcheck:
checks:
- all
# Deprecations are tracked separately; some (e.g. gRPC dial options)
# are kept intentionally for compatibility. Migrate them on their own.
- -SA1019
# Initialism/naming convention (Id->ID, Http->HTTP, ...). The remaining
# offenders are exported identifiers (e.g. web.Id, web.DefaultId) whose
# rename is a breaking API change; not worth it in a lint-bootstrap pass.
- -ST1003
exclusions:
# Use golangci-lint's built-in sensible exclusions and skip generated code.
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
rules:
# The protobuf code generator is a port of upstream protoc-gen-go and
# keeps its structure; don't flag its unused legacy helpers.
- path: cmd/protoc-gen-micro/generator/
linters:
- unused
# Tests are held to a looser standard.
- path: _test\.go
linters:
- bodyclose
- errcheck
# Demo/harness code: fire-and-forget calls are fine and `_ =` noise hurts
# readability of examples.
- path: (^|/)(examples|internal/harness)/
linters:
- errcheck
formatters:
enable:
- gofmt
+136
View File
@@ -0,0 +1,136 @@
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
version: 2
before:
hooks:
- go mod tidy
builds:
- main: ./cmd/micro
id: micro
binary: micro
env:
- CGO_ENABLED=0
- >-
{{- if eq .Os "darwin" }}
{{- if eq .Arch "amd64"}}CC=o64-clang{{- end }}
{{- if eq .Arch "arm64"}}CC=aarch64-apple-darwin20.2-clang{{- end }}
{{- end }}
{{- if eq .Os "windows" }}
{{- if eq .Arch "amd64" }}CC=x86_64-w64-mingw32-gcc{{- end }}
{{- end }}
goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm
- arm64
goarm:
- 7
ignore:
- goos: windows
goarch: arm
- main: ./cmd/protoc-gen-micro
id: protoc-gen-micro
binary: protoc-gen-micro
env:
- CGO_ENABLED=0
- >-
{{- if eq .Os "darwin" }}
{{- if eq .Arch "amd64"}}CC=o64-clang{{- end }}
{{- if eq .Arch "arm64"}}CC=aarch64-apple-darwin20.2-clang{{- end }}
{{- end }}
{{- if eq .Os "windows" }}
{{- if eq .Arch "amd64" }}CC=x86_64-w64-mingw32-gcc{{- end }}
{{- end }}
goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm
- arm64
goarm:
- 7
ignore:
- goos: windows
goarch: arm
archives:
- id: micro
ids:
- micro
formats: [tar.gz]
name_template: >-
{{ .Binary }}_
{{- .Os }}_
{{- .Arch }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
files:
- none*
format_overrides:
- goos: windows
formats: [zip]
- id: protoc-gen-micro
ids:
- protoc-gen-micro
formats: [tar.gz]
name_template: >-
{{ .Binary }}_
{{- .Os }}_
{{- .Arch }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
files:
- none*
format_overrides:
- goos: windows
formats: [zip]
report_sizes: true
changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
dockers_v2:
-
ids:
- micro
- protoc-gen-micro
images:
- "micro/micro"
- "ghcr.io/micro/go-micro"
tags:
- "v{{ .Version }}"
- "{{ if .IsNightly }}nightly{{ end }}"
- "{{ if not .IsNightly }}latest{{ end }}"
labels:
"io.artifacthub.package.readme-url": "https://raw.githubusercontent.com/micro/go-micro/refs/heads/master/README.md"
"io.artifacthub.package.logo-url": "https://www.gravatar.com/avatar/09d1da3ea9ee61753219a19016d6a672?s=120&r=g&d=404"
"org.opencontainers.image.description": "A Go Platform built for Developers"
"org.opencontainers.image.created": "{{.Date}}"
"org.opencontainers.image.title": "{{.ProjectName}}"
"org.opencontainers.image.revision": "{{.FullCommit}}"
"org.opencontainers.image.version": "{{.Version}}"
"org.opencontainers.image.source": "{{.GitURL}}"
"org.opencontainers.image.url": "{{.GitURL}}"
"org.opencontainers.image.licenses": "MIT"
platforms:
- linux/amd64
- linux/arm64
retry:
attempts: 5
delay: 5s
max_delay: 2m
-11
View File
@@ -1,11 +0,0 @@
language: go
go:
- 1.13.x
env:
- GO111MODULE=on
notifications:
slack:
secure: aEvhLbhujaGaKSrOokiG3//PaVHTIrc3fBpoRbCRqfZpyq6WREoapJJhF+tIpWWOwaC9GmChbD6aHo/jMUgwKXVyPSaNjiEL87YzUUpL8B2zslNp1rgfTg/LrzthOx3Q1TYwpaAl3to0fuHUVFX4yMeC2vuThq7WSXgMMxFCtbc=
cache:
directories:
- $GOPATH/pkg/mod
+137
View File
@@ -0,0 +1,137 @@
{
"folders": [
{
"path": "."
}
],
"settings": {
"go.toolsManagement.autoUpdate": true,
"go.useLanguageServer": true,
"go.lintOnSave": "workspace",
"go.lintTool": "golangci-lint",
"go.lintFlags": [
"--fast"
],
"go.formatTool": "goimports",
"go.formatFlags": [],
"go.buildOnSave": "workspace",
"go.testOnSave": false,
"go.coverOnSave": false,
"go.testFlags": ["-v", "-race"],
"go.testTimeout": "60s",
"go.gopath": "",
"go.goroot": "",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
},
"files.exclude": {
"**/.git": true,
"**/.DS_Store": true,
"**/node_modules": true,
"**/*.test": true,
"**/coverage.out": true,
"**/coverage.html": true
},
"files.watcherExclude": {
"**/.git/objects/**": true,
"**/.git/subtree-cache/**": true,
"**/node_modules/**": true,
"**/.vscode/**": true
},
"search.exclude": {
"**/node_modules": true,
"**/bower_components": true,
"**/*.code-search": true,
"**/vendor": true,
"**/.git": true
},
"[go]": {
"editor.tabSize": 4,
"editor.insertSpaces": false,
"editor.formatOnSave": true,
"editor.defaultFormatter": "golang.go"
},
"[go.mod]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "golang.go"
},
"[markdown]": {
"editor.formatOnSave": false,
"editor.wordWrap": "on"
},
"gopls": {
"ui.semanticTokens": true,
"ui.completion.usePlaceholders": true,
"formatting.gofumpt": false,
"analyses": {
"unusedparams": true,
"shadow": true,
"fieldalignment": false
}
}
},
"extensions": {
"recommendations": [
"golang.go",
"editorconfig.editorconfig",
"redhat.vscode-yaml",
"ms-vscode.makefile-tools"
]
},
"tasks": {
"version": "2.0.0",
"tasks": [
{
"label": "Run Tests",
"type": "shell",
"command": "make test",
"group": {
"kind": "test",
"isDefault": true
},
"presentation": {
"reveal": "always",
"panel": "new"
}
},
{
"label": "Run Tests with Coverage",
"type": "shell",
"command": "make test-coverage",
"group": "test"
},
{
"label": "Run Linter",
"type": "shell",
"command": "make lint",
"group": "build"
},
{
"label": "Format Code",
"type": "shell",
"command": "make fmt",
"group": "build"
}
]
},
"launch": {
"version": "0.2.0",
"configurations": [
{
"name": "Debug Current File",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${file}"
},
{
"name": "Debug Test",
"type": "go",
"request": "launch",
"mode": "test",
"program": "${workspaceFolder}"
}
]
}
}
+39
View File
@@ -0,0 +1,39 @@
# Repository agent instructions
These instructions apply to the entire repository.
## Pull requests from Codex tasks
When a Codex task makes repository changes and the requested outcome is a PR:
1. Keep the change focused on the assigned issue or prompt.
2. Run the relevant verification commands and capture their results
(`go build ./...`, `go test ./...`, `golangci-lint run ./...`).
3. Check `git status --short` and review the diff before finishing.
4. Create a uniquely-named branch under the `codex/` prefix (do not work on
`master`, and do not use a generic name like `work`):
```sh
git switch -c codex/<issue-number>-<short-slug>
```
5. Stage the intended files and commit on that branch.
6. Open the pull request yourself with the GitHub CLI, which is installed in the
environment and whose `origin` points at this repository, then enable
auto-merge so GitHub merges it once the required CI checks pass:
```sh
git push -u origin HEAD
gh pr create --base master --label codex \
--title "<concise title>" \
--body "<summary of the change and testing, including 'Closes #<issue>'>"
gh pr merge --squash --auto --delete-branch
```
The branch should start with `codex/` and the PR should carry the `codex`
label. Auto-merge waits for the required status checks (build, tests,
golangci-lint) — never merge a PR manually before CI is green.
Do not just say that a PR was opened, and do **not** rely on the `make_pr` tool:
in this environment `make_pr` only records the title/body and never pushes a
branch or creates a PR. The task is not complete until `gh pr create` has opened
a real pull request and printed its URL.
+291
View File
@@ -0,0 +1,291 @@
# Changelog
All notable changes to Go Micro are documented here.
Format follows [Keep a Changelog](https://keepachangelog.com/) and versions
follow [Semantic Versioning](https://semver.org/), matching the git tags and
[GitHub releases](https://github.com/micro/go-micro/releases) (`v6.MINOR.PATCH`).
Patch releases are cut automatically as the loop merges improvements; the
`[Unreleased]` section below is kept current between tags and rolled into the
next version when it ships.
> Earlier `2026.0x` headings are historical calendar-style markers from before
> v6 tagging; they are kept for continuity and not reused.
---
## [Unreleased]
### Added
- **Provider HTTP retry signals** — provider failures now preserve HTTP status and `Retry-After` details so retry classification and backoff can respond to rate limits and unavailable providers. (`ai/`)
### Fixed
- **Stream fallback memory** — unsupported streaming attempts no longer leave stale duplicate user turns before fallback paths continue with non-streaming agent calls. (`agent/`)
- **Function-style text tool calls** — agent fallback parsing now recognizes provider replies that render tools as function-style calls, including nested JSON arguments. (`agent/`)
- **Plan/delegate notify recovery** — plan-delegate recovery now waits for recovered notify side effects and routes retries through the communications agent that owns the notification. (`internal/harness/`)
### Documentation
- **First-agent docs wayfinding guard** — the local harness now includes a focused no-network check for first-agent and 0→hero docs links. (`Makefile`, `internal/harness/`)
---
## [6.3.18] - July 2026
### Added
- **StreamAsk close cancellation** — agent streaming calls now cancel promptly when their runner closes, avoiding orphaned stream work. (`agent/`)
- **Agent resume pending helper** — agent durability now has a focused helper for resuming pending checkpointed runs. (`agent/`)
- **Agent tool retry tracing** — agent traces now include tool retry attempts for easier debugging of retry/fallback behavior. (`agent/`)
- **Shared-broker universe harness** — the universe harness now runs against the shared broker path, improving coverage of the same runtime wiring used by services, agents, and workflows. (`internal/harness/`)
### Fixed
- **Plan/delegate retry idempotency** — agent retries now preserve side-effect and notification dedupe across conformance retry paths, including completion and owner-notification edge cases. (`agent/`, `internal/harness/`)
- **AtlasCloud text tool calls** — AtlasCloud fallback handling now recovers more text-rendered tool calls from OpenAI-compatible responses. (`ai/atlascloud/`, `agent/`)
- **OpenAI-compatible text tool calls** — OpenAI-compatible providers now recover text-rendered tool calls more reliably. (`agent/`)
- **AtlasCloud multi-step follow-ups** — AtlasCloud tool fallback handling now continues multi-step tool follow-up paths more reliably. (`ai/atlascloud/`, `agent/`)
### Documentation
- **Agent debugging quickcheck** — docs now include a focused quickcheck path for first-agent debugging. (`internal/website/docs/`)
- **Website first-agent examples map** — website docs now link the maintained examples wayfinding map for the first-agent route. (`internal/website/docs/`)
- **Examples wayfinding index** — examples docs now provide a central map for first-agent, support, and interop examples. (`examples/`, `internal/website/docs/`)
---
## [6.3.17] - July 2026
### Added
- **First-agent examples CLI wayfinding** — `micro examples` now prints the maintained provider-free first-agent examples in copy/paste order. (`cmd/micro/`)
- **0→hero CLI entrypoint** — `micro zero-to-hero` now points developers at the maintained no-secret services → agents → workflows harness and runnable examples. (`cmd/micro/`)
- **First-agent tutorial smoke harness** — the first-agent tutorial path now has smoke coverage to keep the no-secret on-ramp runnable. (`internal/harness/`)
- **No-secret agent debugging smoke** — the no-secret agent debugging path now has smoke coverage for the first-agent troubleshooting flow. (`internal/harness/`)
- **Durable checkpoint resume smoke coverage** — durable agent resume after checkpointing now has focused smoke coverage. (`agent/`, `internal/harness/`)
### Fixed
- **Plan/delegate notify replays** — duplicate and replayed plan-delegate notifications are now idempotent, so resumed runs do not duplicate completed notifications. (`agent/`, `internal/harness/`)
- **Provider conformance scheduling** — provider conformance workflow dispatches now guard their scheduling path more reliably. (`.github/workflows/`)
- **Plan/delegate notification completion** — delegated notifications now preserve plan completion state more reliably, including duplicate, paraphrased, and delegated-owner notification paths. (`agent/`, `internal/harness/`)
- **AtlasCloud tool fallback** — AtlasCloud built-in tool schemas and follow-up tool fallback handling now recover conformance delegate retries more reliably. (`ai/atlascloud/`, `agent/`)
- **Agent conformance retry completion** — conformance retry prompts and completion handling are more deterministic for delegated agent runs. (`agent/`, `internal/harness/`)
### Documentation
- **First-agent quickstart numbering** — the first-agent on-ramp numbering is consistent across the README and website docs. (`README.md`, `internal/website/docs/`)
- **First-agent inspect command** — docs now use the maintained `micro inspect agent <name>` form. (`README.md`, `internal/website/docs/`)
- **`micro loop` quickstart wayfinding** — docs now surface the loop quickstart from the public docs index and README wayfinding. (`README.md`, `internal/website/docs/`)
---
## [6.3.16] - July 2026
### Added
- **No-secret agent demo CLI** — the CLI now surfaces `micro agent demo`, making the provider-free first-agent path discoverable from the installed binary. (`cmd/micro/`)
- **First-agent recovery doctor** — first-agent recovery checks now help diagnose install, scaffold, and provider setup issues before the live agent run. (`cmd/micro/`, `internal/website/docs/guides/`)
### Changed
- **Architecture lifecycle docs** — the architecture guide now leads with the services → agents → workflows lifecycle and the first-agent on-ramp. (`internal/website/docs/architecture.md`)
- **First-agent on-ramp** — README and website docs now lead new users through install troubleshooting, no-secret demos, the smallest first-agent example, debugging, and the 0→hero reference path in the same order. (`README.md`, `internal/website/docs/`)
### Fixed
- **Config close idempotency** — config close paths now tolerate repeated closes safely. (`config/`)
- **OpenTelemetry child span events** — agent traces now preserve child span events more reliably. (`agent/`)
### Documentation
- **Security reporting** — security docs now route vulnerability reports through GitHub Security Advisories. (`SECURITY.md`, `internal/website/docs/`)
- **Install troubleshooting** — the first-agent on-ramp now includes clearer install and PATH recovery guidance. (`internal/website/docs/guides/install-troubleshooting.md`)
---
## [6.3.15] - July 2026
### Added
- **Anthropic streaming** — the Anthropic provider now supports Messages SSE streaming and is registered as a streaming-capable provider, with capability docs and parser coverage. (`ai/anthropic/`, `internal/website/docs/guides/`)
- **AP2 mandate foundation for A2A** — the A2A gateway now has the shared payment-mandate foundation needed for AP2-style agent payment flows. (`gateway/a2a/`)
- **Smallest first-agent example** — a no-secret, mock-model first-agent example gives the on-ramp a minimal runnable starting point. (`examples/first-agent/`)
### Changed
- **First-agent CLI next steps** — CLI output now points new users toward the maintained first-agent path after scaffold/run milestones. (`cmd/micro/`)
### Fixed
- **Plan/delegate completion** — plan-delegate runs now preserve completed steps, guard ordering, require notify-before-completion, and stabilize checkpoint continuation paths. (`agent/`, `internal/harness/`)
- **Provider text tool calls** — AtlasCloud and weaker-model fallback paths now recover tagged, `Create`-suffixed, mixed text/tool-call, and follow-up tool calls more reliably. (`agent/`, `ai/atlascloud/`)
- **First-agent broker isolation** — the first-agent harness now isolates broker state more reliably across runs. (`internal/harness/`)
### Documentation
- **First-agent example path** — docs and website wayfinding now surface the smallest example, no-secret transcript, and 0→hero path together. (`README.md`, `internal/website/docs/`)
- **Agent operations guidance** — agent debugging docs now include operational failure guidance, inspect hints, and durable resume pointers. (`internal/website/docs/guides/`)
---
## [6.3.14] - July 2026
### Added
- **MiniMax provider** — run agents against MiniMax's `MiniMax-M3` model via its OpenAI-compatible endpoint, with tool calling and streaming; auto-detected from the base URL. (`ai/minimax/`)
- **`micro loop` security role** — a new opt-in loop role (`--roles …,security`) that periodically audits a repo for vulnerabilities and files `security` issues. It is deliberately conservative: it never auto-merges fixes and never publishes exploit detail in public issues (responsible disclosure), and risky fixes are marked `needs-human`. go-micro now runs it against its own attack surface (MCP/A2A gateways, x402, auth, provider URLs, agent tool loop, deps). (`cmd/micro/loop/`)
- **Agent run tracing** — agent model streaming and run-event kinds now emit richer trace detail for debugging agent execution. (`agent/`)
### Changed
- **Agent memory** — streamed agent replies are persisted in conversation memory so later turns can reference streamed responses. (`agent/`)
### Fixed
- **Plan/delegate completion** — agents now continue unfinished plan steps more reliably, fail checkpointed runs that leave delegated plans unfinished, recover from unknown plan-delegate tool calls, avoid duplicate side effects, and complete timeout paths deterministically. (`agent/`)
- **AtlasCloud tool calls** — streaming and request fallback handling now recovers tool-call results from provider responses that omit the expected structured fields. (`ai/atlascloud/`)
- **Agent preflight diagnostics** — provider setup failures now surface more actionable errors before an agent run starts. (`agent/`)
- **A2A fallback streams** — fallback stream validation is stricter for malformed or incomplete A2A streaming responses. (`gateway/a2a/`)
- **File-store test isolation** — file-store expiry and table tests are less timing-sensitive and isolate their state more reliably. (`store/file/`)
### Documentation
- **First-agent debugging path** — docs now include no-secret transcript checkpoints, durable resume examples, and clearer CLI/website wayfinding for first-agent debugging. (`README.md`, `internal/website/docs/`, `examples/agent-durable/`)
---
## [6.3.13] - July 2026
### Added
- **`micro loop`** — scaffold an autonomous improvement loop into any repository: GitHub Actions workflows dispatched to an @mention-driven coding agent, across up to five roles — `planner` (ranked queue), `builder` (top item as a single-concern PR, auto-merged on green CI), `triage` (CI failures → fix issues), and opt-in `coherence` (docs/CHANGELOG alignment) and `release` (daily patch tag). Each dispatch role's instruction lives in an editable `.github/loop/prompts/<role>.md` file — the workflow is the mechanism, the prompt is the policy — so a repo customizes behavior without forking the CLI. `micro loop init --roles …` writes it all; `micro loop verify` checks the wiring. This is the loop that maintains go-micro itself, generalized. (`cmd/micro/loop/`)
### Changed
- **x402 payments** — settlement now covers CDP facilitator authentication and conformance edge cases. (`wrapper/x402/`)
### Fixed
- **Plan/delegate harnessing** — side effects and notifications are now idempotent and deterministic across duplicate, alias, order-scoped, and reachability scenarios. (`agent/`, `internal/harness/`)
### Documentation
- **First-agent on-ramp** — quickstart docs now connect the no-secret first-agent transcript, example map, and 0→hero path. (`README.md`, `internal/website/docs/`)
- **Ollama provider docs** — the provider surface, capability matrix, and examples now document local and cloud behavior. (`internal/website/docs/`, `examples/agent-ollama/`)
---
## [6.3.12] - July 2026
### Added
- **Ollama provider** — run agents against open-weight models locally (`/api/chat`, NDJSON streaming) or via Ollama Cloud (OpenAI-compatible `/v1/chat/completions`, SSE), auto-detected from the base URL, with tool calling in both modes. Point any agent at a non-default endpoint with the new `agent.BaseURL` / `micro.AgentBaseURL` option. (`ai/ollama/`, `examples/agent-ollama/`)
- **Retrieval-backed agent memory** — agents can recall relevant prior turns by similarity, not just the recent window, with a summarizer hook that compacts older history so long conversations stay in budget. (`agent/`)
- **Scheduled flows** — a flow can run an agent (or any step) on a cron-style schedule, with the dispatch traced end to end. (`flow/`)
- **Flow verification/grader loop** — a workflow can grade its own step output against a rubric and retry until it passes, plus run-trace analysis to surface where a flow spends its time. (`flow/`)
- **A2A streaming & continuity** — outbound agent streaming flows through the A2A binding (`message/stream`), with `tasks/resubscribe` and `input-required` handoffs for multi-turn interop. (`gateway/a2a/`)
### Changed
- **Agent tool-call resilience** — opt-in retries around agent tool calls, and a fallback that executes tool calls emitted as text by weaker models so they still make progress. (`agent/`)
- **Hardened agent durability** — terminal failure statuses are classified and surfaced, and durable resume-after-restart is covered by tests. (`agent/`)
### Documentation
- **"Your first agent" walkthrough** and a canonical 0-to-hero reference path, lowering the on-ramp from install to a running agent. (`internal/website/docs/`)
- **Discord** linked prominently across the README, website nav/footer, and docs. (`https://discord.gg/G8Gk5j3uXr`)
---
## [6.0.0] - June 2026
The AI-native major release. Breaking changes are listed first; everything
else is additive. See the [v5 → v6 migration guide](internal/website/docs/guides/migration/v5-to-v6.md) — it's a small upgrade.
### Changed (breaking)
- **Module path is now `go-micro.dev/v6`.** Update imports (`go-micro.dev/v5/...``go-micro.dev/v6/...`) and `go install go-micro.dev/v6/cmd/micro@v6`.
- **TLS verification is on by default.** v5 skipped verification unless `MICRO_TLS_SECURE=true`; v6 verifies by default. `MICRO_TLS_SECURE` is removed — set `MICRO_TLS_INSECURE=true` (or call `tls.InsecureConfig()`) for self-signed/dev certs.
- **`micro.NewService(name, opts...)` is the service constructor**, symmetric with `NewAgent`/`NewFlow`. `micro.New(name, opts...)` remains as a deprecated alias; the old name-less `micro.NewService(opts...)` form is removed (pass the name positionally). Generators emit the new form.
- **JWT auth ported in-module.** The external `github.com/micro/plugins/v5/auth/jwt` (pinned to v5) is replaced by `go-micro.dev/v6/auth/jwt/token`, now on the maintained `golang-jwt/jwt/v5`; the deprecated `dgrijalva/jwt-go` dependency is dropped.
### Added
- **A2A protocol — both directions** — `gateway/a2a` exposes registered agents over the open Agent2Agent (A2A) protocol so agents on other frameworks can discover and call them: Agent Cards are generated from registry metadata (the same way the MCP gateway derives tools), and incoming tasks are translated to the agent's existing `Agent.Chat` RPC, with no per-agent code (`micro a2a serve`). The outbound `a2a.Client` calls external A2A agents by URL, wired into `flow.A2A(url)` (a workflow step) and `delegate` to an `http(s)` URL (from inside an agent). An agent can also serve A2A **directly** without a gateway via `AgentA2A(addr)` (`a2a.NewAgentHandler`), handling tasks in-process. The JSON-RPC binding includes `message/send`, `message/stream` (SSE), `tasks/get`, multi-turn continuation by `taskId`/`contextId`, best-effort push notification callbacks, `tasks/resubscribe`, `input-required` handoffs, and card discovery. (`gateway/a2a/`, `cmd/micro/a2a/`)
- **Agents (`micro.NewAgent`)** — an agent is a service with an LLM inside: it discovers its assigned services as tools, runs the model's tool loop, registers a `Chat` RPC endpoint, and is reachable like any service. `Ask` for programmatic use; `micro chat` discovers and routes to agents; `micro agent list`/`describe`. (`agent/`)
- **Plan & delegate** — two built-in agent tools added to every agent: `plan` (an ordered, store-persisted plan surfaced back in the prompt) and `delegate` (hand a self-contained subtask to a registered agent over RPC, otherwise to an ephemeral sub-agent). No harness or graph — they're plain tools. (`agent/builtin.go`, `examples/agent-plan-delegate/`)
- **Agent guardrails** — `MaxSteps` (stop on count), `LoopLimit` (stop repeated no-progress calls; on by default), and `ApproveTool` (human-in-the-loop / policy gate before each action), enforced at the one point every tool call passes through. (`agent/`, guide + blog)
- **Pluggable agent memory & custom tools** — durable store-backed conversation memory by default, swappable via `AgentMemory`; register any function as a tool with `AgentTool`.
- **Workflows (`micro.NewFlow`)** — event-driven orchestration that maps to Anthropic's workflow/agent split: an event triggers a deterministic step (or ordered durable steps), or dispatches to an agent with `FlowAgent`. (`flow/`)
- **Flow loops (`FlowLoop`)** — a flow step that runs a body step repeatedly, carrying state across passes, until a stop condition is met or a hard iteration cap is hit. Stop on a code-defined predicate (`FlowUntil`) or let the model judge it done (`FlowUntilLLM` — the supervised "Ralph" loop); `FlowLoopMax` is the guardrail that guarantees termination, and `FlowOnIteration` reports progress. (`flow/loop.go`, `examples/flow-loop/`, guide)
- **x402 payments** — opt-in per-call payments for tools via the x402 standard, with a pluggable facilitator and a consumer-side client + budget; the MCP gateway can advertise and require payment per tool. (`wrapper/x402/`, guide + blog)
- **Scoped store state** — `store.Scope(s, database, table)` returns a store handle that confines every operation to a database/table without mutating the shared store (unlike `Init(Table(...))`, which is process-global and races between co-located components). Services, agents, and flows now each keep their state in their own table (`service/{name}`, `agent/{name}`, `flow/{name}`); the service path replaces the old `Init(store.Table(name))` global mutation with a scoped handle.
- **Flow discovery & history CLI** — running flows now register in the registry as `type=flow` (and deregister on `Stop`), so they're discoverable like agents: `micro flow list` shows running flows, `micro flow runs <name>` shows a flow's durable run history from the store, and `micro agent history <name>` shows an agent's stored conversation. Live state comes from the registry; durable history from the scoped store.
- **Durable workflows** — a flow can now be an ordered list of steps (a task with stages) that is checkpointed before and after each step, so a run survives a crash and resumes where it stopped without re-running completed steps. State carries a typed payload plus a `Stage` marker; flow-level `Retry` with a per-step override; runs retained for audit unless `DeleteOnSuccess`. Step actions: `Call` (RPC), `LLM` (model turn), `Dispatch` (to an agent), or any `StepFunc`. Durability is a pluggable `Checkpoint` (store-backed by default; implement the interface for Temporal/Restate). Runnable example: `examples/flow-durable/`. Blog: "Durable Workflows" (`internal/website/blog/24.md`).
- **Agent tool-execution wrappers** — `AgentWrapTool` registers middleware around an agent's tool calls, the tool-side analogue of `client.CallWrapper`/`server.HandlerWrapper`. Use it for logging, metrics, retries, or policy; wrappers compose outermost-first and run outside the built-in guardrails. Includes a runnable example with observe + retry wrappers (`examples/agent-wrap-tool/`).
- **Agent platform showcase** — full platform example (Users, Posts, Comments, Mail) mirroring [micro/blog](https://github.com/micro/blog), demonstrating how existing microservices become agent-accessible with zero code changes (`examples/mcp/platform/`).
- **Blog post: "Your Microservices Are Already an AI Platform"** — walkthrough of agent-service interaction patterns using real-world services (`internal/website/blog/7.md`).
- **Circuit breakers for MCP gateway** — per-tool circuit breakers protect downstream services from cascading failures. Configurable max failures, open-state timeout, and half-open probing. Available via `Options.CircuitBreaker` and `--circuit-breaker` CLI flag (`gateway/mcp/circuitbreaker.go`).
- **Helm chart for MCP gateway** — official Helm chart at `deploy/helm/mcp-gateway/` with Deployment, Service, ServiceAccount, HPA, and Ingress templates. Supports Consul/etcd/mDNS registries, JWT auth, rate limiting, audit logging, per-tool scopes, TLS ingress, and auto-scaling.
- **MCP gateway benchmarks** — comprehensive benchmark suite for tool listing, lookup, auth, rate limiting, and JSON serialization (`gateway/mcp/benchmark_test.go`)
- **Workflow example** — cross-service orchestration demo with Inventory, Orders, and Notifications services showing agents chaining multi-step workflows from natural language (`examples/mcp/workflow/`)
- **Docker Compose deployment** — production-like setup with Consul registry, standalone MCP gateway, and Jaeger tracing in one `docker-compose up` (`examples/deployment/`)
---
## [2026.03] - March 2026
### Added
#### Developer Experience
- **`micro new` MCP templates** — `micro new myservice` generates MCP-enabled services with doc comments, `@example` tags, and `WithMCP()` wired in. Use `--no-mcp` to opt out.
- **`micro.NewService("name")` unified API** — single way to create services: `micro.NewService("greeter")` or `micro.NewService("greeter", micro.Address(":8080"))`. Replaces `micro.NewService()` + `service.New()` dual API.
- **`service.Handle()` simplified registration** — register handlers with `service.Handle(new(Greeter))` instead of manual `server.NewHandler` + `server.Handle`.
- **`micro.NewGroup()` modular monoliths** — run multiple services in one binary with shared lifecycle: `micro.NewGroup(users, orders).Run()`.
- **`mcp.WithMCP()` one-liner** — add MCP to any service with a single option: `micro.NewService("name", mcp.WithMCP(":3001"))`.
- **CRUD example** — contact book service with 6 operations, rich agent docs, and validation patterns (`examples/mcp/crud/`).
#### MCP Gateway
- **WebSocket transport** — bidirectional JSON-RPC 2.0 streaming over WebSocket for real-time agent communication (`gateway/mcp/websocket.go`).
- **OpenTelemetry integration** — full span instrumentation across HTTP, stdio, and WebSocket transports with W3C trace context propagation (`gateway/mcp/otel.go`).
- **Standalone gateway binary** — `micro-mcp-gateway` with Docker support for running the MCP gateway independently of services.
- **Per-tool auth scopes** — service-level (`server.WithEndpointScopes()`) and gateway-level (`Options.Scopes`) scope enforcement with bearer token auth.
- **Rate limiting** — per-tool token bucket rate limiting (`Options.RateLimit`).
- **Audit logging** — immutable audit records per tool call with trace ID, account, scopes, duration, and errors (`Options.AuditFunc`).
#### AI Model Package
- **`model.Model` interface** — unified AI provider abstraction with `Generate()` and `Stream()` methods.
- **Anthropic Claude provider** — `model/anthropic` with tool execution and auto-calling.
- **OpenAI GPT provider** — `model/openai` with provider auto-detection from base URL.
#### Agent SDKs
- **LangChain SDK** — `contrib/langchain-go-micro/` Python package with auto-discovery, tool generation, and multi-agent workflow examples.
- **LlamaIndex SDK** — `contrib/go-micro-llamaindex/` Python package with RAG integration examples.
#### Documentation
- **AI-native services guide** — building services for AI agents from scratch
- **MCP security guide** — auth, scopes, and audit logging
- **Tool descriptions guide** — writing doc comments that improve agent performance
- **Agent patterns guide** — architecture patterns for agent integration
- **Error handling guide** — writing agent-friendly error responses with typed errors
- **Troubleshooting guide** — common MCP issues and solutions
- **Migration guide** — add MCP to existing services in 5 minutes
#### CLI
- **`micro mcp serve`** — start MCP server (stdio for Claude Code, HTTP for web agents)
- **`micro mcp list`** — list available tools (human-readable or JSON)
- **`micro mcp test`** — test tools with JSON input
- **`micro mcp docs`** — generate tool documentation
- **`micro mcp export`** — export to LangChain, OpenAPI, or JSON formats
#### Agent Playground
- **Chat-focused UI** — redesigned playground with collapsible tool calls, real-time status, and thinking indicators
- **Provider settings** — configurable OpenAI/Anthropic provider, model, and API key
### Changed
- Service interface moved to `service.Service` with `micro.Service` as a type alias for backward compatibility.
- `service.New()` returns `service.Service` interface (was `*ServiceImpl`).
- `service.NewGroup()` accepts `service.Service` interface (was `*ServiceImpl`).
- `go.mod` template in `micro new` updated to Go 1.22.
### Fixed
- Handler `Handle()` method accepts variadic `server.HandlerOption` for scopes and metadata.
- Store initialization uses service name as table automatically.
- Service `Stop()` properly aggregates errors from lifecycle hooks.
---
## [2026.02] - February 2026
### Added
- **MCP gateway library** — `gateway/mcp/` with HTTP/SSE and stdio transports, service discovery, tool generation, and JSON schema generation from Go types (2,500+ lines).
- **CLI integration** — `micro run --mcp-address` flag to start MCP alongside services.
- **Documentation extraction** — auto-extract tool descriptions from Go doc comments with `@example` tag and struct tag parsing.
- **Blog post** — "Making Microservices AI-Native with MCP"
- **MCP examples** — `examples/mcp/hello/` and `examples/mcp/documented/`
---
## [2026.01] - January 2026
### Added
- **`micro deploy`** — deploy services to any Linux server via SSH + systemd with `micro deploy user@server`.
- **`micro build`** — build Go binaries and Docker images with `micro build --docker`.
- **Blog post** — "Introducing micro deploy"
---
_For earlier changes, see the [git log](https://github.com/micro/go-micro/commits/master)._
+158
View File
@@ -0,0 +1,158 @@
# CLAUDE.md - Go Micro Project Guide
## Project Overview
Go Micro is a framework for distributed systems development in Go. It provides pluggable abstractions for service discovery, RPC, pub/sub, config, auth, storage, and more.
The framework is evolving into an **AI-native platform** where every microservice is automatically accessible to AI agents via the Model Context Protocol (MCP).
## Build & Test
```bash
# Run all tests
make test
# Run tests for a specific package
go test ./gateway/mcp/...
go test ./ai/...
go test ./model/...
# Lint
make lint
# Format
make fmt
# Build CLI
go build -o micro ./cmd/micro
# Run locally with hot reload
micro run
```
## Project Structure
```
go-micro/
├── agent/ # Agent abstraction (intelligent service management)
├── ai/ # AI model providers (Anthropic, OpenAI, Gemini, etc.)
├── auth/ # Authentication (JWT, no-op)
├── broker/ # Message broker (NATS, RabbitMQ)
├── cache/ # Caching (Redis)
├── client/ # RPC client (gRPC)
├── cmd/micro/ # CLI tool (run, deploy, mcp, build, server)
├── codec/ # Message codecs (JSON, Proto)
├── config/ # Dynamic config (env, file, etcd, NATS)
├── errors/ # Error handling
├── events/ # Event system (NATS JetStream)
├── flow/ # Event-driven LLM orchestration
├── gateway/
│ ├── api/ # REST API gateway
│ └── mcp/ # MCP gateway (core AI integration)
│ └── deploy/ # Helm charts for MCP gateway
├── health/ # Health checking
├── logger/ # Logging
├── metadata/ # Context metadata
├── model/ # Typed data models (CRUD, queries, schemas)
├── registry/ # Service discovery (mDNS, Consul, etcd)
├── selector/ # Client-side load balancing
├── server/ # RPC server
├── service/ # Service interface + profiles
├── store/ # Data persistence (Postgres, NATS KV)
├── transport/ # Network transport
├── wrapper/ # Middleware (auth, trace, metrics)
├── examples/ # Working examples
└── internal/ # Non-public: docs, utils, test harness
```
## Key Architectural Decisions
- **Plugin architecture**: All abstractions use Go interfaces. Defaults work out of the box, everything is swappable.
- **Progressive complexity**: Zero-config for development, full control for production.
- **AI-native by default**: Every service is automatically an MCP tool. No extra code needed.
- **In-repo plugins**: Plugins live in the main repo to avoid version compatibility issues.
- **Reflection-based registration**: Handlers are registered via reflection for minimal boilerplate.
## Code Conventions
- Standard Go conventions (gofmt, golint)
- Functional options pattern for configuration (`WithX()` functions)
- Interface-first design: define the interface, then implement
- Tests alongside code (not in separate test directories)
- Commit messages: imperative mood, concise summary line
## Current Focus & Priorities (March 2026)
### Status
- **Q1 2026 (MCP Foundation):** COMPLETE
- **Q2 2026 (Agent DX):** COMPLETE (100%)
- **Q3 2026 (Production):** 50% complete (ahead of schedule)
### Priority 1: Agent Showcase & Examples
Build compelling demos showing agents interacting with go-micro services in realistic scenarios.
### Priority 2: Additional Protocol Support
- gRPC reflection-based MCP
- HTTP/3 support
### Priority 3: Kubernetes & Deployment
- Helm Charts for MCP gateway
- Kubernetes Operator with CRDs
### Recently Completed
- **Agent Plan & Delegate** - Two built-in agent tools: `plan` (ordered plan persisted to store-backed memory, surfaced in the prompt) and `delegate` (hand a subtask to another agent — RPC to a registered agent, else an ephemeral sub-agent with isolated context). Added automatically to every agent; no harness or graph. (`agent/builtin.go`, `examples/agent-plan-delegate/`)
- **`micro new` MCP Templates** - Scaffolds MCP-enabled services with doc comments, `@example` tags, `WithMCP()`. `--no-mcp` to opt out.
- **CRUD Example** - Contact book service with 6 operations, rich agent docs (`examples/mcp/crud/`)
- **Migration Guide** - "Add MCP to Existing Services" guide with 3 approaches
- **Troubleshooting Guide** - Common MCP issues and solutions
- **Error Handling Guide** - Patterns for agent-friendly error responses
- **Documentation Guides** - Six guides: AI-native services, MCP security, tool descriptions, agent patterns, error handling, troubleshooting
- **WithMCP Option** - One-line MCP setup (`gateway/mcp/option.go`)
- **Agent Playground Redesign** - Chat-focused UI with collapsible tool calls
- **Standalone Gateway Binary** - `micro-mcp-gateway` with Docker support
- **WebSocket Transport** - Bidirectional JSON-RPC 2.0 streaming (`gateway/mcp/websocket.go`)
- **OpenTelemetry Integration** - Full span instrumentation with W3C trace context (`gateway/mcp/otel.go`)
- **LlamaIndex SDK** - Python package with RAG examples (`contrib/go-micro-llamaindex/`)
## Key Files
| Purpose | File |
|---------|------|
| MCP Gateway | `gateway/mcp/mcp.go` |
| MCP Docs | `gateway/mcp/DOCUMENTATION.md` |
| AI Interface | `ai/model.go` |
| Model Layer | `model/model.go` |
| CLI Entry | `cmd/micro/main.go` |
| MCP CLI | `cmd/micro/mcp/` |
| Server (run/server) | `cmd/micro/server/server.go` |
| Roadmap | `ROADMAP.md` (full: `internal/website/docs/roadmap.md`) |
| Status | `CHANGELOG.md` |
| Changelog | `CHANGELOG.md` |
| Docs Site | `internal/website/docs/` |
## Roadmap & Status Documents
- **[ROADMAP.md](ROADMAP.md)** - the single, current roadmap (agentic development + DX). Full version at `internal/website/docs/roadmap.md`.
- **[CHANGELOG.md](CHANGELOG.md)** - what shipped and when (the source of truth for status).
- **[internal/docs/IMPLEMENTATION_SUMMARY.md](internal/docs/IMPLEMENTATION_SUMMARY.md)** - Implementation notes
- **[CHANGELOG.md](CHANGELOG.md)** - What changed and when
## Coordination with Codex
Go Micro is maintained by two AI tools — **Claude Code** (you) and **Codex** (its playbook is [CODEX.md](CODEX.md)) — plus the human maintainer, who routes work and owns every merge. To work side by side without collisions:
- **Lanes / branches.** You work on `claude/*` branches; Codex on `codex/*`. Never push to Codex's branch, and never have both agents committing the same branch at once.
- **Base PRs on `master`; don't stack on Codex's in-flight branch.** If that base squash-merges, your commit gets orphaned (this happened — the #3007 fixes had to be re-landed). If the code you need isn't merged yet, wait for it, then branch off `master`. To improve an *open* Codex PR, fix it in place (once Codex is done with the branch, or via an `@codex` comment on the PR) rather than a separate stacked PR.
- **One concern per PR.** Single-purpose PRs; don't bundle (e.g.) a feature with a docs change.
- **Cross-review.** Review Codex's PRs before merge — mechanical fixes you can land yourself (based on `master`), but design/scope/positioning calls go to the human; don't silently rewrite Codex's intent. Codex reviews yours via `@codex review`.
- **Dispatching Codex.** Start a task by commenting `@codex <instruction>` on an issue/PR (that issue/PR is its context). `@codex review` is reserved for review; any other instruction starts a *task*. It's consequential (spends a Codex task slot, pushes commits) and **serial** (one task at a time) — so dispatch one task at a time, only on the human's go-ahead, and never write a literal `@codex` in a comment unless you intend to trigger it (write "Codex" in prose otherwise).
- **CI is the gate.** `go build`, `go test`, `golangci-lint` (blocking), and `make harness` must pass before merge. `internal/harness/` and `examples/` are excluded from errcheck; everything else gets the full set.
- **Backlog = GitHub issues**, each a scoped, self-contained brief with acceptance criteria.
## Contributing
See [CONTRIBUTING.md](CONTRIBUTING.md) for full guidelines. Key points:
- Open an issue before large changes
- Include tests for new features
- Run `make test` and `make lint` before submitting
- Follow commit message format: `type: description` (e.g., `feat: add WebSocket transport`)
+197
View File
@@ -0,0 +1,197 @@
# Codex Maintainer Playbook
Go Micro has six months of Codex access through OpenAI's Codex for Open Source
program. Use it to increase maintainer throughput without changing the project's
bar for review, tests, or design taste.
## Operating principles
1. **Humans set direction; Codex accelerates execution.** Maintainers choose the
issue, constraints, and acceptance criteria. Codex drafts, investigates, and
verifies.
2. **Small, reviewable changes win.** Prefer focused PRs that can be understood
in one sitting over large speculative rewrites.
3. **Keep the contract green.** Every Codex-assisted change should preserve the
CLI-first getting-started flow, the harnesses, `make test`, and `make lint`.
4. **Document while coding.** If behavior changes, ask Codex to update examples,
guides, and release notes in the same branch.
5. **No blind merges.** Codex output is treated like any contributor output:
reviewed by a maintainer, backed by tests, and checked for public API impact.
## Coordination with Claude Code
Go Micro is maintained by two AI tools — **Codex** (you) and **Claude Code** (its guide is [CLAUDE.md](CLAUDE.md)) — plus the human maintainer, who routes work and owns every merge.
- **Lanes / branches.** You work on `codex/*` branches; Claude Code on `claude/*`. Never push to a branch the other owns, and never have both agents on one branch at once.
- **Base PRs on `master`.** Don't stack a PR on another agent's in-flight branch — if that base squash-merges, your changes can be orphaned. If the code you need isn't merged yet, wait, then branch off `master`. To improve a PR that hasn't merged, push to that PR's branch rather than opening a separate stacked PR — keep the change one mergeable unit.
- **One concern per PR.** Keep each PR single-purpose so a reviewer can read it in one sitting; don't bundle unrelated changes (e.g. a feature plus a docs rebrand).
- **Cross-review before merge.** Claude Code reviews your PRs; you review its with `@codex review`. A fresh pass from the other model catches what the author misses.
- **Dispatch.** Maintainers (or Claude Code) start your tasks with `@codex <instruction>` on the relevant issue/PR — that's your context. `@codex review` is review; any other instruction is a *task*. You run one task at a time: take the current one to a clean, green PR before the next is dispatched.
- **CI is the gate.** `go build`, `go test`, `golangci-lint` (blocking), and `make harness` must pass; never merge red. `internal/harness/` and `examples/` are excluded from errcheck; everything else gets the full set.
- **Backlog = GitHub issues**, each a scoped brief with acceptance criteria.
## Best uses
### 1. PR review and triage
- Summarize a PR: changed surface area, public API impact, tests added or missing.
- Ask for targeted review passes: concurrency, cancellation, security, backwards
compatibility, docs drift, and examples.
- Convert review findings into small patch suggestions or issue comments.
### 2. Issue reproduction
- Turn bug reports into failing tests or runnable reproduction scripts.
- Minimize flakes by isolating registry, broker, store, transport, and AI-provider
dependencies behind deterministic fakes where possible.
- Attach the exact command that reproduces the failure to the issue.
### 3. Release support
- Draft changelog entries from merged commits, grouped by feature, fix, docs, and
compatibility notes.
- Check that `README.md`, `ROADMAP.md`, website docs, examples, and `CHANGELOG.md`
agree before tagging.
- Run dry-run release commands and summarize blockers.
### 4. Docs and examples
- Keep the 0→1 path current: scaffold, run, call, chat, inspect.
- Keep the 0→hero example current: a realistic multi-agent system that exercises
agents, services, flows, MCP, A2A, and observability.
- Add runnable examples for new primitives before adding broad prose.
### 5. Hardening backlog
Use Codex to break roadmap items into small PRs, especially:
- cross-provider conformance scenarios for all supported AI providers;
- timeout, cancellation, retry, and rate-limit behavior;
- durable agent loops on top of the existing checkpoint model;
- streaming across `ai.Stream` and A2A;
- agent run metadata mapped to OpenTelemetry spans.
## Suggested weekly loop
1. Pick one maintenance lane: reviews, bugs, release prep, docs, or hardening.
2. Ask Codex for a branch-sized plan with acceptance criteria and test commands.
3. Have Codex implement the smallest valuable slice.
4. Run the relevant checks locally and in CI.
5. Review the diff as maintainer-owned code, then merge or send it back.
6. Record any recurring prompt, check, or failure mode in this playbook.
## First two weeks
Do not start with a giant feature. Start by making Codex pay rent on maintenance
work that is already on the roadmap and easy to review.
### Day 1: set up the review loop
1. Pick three recent PRs or commits: one feature, one bug fix, and one docs-only
change.
2. Ask Codex to review each using the PR review template below.
3. Compare Codex findings with maintainer judgment. Keep the checks that found
real issues; delete the noisy ones.
4. Turn the final review prompt into a saved project note or issue comment
template.
Success means Codex can produce a useful first-pass review in under ten minutes
without blocking a maintainer on false positives.
### Days 2-3: make bugs reproducible
1. Pick one open bug or flaky area.
2. Ask Codex for a failing test only. Do not allow a fix in the first pass.
3. Review the test for whether it captures the real contract.
4. In a second branch, ask Codex to fix the failure with the smallest patch.
Success means every accepted bug fix starts with a regression test or deterministic
harness case.
### Days 4-5: audit the getting-started contract
Run through the 0→1 path from a clean checkout and ask Codex to patch only the
first broken or confusing step. The target is not new prose; it is a runnable
path that works exactly as documented.
Candidate checks:
```sh
make test
make harness
make lint
go run ./examples/hello-world
go run ./internal/harness/universe
```
### Week 2: choose one roadmap slice
Pick one hardening item and break it into PRs that each land independently. The
best first slice is usually test infrastructure, not product code.
Recommended order:
1. **Provider conformance skeleton**: define one deterministic agent scenario and
gate real-provider runs on credentials.
2. **Cancellation audit**: trace `context.Context` propagation through one package
at a time.
3. **Docs drift audit**: compare `README.md`, `ROADMAP.md`, website docs, and
examples for one shipped feature.
4. **Release checklist dry run**: have Codex build a release-blocker list from the
diff since the previous tag.
## Standing task queue
Keep Codex busy on tasks with clear acceptance criteria:
| Priority | Task | Acceptance criteria |
| --- | --- | --- |
| P0 | PR first-pass review | Summary, risks, required changes, and exact verification commands. |
| P0 | Bug reproduction | A failing test or harness case committed before the fix. |
| P0 | 0→1 docs check | Fresh-checkout commands work as written or a patch fixes the first break. |
| P1 | Cross-provider conformance | One scenario runs against fakes by default and real providers when keys exist. |
| P1 | Cancellation hardening | Tests prove timeout/cancel behavior for the touched package. |
| P1 | Release audit | Changelog, docs, examples, and migration notes agree before tagging. |
| P2 | Example polish | Example is runnable, linked from docs, and covered by a lightweight check. |
## What not to use Codex for yet
- Broad rewrites without a failing test, benchmark, or public design note.
- Public API changes before a maintainer writes the compatibility story.
- Large generated docs that nobody has run.
- Provider-specific behavior that is not checked against the shared `ai.Model`
contract.
## Prompt templates
### PR review
```text
Review this PR for Go Micro. Focus on public API compatibility, cancellation and
context propagation, concurrency safety, tests, and docs drift. Return: summary,
risks, required changes, optional improvements, and exact commands to verify.
```
### Bug reproduction
```text
Reproduce this issue in the smallest Go test or harness change possible. Do not
fix it yet. Explain the failing path and provide the exact command that fails.
```
### Branch implementation
```text
Implement the smallest branch that satisfies this issue. Keep the API compatible
unless explicitly required, update docs/examples when behavior changes, and run
`make test`, `make harness`, and `make lint` or explain any environment blocker.
```
### Release audit
```text
Audit this release branch. Compare CHANGELOG, README, ROADMAP, website docs, and
examples against the diff since the last tag. List inconsistencies, missing
migration notes, and checks to run before tagging.
```
+230
View File
@@ -0,0 +1,230 @@
# Contributing to Go Micro
Thank you for your interest in contributing to Go Micro! This document provides guidelines and instructions for contributing.
## Code of Conduct
Be respectful, inclusive, and collaborative. We're all here to build great software together.
## How Go Micro is built
Go Micro is developed by an **autonomous improvement loop** — a planner, a
generator, and a separate evaluator, running as scheduled GitHub Actions with a
human setting direction. It's the framework's own thesis (an agent operating a
system) pointed at itself: an agent harness, built by agents. The full process —
the planner → generator → evaluator pipeline, the correctness-only merge gate, and
the guardrails — is documented in
[`internal/docs/CONTINUOUS_IMPROVEMENT.md`](internal/docs/CONTINUOUS_IMPROVEMENT.md).
Human contributions follow the same gate: green CI, one concern per PR.
## Getting Started
1. Fork the repository
2. Clone your fork: `git clone https://github.com/YOUR_USERNAME/go-micro.git`
3. Add upstream remote: `git remote add upstream https://github.com/micro/go-micro.git`
4. Create a feature branch: `git checkout -b feature/my-feature`
## Development Setup
```bash
# Install dependencies
go mod download
# Install development tools
make install-tools
# Run tests
make test
# Run tests with race detector and coverage
make test-coverage
# Run linter
make lint
# Format code
make fmt
```
See `make help` for all available commands.
## Making Changes
### Code Guidelines
- Follow standard Go conventions (use `gofmt`, `golint`)
- Write clear, descriptive commit messages
- Add tests for new functionality
- Update documentation for API changes
- Keep PRs focused - one feature/fix per PR
### Commit Messages
Use conventional commits format:
```
type(scope): subject
body
footer
```
Types:
- `feat`: New feature
- `fix`: Bug fix
- `docs`: Documentation changes
- `test`: Test additions/changes
- `refactor`: Code refactoring
- `perf`: Performance improvements
- `chore`: Maintenance tasks
Examples:
```
feat(registry): add kubernetes registry plugin
fix(broker): resolve nats connection leak
docs(examples): add streaming example
```
### Testing
- Write unit tests for all new code
- Ensure existing tests pass
- Add integration tests for plugin implementations
- Test with multiple Go versions (1.20+)
```bash
# Run specific package tests
go test ./registry/...
# Run with verbose output
go test -v ./...
# Run specific test
go test -run TestMyFunction ./pkg/...
# Optional: Use richgo for colored output
go install github.com/kyoh86/richgo@latest
richgo test -v ./...
```
### Documentation
- Update relevant markdown files in `internal/website/docs/`
- Add examples to `internal/website/docs/examples/` for new features
- Update README.md for major features
- Add godoc comments for exported functions/types
## Pull Request Process
1. **Update your branch**
```bash
git fetch upstream
git rebase upstream/master
```
2. **Run tests and linting**
```bash
go test ./...
golangci-lint run
```
3. **Push to your fork**
```bash
git push origin feature/my-feature
```
4. **Create Pull Request**
- Use a descriptive title
- Reference any related issues
- Describe what changed and why
- Add screenshots for UI changes
- Mark as draft if work in progress
5. **PR Review**
- Respond to feedback promptly
- Make requested changes
- Re-request review after updates
### PR Checklist
- [ ] Tests pass locally
- [ ] Code follows Go conventions
- [ ] Documentation updated
- [ ] Commit messages are clear
- [ ] Branch is up to date with master
- [ ] No merge conflicts
## Adding Plugins
New plugins should:
1. Live in the appropriate interface directory (e.g., `registry/myplugin/`)
2. Implement the interface completely
3. Include comprehensive tests
4. Provide usage examples
5. Document configuration options (env vars, options)
6. Add to plugin documentation
Example structure:
```
registry/myplugin/
├── myplugin.go # Main implementation
├── myplugin_test.go # Tests
├── options.go # Plugin-specific options
└── README.md # Usage and configuration
```
## Reporting Issues
Before creating an issue:
1. Search existing issues
2. Check documentation
3. Try the latest version
When reporting bugs:
- Use the bug report template
- Include minimal reproduction code
- Specify versions (Go, Go Micro, plugins)
- Provide relevant logs
## Documentation Contributions
Documentation improvements are always welcome!
- Fix typos and grammar
- Improve clarity
- Add missing examples
- Update outdated information
Documentation lives in `internal/website/docs/`. Preview locally with Jekyll:
```bash
cd internal/website
bundle install
bundle exec jekyll serve --livereload
```
## Community
- GitHub Issues: Bug reports and feature requests
- GitHub Discussions: Questions, ideas, and community chat
- Sponsorship: [GitHub Sponsors](https://github.com/sponsors/micro)
## Release Process
Maintainers handle releases:
1. Update CHANGELOG.md
2. Tag release: `git tag -a v5.x.x -m "Release v5.x.x"`
3. Push tag: `git push origin v5.x.x`
4. GitHub Actions creates release
## Questions?
- Check [documentation](internal/website/docs/)
- Browse [examples](internal/website/docs/examples/)
- Open a [question issue](.github/ISSUE_TEMPLATE/question.md)
Thank you for contributing to Go Micro! 🎉
+26
View File
@@ -0,0 +1,26 @@
FROM alpine:latest
ARG TARGETPLATFORM
ENV USER=micro
ENV GROUPNAME=$USER
ARG UID=1001
ARG GID=1001
RUN addgroup --gid "$GID" "$GROUPNAME" \
&& adduser \
--disabled-password \
--gecos "" \
--home "/micro" \
--ingroup "$GROUPNAME" \
--no-create-home \
--uid "$UID" "$USER"
ENV PATH=/usr/local/go/bin:$PATH
RUN apk --no-cache add git make curl
COPY --from=golang:1.26.0-alpine /usr/local/go /usr/local/go
COPY $TARGETPLATFORM/micro /usr/local/go/bin/
COPY $TARGETPLATFORM/protoc-gen-micro /usr/local/go/bin/
WORKDIR /micro
EXPOSE 8080
ENTRYPOINT ["/usr/local/go/bin/micro"]
CMD ["server"]
+12 -2
View File
@@ -1,4 +1,3 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
@@ -176,7 +175,18 @@
END OF TERMS AND CONDITIONS
Copyright 2015 Asim Aslam.
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
+128
View File
@@ -0,0 +1,128 @@
NAME = micro
GIT_COMMIT = $(shell git rev-parse --short HEAD)
GIT_TAG = $(shell git describe --abbrev=0 --tags --always --match "v*")
GIT_IMPORT = go-micro.dev/v5/cmd/micro
BUILD_DATE = $(shell date +%s)
LDFLAGS = -X $(GIT_IMPORT).BuildDate=$(BUILD_DATE) -X $(GIT_IMPORT).GitCommit=$(GIT_COMMIT) -X $(GIT_IMPORT).GitTag=$(GIT_TAG)
# GORELEASER_DOCKER_IMAGE = ghcr.io/goreleaser/goreleaser-cross:v1.25.7
GORELEASER_DOCKER_IMAGE = ghcr.io/goreleaser/goreleaser:latest
.PHONY: test test-race test-coverage harness cli-wayfinding docs-wayfinding install-smoke provider-conformance-mock provider-conformance lint fmt install-tools proto clean help gorelease-dry-run gorelease-dry-run-docker
# Default target
help:
@echo "Go Micro Development Tasks"
@echo ""
@echo " make test - Run tests"
@echo " make test-race - Run tests with race detector"
@echo " make test-coverage - Run tests with coverage"
@echo " make lint - Run linter"
@echo " make harness - Run deterministic getting-started and end-to-end harnesses"
@echo " make cli-wayfinding - Verify installed first-agent CLI wayfinding commands"
@echo " make docs-wayfinding - Verify first-agent docs wayfinding links resolve locally"
@echo " make install-smoke - Verify the local install.sh and first-run CLI smoke path"
@echo " make provider-conformance-mock - Run cross-provider harness with deterministic mock provider"
@echo " make provider-conformance - Run harnesses against configured live providers"
@echo " make fmt - Format code"
@echo " make install-tools - Install development tools"
@echo " make proto - Generate protobuf code"
@echo " make clean - Clean build artifacts"
$(NAME):
CGO_ENABLED=0 go build -ldflags "-s -w ${LDFLAGS}" -o $(NAME) cmd/micro/main.go
# Run tests
test:
go test -v ./...
# Run tests with race detector
test-race:
go test -v -race ./...
# Run tests with coverage
test-coverage:
go test -v -race -coverprofile=coverage.out -covermode=atomic ./...
go tool cover -html=coverage.out -o coverage.html
@echo "Coverage report: coverage.html"
# Run the documented getting-started contracts plus the deterministic
# services → agents → workflows harnesses (mock LLM — no API key).
# This mirrors the default CI path so local dogfooding catches scaffold,
# run/chat/inspect, and 0→hero regressions before a PR is opened.
harness:
$(MAKE) cli-wayfinding
go test ./cmd/micro/cli/new -run TestZeroToOne -count=1
./internal/harness/zero-to-hero-ci/run.sh
go run ./internal/harness/agent-flow
$(MAKE) provider-conformance-mock
# Verify the installed CLI keeps the first-agent on-ramp commands discoverable.
# This guards the no-secret commands README/docs recommend (`micro agent demo`,
# `micro examples`, and `micro zero-to-hero`) as a CI contract.
cli-wayfinding:
go test ./cmd/micro -run 'TestFirstAgentWalkthroughCLIBoundaries|TestExamplesWayfinding' -count=1
$(MAKE) docs-wayfinding
$(MAKE) install-smoke
# Verify the README and website first-agent/0→hero wayfinding links resolve to
# maintained local docs and examples. This is a focused no-network guard for the
# developer-adoption on-ramp.
docs-wayfinding:
go test ./internal/harness/zero-to-hero-ci -run 'TestFirstAgentWayfindingDocs|TestFirstAgentWayfindingLinkTargetsResolve' -count=1
# Verify the documented install script and first-run CLI command boundaries without
# provider keys or network access.
install-smoke:
./internal/harness/install-smoke/run.sh
# Run the shared provider conformance contract with the deterministic mock
# provider. This is the no-secret path used by CI and local dogfooding to keep
# provider-facing agent/tool semantics covered on every machine.
provider-conformance-mock:
go run ./internal/harness/provider-conformance -providers mock
# Run the same harnesses against every configured live provider. Providers
# without API keys are skipped; configured providers must pass.
provider-conformance:
go run ./internal/harness/provider-conformance
# Run linter
lint:
golangci-lint run
# Format code
fmt:
gofmt -s -w .
goimports -w .
# Install development tools
install-tools:
@echo "Installing development tools..."
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
go install golang.org/x/tools/cmd/goimports@latest
go install github.com/kyoh86/richgo@latest
go install go-micro.dev/v5/cmd/protoc-gen-micro@latest
@echo "Tools installed successfully"
# Generate protobuf code
proto:
@echo "Generating protobuf code..."
find . -name "*.proto" -not -path "./vendor/*" -exec protoc --proto_path=. --micro_out=. --go_out=. {} \;
# Clean build artifacts
clean:
rm -f coverage.out coverage.html
find . -name "*.test" -type f -delete
go clean -cache -testcache
# Try binary release
gorelease-dry-run:
docker run \
--rm \
-e CGO_ENABLED=0 \
-v $(CURDIR):/$(NAME) \
-v /var/run/docker.sock:/var/run/docker.sock \
-w /$(NAME) \
$(GORELEASER_DOCKER_IMAGE) \
--clean --verbose --skip=publish,validate --snapshot
+480 -31
View File
@@ -1,49 +1,498 @@
# Go Micro [![License](https://img.shields.io/:license-apache-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![GoDoc](https://godoc.org/github.com/micro/go-micro?status.svg)](https://godoc.org/github.com/micro/go-micro) [![Travis CI](https://api.travis-ci.org/micro/go-micro.svg?branch=master)](https://travis-ci.org/micro/go-micro) [![Go Report Card](https://goreportcard.com/badge/micro/go-micro)](https://goreportcard.com/report/github.com/micro/go-micro)
# Go Micro [![Go.Dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white&style=flat-square)](https://pkg.go.dev/go-micro.dev/v6?tab=doc) [![Go Report Card](https://goreportcard.com/badge/github.com/go-micro/go-micro)](https://goreportcard.com/report/github.com/go-micro/go-micro) [![Discord](https://img.shields.io/badge/Discord-join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/G8Gk5j3uXr)
Go Micro is a framework for microservice development.
Go Micro is an **agent harness** and service framework for Go.
## Overview
**Community:** questions, ideas, or just want to build alongside us? [Join the Discord](https://discord.gg/G8Gk5j3uXr).
Go Micro provides the core requirements for distributed systems development including RPC and Event driven communication.
The **micro** philosophy is sane defaults with a pluggable architecture. We provide defaults to get you started quickly
but everything can be easily swapped out.
A harness is the runtime around an agent: the tools it can call, the memory it keeps, the guardrails that bound it, the workflows that trigger it, the services it depends on, and the protocols other agents use to reach it.
<img src="https://micro.mu/docs/images/go-micro.svg" />
Go Micro gives you the harness as Go code. Build an agent and it gets a model, memory, tools, planning, delegation, guardrails, and service discovery; it is reachable over [MCP](https://modelcontextprotocol.io/) and [A2A](https://a2a-protocol.org). Write services and every endpoint becomes an AI-callable tool. Orchestrate the deterministic parts with durable flows. Agents, services, and flows share one runtime because an agent is a distributed system, and building one is building a service.
Plugins are available at [github.com/micro/go-plugins](https://github.com/micro/go-plugins).
## Sponsors
Follow us on [Twitter](https://twitter.com/microhq) or join the [Slack](http://slack.micro.mu/) community.
<a href="https://go-micro.dev/blog/3"><img src="https://upload.wikimedia.org/wikipedia/commons/7/78/Anthropic_logo.svg" height="26" /></a>
&nbsp;&nbsp;
<a href="https://go-micro.dev/blog/29"><img src="https://upload.wikimedia.org/wikipedia/commons/4/4d/OpenAI_Logo.svg" height="26" /></a>
&nbsp;&nbsp;
<a href="https://go-micro.dev/blog/8"><img src="https://www.atlascloud.ai/logo.svg" height="26" /></a>
**Want to support Go Micro and see your logo here?** [Become a sponsor](https://discord.gg/G8Gk5j3uXr) — reach out on Discord.
## Commercial Support
Running Go Micro in production, or building on it and want help? Paid **support, consulting, training, and retainers** are available directly from the maintainer — and they're what keep the project maintained. See [**Support**](SUPPORT.md) for the tiers, or [open a request](https://github.com/micro/go-micro/issues/new?template=commercial_support.md).
## Contents
- [Quick Start](#quick-start)
- [First agent on-ramp](#first-agent-on-ramp)
- [Why an Agent Harness](#why-an-agent-harness)
- [Writing Services](#writing-services)
- [Building Agents](#building-agents) — [Plan & Delegate](#plan--delegate), [Pluggable](#batteries-included-pluggable), [Paid tools (x402)](#paid-tools-x402), [A2A](#reachable-by-other-agents-a2a)
- [Features](#features)
- [CLI](#cli)
- [Autonomous improvement loop](#autonomous-improvement-loop)
- [Multi-Service Projects](#multi-service-projects)
- [Data Model](#data-model)
- [AI Providers](#ai-providers)
- [Examples](#examples)
- [Commercial Support](#commercial-support)
- [Docs](#docs)
## Quick Start
Install the CLI:
```bash
# Binary (no Go required)
curl -fsSL https://go-micro.dev/install.sh | sh
# Or with Go
go install go-micro.dev/v6/cmd/micro@latest
```
If install or `PATH` checks fail, use the [install troubleshooting guide](internal/website/docs/guides/install-troubleshooting.md) before scaffolding your first service.
### Fastest start — no API key
Scaffold a service, run it, call it:
```bash
micro new helloworld
cd helloworld
micro run
```
Then in another terminal:
```bash
curl -X POST http://localhost:8080/api/helloworld/Helloworld.Call \
-H 'Content-Type: application/json' -d '{"name":"World"}'
```
This install → scaffold → run → call path is covered by no-secret CI harnesses. To
verify just the local installer and first-run CLI boundaries without network
access or provider keys, use:
```bash
make install-smoke
```
To run the broader local contract (including the [0→hero services → agents → workflows path](internal/website/docs/guides/zero-to-hero.md),
chat/inspect CLI boundaries, and deploy dry-run), use:
```bash
make harness
```
### First agent on-ramp
After install and the first `micro new`/`micro run` smoke check, take the
walkable agent path in this order:
1. [Install troubleshooting](internal/website/docs/guides/install-troubleshooting.md) — verify the binary installer or `go install`, `PATH`, `micro --version`, and the no-secret smoke path before agent work.
2. `micro agent demo` — print the provider-free first-agent demo command and next docs steps from the installed CLI.
3. `micro examples` — print the maintained provider-free runnable examples in copy/paste order.
4. `micro zero-to-hero` — print the maintained one-command no-secret lifecycle harness and runnable examples.
5. [Examples wayfinding index](examples/INDEX.md) — choose the smallest no-secret first-agent, maintained [0→hero support reference](examples/support/), and next interop examples from one map.
6. [Smallest first-agent example](examples/first-agent/) — run one service-backed agent with a mock model and no provider key.
7. [No-secret first-agent transcript](internal/website/docs/guides/no-secret-first-agent.md) — run the
maintained support agent with a mock model and see services → agents → workflows succeed without a key.
8. [Your First Agent](internal/website/docs/guides/your-first-agent.md) — build a
service-backed agent and talk to it with `micro chat`.
9. [Debugging your agent](internal/website/docs/guides/debugging-agents.md) — use
`micro inspect agent <name>`, run history, memory, and provider checks when the first
conversation does something unexpected.
10. [0→hero Reference](internal/website/docs/guides/zero-to-hero.md) — complete the
services → agents → workflows loop with scaffold, run, chat, inspect, flow
history, and deploy dry-run commands that match the maintained harness.
### Autonomous improvement loop
Want the same services → agents → workflows lifecycle applied to your
repository? `micro loop` scaffolds the autonomous improvement loop used by Go
Micro itself: a North Star, ranked issue queue, role prompts, GitHub Actions
workflows, and verification for CI-gated PRs.
```bash
micro loop init --roles all
micro loop verify
```
Before turning on the schedule, configure a dispatch token such as
`CODEX_TRIGGER_TOKEN`, protect the default branch with required CI checks
(`go build ./...`, `go test ./...`, and `golangci-lint run ./...` for this
repository), and seed `.github/loop/PRIORITIES.md` with one scoped issue per
increment. See the [`micro loop` quickstart](internal/website/docs/guides/micro-loop.md)
for the setup checklist and operating model.
### Generate from a prompt — with an LLM key
Set a provider key, describe what you want, and the AI designs services, writes handlers, compiles, and starts them:
```bash
export ANTHROPIC_API_KEY=sk-ant-... # or OPENAI_API_KEY, GEMINI_API_KEY, ...
micro run --prompt "a task management system with categories" --provider anthropic
```
The AI designs the architecture, you review it, then it generates handlers with real business logic, compiles them, and starts them:
```
Services:
● task — Task management with status tracking
● project — Project organization
Generate? [Y/n]
Micro
Services:
● task
● project
Agents:
◆ agent
```
Then talk to your services from the console:
```
> Create a project called Launch, then add three tasks to it
→ project_Project_Create({"name":"Launch"})
← {"record":{"id":"p1..."},"success":true}
→ task_Task_Create({"title":"Design specs","project_id":"p1..."})
→ task_Task_Create({"title":"Write code","project_id":"p1..."})
→ task_Task_Create({"title":"Ship it","project_id":"p1..."})
Created project Launch and added three tasks to it.
```
When you need a capability that doesn't exist, the agent generates a new service mid-conversation:
```
> I need to track shipping. Create a shipment for order 123 to London.
⚡ generating shipping service...
✓ shipping
→ shipping_Shipping_Create({"order_id":"123","destination":"London"})
← {"record":{"id":"xyz...","status":"pending"}}
Created shipment for order 123 going to London.
```
Edit the generated code by hand at any time — re-running preserves your changes. [Read more](https://go-micro.dev/blog/13).
## Why an Agent Harness
The first wave of agent frameworks helped developers put a model in a loop. The next problem is operating that loop: connecting it to real tools, scoping what it can touch, preserving state, routing work to specialists, recovering from failures, observing what happened, and letting other agents call it. That is harness work.
Go Micro's answer is to make the harness the same thing you already deploy:
- **Tools are services** — endpoint metadata becomes tool schema; RPC executes the call.
- **Agents are services** — they register, discover, load-balance, and expose `Agent.Chat`.
- **Workflows are durable code paths** — use flows when the path is known; dispatch to agents when it is not.
- **Safety lives at execution** — `MaxSteps`, `LoopLimit`, `ApproveTool`, and tool wrappers run where actions happen.
- **Interop is built in** — MCP for tools, A2A for agents, x402 for paid tools.
Use Go Micro when the agent has to operate a system, not just answer a prompt.
## Writing Services
Under the hood, a service is a struct with methods. Doc comments and `@example` tags become tool descriptions for AI agents automatically.
```go
package main
import (
"context"
"go-micro.dev/v6"
)
type Request struct {
Name string `json:"name"`
}
type Response struct {
Message string `json:"message"`
}
type Say struct{}
// Hello greets a person by name.
// @example {"name": "Alice"}
func (h *Say) Hello(ctx context.Context, req *Request, rsp *Response) error {
rsp.Message = "Hello " + req.Name
return nil
}
func main() {
service := micro.NewService("greeter")
service.Handle(new(Say))
service.Run()
}
```
Run it and everything is accessible — REST, gRPC, MCP, agent playground:
```bash
micro run
# Dashboard: http://localhost:8080
# API: http://localhost:8080/api/{service}/{method}
# Agent: http://localhost:8080/agent
# MCP Tools: http://localhost:8080/mcp/tools
```
You can also scaffold a service from a template:
```bash
micro new helloworld
micro new contacts --template crud
```
## Building Agents
An Agent is a service with an LLM inside it. It has a proto-defined `Agent.Chat` RPC endpoint, registers in the registry, and is callable like any service:
```go
agent := micro.NewAgent("task-mgr",
micro.AgentServices("task", "project"),
micro.AgentPrompt("You manage tasks and projects. You understand deadlines and priorities."),
micro.AgentProvider("anthropic"),
)
agent.Run()
```
The agent discovers its services from the registry, scopes its tools to their endpoints, and maintains conversation memory in the store. It registers itself so `micro chat` and other agents can find it.
```go
// Programmatic interaction
resp, _ := agent.Ask(ctx, "What tasks are overdue?")
fmt.Println(resp.Reply)
```
Multiple agents coordinate via RPC — each is a service with an `Agent.Chat` endpoint. `micro chat` routes to the right one.
```bash
micro agent list # list registered agents
micro call task-mgr Agent.Chat '{"message": "What tasks are overdue?"}'
```
### Plan & Delegate
Every agent gets two built-in harness capabilities, exposed as tools — no extra setup or separate graph runtime:
- **`plan`** — for multi-step work, the agent records an ordered plan in its store-backed memory and stays oriented across turns.
- **`delegate`** — the agent hands a self-contained subtask to another agent. If a registered agent already owns the relevant services, the hand-off goes over RPC to that agent; otherwise a focused, short-lived sub-agent is created for the subtask with its own isolated context.
This keeps intelligence distributed: an agent doesn't need to know *how* to do everything, only *who* does. See [examples/agent-plan-delegate](examples/agent-plan-delegate/).
```go
// A sub-agent is just an agent — created with New, talked to with Ask.
// delegate-first: reuse a registered agent, or spin up a focused one.
resp, _ := agent.Ask(ctx, "Plan the launch, create the tasks, and have comms notify the owner.")
```
### Batteries included, pluggable
Just as a service composes pluggable abstractions (registry, broker, store), an agent composes a **model**, **memory**, and **tools** — sane defaults out of the box, each swappable.
```go
agent := micro.NewAgent("assistant",
micro.AgentProvider("anthropic"), // model — swap the provider
micro.AgentCompactMemory(40, 12), // memory — durable, summarized, recallable
micro.AgentTool("weather", "Get the weather for a city",
map[string]any{"city": map[string]any{"type": "string"}},
func(ctx context.Context, in map[string]any) (string, error) {
return getWeather(in["city"].(string)) // tools beyond your services — any function
}),
micro.AgentMaxSteps(8), // guardrails
)
```
**Memory** is durable and store-backed by default (Postgres, NATS KV, or file), so an agent picks up where it left off after a restart — or supply your own with `AgentMemory`. Long-running agents can opt into `AgentCompactMemory(maxMessages, keepRecent)`: older turns are collapsed into a deterministic summary, recent turns stay verbatim, and relevant archived turns are recalled on future asks without replaying the whole conversation. **Tools** are your services automatically, plus any function you register with `AgentTool`.
### Paid tools (x402)
Every endpoint is an AI-callable tool — and it can be a *paid* tool. Go Micro supports [x402](https://x402.org), the HTTP 402 payment standard for agents, so a tool can require a stablecoin payment and an agent can settle it autonomously. It's opt-in and carries no crypto in the framework: verification is delegated to a pluggable facilitator (Coinbase, Alchemy, self-hosted), so Base and Solana are just different facilitators.
```bash
# Charge for tool calls at the MCP gateway (off unless you set a pay-to address)
micro mcp serve --x402_pay_to 0xYourAddress --x402_network solana --x402_amount 10000
# Per-tool amounts via a config file
micro mcp serve --x402_config x402.json
```
See the [Payments (x402) guide](internal/website/docs/guides/x402-payments.md).
### Reachable by other agents (A2A)
Within a Go Micro system, agents reach each other over RPC. To make them reachable by agents on *other* frameworks, Go Micro speaks the [Agent2Agent (A2A) protocol](https://a2a-protocol.org). The A2A gateway discovers your agents from the registry, generates an Agent Card for each from its metadata — the same way the MCP gateway derives tools from service endpoints — and translates incoming A2A tasks to the agent's `Agent.Chat` RPC. No per-agent code: register an agent and it's reachable over A2A.
```bash
micro a2a serve --address :4000 # gateway: expose every registered agent over A2A
micro a2a list # agents and their Agent Card URLs
```
Or skip the gateway entirely — an agent can serve its own A2A endpoint directly, handling tasks in-process:
```go
micro.NewAgent("task-mgr", micro.AgentServices("task"), micro.AgentA2A(":4000"))
```
It works both ways. To call an agent on another framework, an `a2a.Client` is wired into the two places that hand off work: `flow.A2A(url)` as a workflow step (the cross-framework `Dispatch`), and `delegate` to an `http(s)` URL from inside an agent.
MCP exposes your services as tools; A2A exposes your agents as agents. See the [A2A guide](internal/website/docs/guides/a2a-protocol.md).
## Features
Go Micro abstracts away the details of distributed systems. Here are the main features.
### AI
- **Service Discovery** - Automatic service registration and name resolution. Service discovery is at the core of micro service
development. When service A needs to speak to service B it needs the location of that service. The default discovery mechanism is
multicast DNS (mdns), a zeroconf system. You can optionally set gossip using the SWIM protocol for p2p networks or consul for a
resilient cloud-native setup.
| Feature | Details |
|---------|---------|
| Agents | `micro.NewAgent()` — intelligent layer that manages services |
| Plan & delegate | Built-in agent tools — plan multi-step work, delegate subtasks to other agents |
| Pluggable memory | Durable store-backed conversation memory by default; swap with `AgentMemory` |
| Custom tools | `AgentTool` — give an agent any function as a tool, beyond its services |
| Guardrails | `MaxSteps` (stop on count), `LoopLimit` (stop repeated no-progress calls), `ApproveTool` (human-in-the-loop) |
| Tool middleware | `AgentWrapTool` — wrap tool execution for logging, metrics, or retries (like client/server wrappers) |
| Workflows | `micro.NewFlow()` — event-driven; one step, ordered durable steps, or triggers an agent |
| Durable execution | Checkpointed flow steps survive a crash and resume where they stopped; store-backed by default, pluggable backend |
| MCP gateway | Every endpoint is an AI tool automatically |
| A2A gateway | Every agent is reachable over the Agent2Agent protocol; cards generated from the registry (`micro a2a`) |
| Payments (x402) | Opt-in per-call payments for tools via the x402 standard; pluggable facilitator (Base, Solana, …) |
| 9 LLM providers | Anthropic, OpenAI, Gemini, Groq, Mistral, Together, Atlas Cloud, MiniMax, Ollama (local + cloud) |
| Interactive console | `micro run` includes a chat console for talking to services |
| Service generation | `micro run --prompt` — describe a system, get running services |
- **Load Balancing** - Client side load balancing built on service discovery. Once we have the addresses of any number of instances
of a service we now need a way to decide which node to route to. We use random hashed load balancing to provide even distribution
across the services and retry a different node if there's a problem.
### Framework
- **Message Encoding** - Dynamic message encoding based on content-type. The client and server will use codecs along with content-type
to seamlessly encode and decode Go types for you. Any variety of messages could be encoded and sent from different clients. The client
and server handle this by default. This includes protobuf and json by default.
| Feature | Details |
|---------|---------|
| Service registry | mDNS (default), Consul, etcd |
| RPC client/server | gRPC transport, load balancing, streaming |
| Pub/sub events | NATS, RabbitMQ, HTTP broker |
| Key-value store | File (bbolt), Postgres, NATS KV |
| Typed model layer | CRUD + queries, SQLite/Postgres backends |
| Everything swappable | All abstractions are Go interfaces |
- **Request/Response** - RPC based request/response with support for bidirectional streaming. We provide an abstraction for synchronous
communication. A request made to a service will be automatically resolved, load balanced, dialled and streamed. The default
transport is http/1.1 or http2 when tls is enabled.
### Developer experience & deployment
- **Async Messaging** - PubSub is built in as a first class citizen for asynchronous communication and event driven architectures.
Event notifications are a core pattern in micro service development. The default messaging is point-to-point http/1.1 or http2 when tls
is enabled.
| Feature | Details |
|---------|---------|
| Hot reload | `micro run` watches files, rebuilds on change |
| Templates | `micro new --template crud/pubsub/api` |
| One-command deploy | `micro deploy user@server` — SSH + systemd, no Docker |
- **Pluggable Interfaces** - Go Micro makes use of Go interfaces for each distributed system abstraction. Because of this these interfaces
are pluggable and allows Go Micro to be runtime agnostic. You can plugin any underlying technology. Find plugins in
[github.com/micro/go-plugins](https://github.com/micro/go-plugins).
## CLI
## Getting Started
| Command | Purpose |
|---------|---------|
| `micro run --prompt "..."` | Generate services + agent, start with interactive console |
| `micro run` | Dev mode: hot reload, gateway, interactive console |
| `micro run -d` | Detached mode (no console) |
| `micro chat` | Standalone chat (when not using micro run) |
| `micro agent list` | List registered agents |
| `micro new myservice` | Scaffold a service |
| `micro call service endpoint '{}'` | Call a service or agent from the CLI |
| `micro build` | Compile production binaries |
| `micro deploy user@server` | Deploy via SSH + systemd |
See the [docs](https://micro.mu/docs/go-micro.html) for detailed information on the architecture, installation and use of go-micro.
## Multi-Service Projects
Run multiple services together:
```go
users := micro.NewService("users", micro.Address(":9001"))
orders := micro.NewService("orders", micro.Address(":9002"))
users.Handle(new(Users))
orders.Handle(new(Orders))
g := micro.NewGroup(users, orders)
g.Run()
```
Or use a `micro.mu` config file:
```
service users
path ./users
service orders
path ./orders
depends users
```
## Data Model
Typed persistence with CRUD and queries:
```go
type User struct {
ID string `json:"id" model:"key"`
Name string `json:"name"`
Email string `json:"email" model:"index"`
}
db := service.Model()
db.Register(&User{})
db.Create(ctx, &User{ID: "1", Name: "Alice", Email: "alice@example.com"})
var results []*User
db.List(ctx, &results, model.Where("email", "alice@example.com"))
```
Backends: memory (default), SQLite, Postgres.
## AI Providers
Swap providers with a single import — same interface everywhere:
| Provider | Default Model |
|----------|---------------|
| Anthropic | `claude-sonnet-4-20250514` |
| OpenAI | `gpt-4o` |
| Google Gemini | `gemini-2.5-flash` |
| Groq | `llama-3.3-70b-versatile` |
| Mistral | `mistral-large-latest` |
| Together AI | `meta-llama/Llama-3.3-70B-Instruct-Turbo` |
| Atlas Cloud | `deepseek-ai/DeepSeek-V3-0324` |
| MiniMax | `MiniMax-M3` |
| Ollama | `llama3.2` (local) |
```go
m := ai.New("anthropic", ai.WithAPIKey(key))
resp, _ := m.Generate(ctx, &ai.Request{Prompt: "hello"})
```
## Examples
New to agents? Follow the [first-agent on-ramp](#first-agent-on-ramp), then use the [examples index](examples/README.md) for the full services → agents → workflows map.
- [hello-world](examples/hello-world/) — Basic RPC service
- [multi-service](examples/multi-service/) — Multiple services in one binary
- [mcp](examples/mcp/) — MCP integration with AI agents
- [first-agent](examples/first-agent/) — Smallest provider-free service-backed agent
- [agent-plan-delegate](examples/agent-plan-delegate/) — Agent planning and multi-agent delegation
- [agent-durable](examples/agent-durable/) — Checkpoint and resume an agent run without replaying completed tool side effects
- [grpc-interop](examples/grpc-interop/) — Call go-micro from any gRPC client
See [all examples](examples/README.md).
## Docs
- [Getting Started](internal/website/docs/getting-started.md)
- [AI Integration](internal/website/docs/ai-integration.md)
- [Your First Agent](internal/website/docs/guides/your-first-agent.md)
- [0→hero Reference](internal/website/docs/guides/zero-to-hero.md)
- [Agents and Workflows](internal/website/docs/guides/agents-and-workflows.md)
- [Agent Design](internal/docs/AGENT_DESIGN.md)
- [Plan & Delegate](internal/website/docs/guides/plan-delegate.md)
- [Agent Guardrails](internal/website/docs/guides/agent-guardrails.md)
- [Payments (x402)](internal/website/docs/guides/x402-payments.md)
- [MCP & AI Agents](internal/website/docs/mcp.md)
- [Data Model](internal/website/docs/model.md)
- [Deployment](internal/website/docs/deployment.md)
- [Plugins](internal/website/docs/plugins.md)
Package reference: https://pkg.go.dev/go-micro.dev/v6
-36
View File
@@ -1,36 +0,0 @@
# Go Micro [![License](https://img.shields.io/:license-apache-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![GoDoc](https://godoc.org/github.com/micro/go-micro?status.svg)](https://godoc.org/github.com/micro/go-micro) [![Travis CI](https://api.travis-ci.org/micro/go-micro.svg?branch=master)](https://travis-ci.org/micro/go-micro) [![Go Report Card](https://goreportcard.com/badge/micro/go-micro)](https://goreportcard.com/report/github.com/micro/go-micro)
Go Micro是基于Golang的微服务开发框架。
## 概览
Go Micro提供分布式系统开发的核心库,包含RPC与事件驱动的通信机制。
**micro**的设计哲学是可插拔的架构理念,她提供可快速构建系统的组件,并且可以根据自身的需求剥离默认实现并自行定制。
<img src="https://micro.mu/docs/images/go-micro.svg" />
所有插件可在仓库[github.com/micro/go-plugins](https://github.com/micro/go-plugins)中找到。
可以订阅我们的[Twitter](https://twitter.com/microhq)或者加入[Slack](http://slack.micro.mu/)论坛。
## 特性
Go Micro把分布式系统的各种细节抽象出来。下面是它的主要特性。
- **服务发现(Service Discovery** - 自动服务注册与名称解析。服务发现是微服务开发中的核心。当服务A要与服务B协作时,它得知道B在哪里。默认的服务发现系统是Consul,而multicast DNS (mdns,组播)机制作为本地解决方案,或者零依赖的P2P网络中的SWIM协议(gossip)。
- **负载均衡(Load Balancing)** - 在服务发现之上构建了负载均衡机制。当我们得到一个服务的任意多个的实例节点时,我们要一个机制去决定要路由到哪一个节点。我们使用随机处理过的哈希负载均衡机制来保证对服务请求颁发的均匀分布,并且在发生问题时进行重试。
- **消息编码(Message Encoding** - 支持基于内容类型(content-type)动态编码消息。客户端和服务端会一起使用content-type的格式来对Go进行无缝编/解码。各种各样的消息被编码会发送到不同的客户端,客户端服服务端默认会处理这些消息。content-type默认包含proto-rpc和json-rpc。
- **Request/Response** - RPC通信基于支持双向流的请求/响应方式,我们提供有抽象的同步通信机制。请求发送到服务时,会自动解析、负载均衡、拨号、转成字节流。默认的传输协议是http/1.1,而tls下使用http2协议。
- **异步消息(Async Messaging** - 发布订阅(PubSub)头等功能内置在异步通信与事件驱动架构中。事件通知在微服务开发中处于核心位置。默认的消息传送使用点到点http/1.1,激活tls时则使用http2。
- **可插拔接口(Pluggable Interfaces** - Go Micro为每个分布式系统抽象出接口。因此,Go Micro的接口都是可插拔的,允许其在运行时不可知的情况下仍可支持。所以只要实现接口,可以在内部使用任何的技术。更多插件请参考:[github.com/micro/go-plugins](https://github.com/micro/go-plugins)。
## 快速上手
更多关于架构、安装的资料可以查看[文档](https://micro.mu/docs/cn/)。
+79
View File
@@ -0,0 +1,79 @@
# Go Micro Roadmap
Go Micro is an **agent harness** and service framework for Go. A harness is the
runtime around an agent — the tools, memory, guardrails, workflows, state,
discovery, and protocols it needs to operate a system rather than just answer a
prompt. An agent is a distributed system — it discovers services, calls them,
holds state, and recovers from failure — so the harness is the runtime services
already have, and building an agent is building a service. The roadmap has two
jobs: make **agentic development** excellent, and make the **developer experience**
around it excellent.
The full, current roadmap lives at **[go-micro.dev/docs/roadmap](https://go-micro.dev/docs/roadmap)**
([source](internal/website/docs/roadmap.md)). The highlights:
## Where we are (v6)
Services, agents (`plan`/`delegate`, guardrails, memory, tool middleware), durable
flows, the MCP and A2A gateways (both directions, including A2A streaming,
push notifications, and multi-turn continuation), x402 paid tools, secure by
default.
## Principles
1. Build into what people run, never a separate product (no hosted platform, no
enterprise edition, no VC).
2. CLI-first — the CLI is the experience; UI must earn its place, never bloat.
3. The getting-started flow is a contract: *0→1* (scaffold → run → call) and
*0→hero* (a working multi-agent system) must always work and are verified on
every change.
4. Interaction matters as much as running — chatting with agents, inspecting runs
and history, end to end.
5. Battle-tested: works across every provider, fails safely, observable.
## Now — hardening
- **Cross-provider conformance** — the same agent scenario across all seven
providers, gated on keys, on a schedule.
- **Failure & resilience** — timeouts, rate limits, cancellation, deadline/context
propagation, retry/backoff.
- **Getting-started contract** — define and CI-verify the 0→1 and 0→hero flows.
## Next — agentic depth
- **Durable agent loop** — resume a long run via `Checkpoint` (flows already do).
- **Streaming** — broaden provider-backed `ai.Stream` coverage and keep chat/A2A streaming end to end.
- **Agent observability** — `RunInfo` → OpenTelemetry spans.
## Later
- Memory management (summarization, retrieval/RAG); human-in-the-loop pause/resume;
richer A2A live-stream reconnection (`tasks/resubscribe`) and `input-required`
handoffs.
## Developer experience (ongoing)
- A seamless CLI inner loop (scaffold → run → chat → inspect → deploy); UI
discipline (trim what isn't great); a maintained real-world example that doubles
as the 0→hero reference; docs kept in lockstep with the code.
## How it's sustained
The framework is the product, funded by sponsorship from those who run it — not a
hosted service, enterprise tier, or venture funding. See
[the v6 story](https://go-micro.dev/blog/27).
## Contributing & feedback
Pick an item, open an issue to discuss the approach, and submit a PR. Or join the
[Discord](https://discord.gg/G8Gk5j3uXr). Include tests, run `make test` and
`make lint`.
## Version support
- **v6** — active development (current).
- **v5** — security fixes only.
- **v4 and earlier** — end of life.
Major versions (v5 → v6) carry breaking changes; minors are backward-compatible.
See the [v5 → v6 migration guide](https://go-micro.dev/docs/guides/migration/v5-to-v6).
+178
View File
@@ -0,0 +1,178 @@
# Security Policy
## Supported Versions
We actively support the following versions of go-micro:
| Version | Supported |
| ------- | ------------------ |
| 5.x | :white_check_mark: |
| 4.x | :x: |
| 3.x | :x: |
| < 3.0 | :x: |
## Reporting a Vulnerability
**Please do not report security vulnerabilities through public GitHub issues.**
### How to Report
Use GitHub's private security advisory feature:
https://github.com/micro/go-micro/security/advisories/new
This keeps vulnerability reports private, ties follow-up to the affected repository, and avoids relying on project email routing.
### What to Include
Please include as much of the following information as possible:
- Type of vulnerability (e.g., RCE, XSS, SQL injection, etc.)
- Full paths of source file(s) related to the vulnerability
- Location of the affected source code (tag/branch/commit or direct URL)
- Step-by-step instructions to reproduce the issue
- Proof-of-concept or exploit code (if possible)
- Impact of the issue, including how an attacker might exploit it
### Response Timeline
- **Acknowledgment**: Within 48 hours
- **Initial Assessment**: Within 5 business days
- **Fix Timeline**: Depends on severity
- Critical: 7 days
- High: 14 days
- Medium: 30 days
- Low: Next release cycle
### Disclosure Policy
- We follow **coordinated disclosure**
- We'll work with you to understand and fix the issue
- We'll credit you in the security advisory (unless you prefer to remain anonymous)
- Please give us reasonable time to fix before public disclosure
- We'll publish a security advisory on GitHub when the fix is released
## Security Best Practices
When using go-micro in production:
### TLS/Transport Security
```go
import "go-micro.dev/v5/transport"
// Enable TLS verification (recommended)
os.Setenv("MICRO_TLS_SECURE", "true")
// Or use SecureConfig explicitly
tlsConfig := transport.SecureConfig()
```
See [TLS Security Update](internal/website/docs/TLS_SECURITY_UPDATE.md) for details.
### Authentication
```go
import "go-micro.dev/v5/auth"
// Use JWT authentication
service := micro.NewService(
micro.Auth(auth.NewAuth()),
)
```
### Input Validation
Always validate and sanitize inputs in your handlers:
```go
func (h *Handler) Create(ctx context.Context, req *Request, rsp *Response) error {
// Validate input
if req.Name == "" {
return errors.BadRequest("handler.create", "name is required")
}
// Sanitize and process
// ...
}
```
### Rate Limiting
Implement rate limiting for public-facing services:
```go
import "go-micro.dev/v5/client"
// Client-side rate limiting
client.NewClient(
client.RequestTimeout(time.Second * 5),
client.Retries(3),
)
```
### Secrets Management
Never commit secrets to version control:
```go
// Good: Use environment variables
apiKey := os.Getenv("API_KEY")
// Better: Use a secrets manager
import "github.com/hashicorp/vault/api"
```
### Dependency Security
Regularly update dependencies:
```bash
# Check for vulnerabilities
go list -json -m all | nancy sleuth
# Update dependencies
go get -u ./...
go mod tidy
```
## Known Security Considerations
### Reflection Usage
go-micro uses reflection for automatic handler registration. While this is a deliberate design choice for developer productivity, be aware:
- Type safety is enforced at runtime, not compile time
- Malformed requests won't crash services (errors are returned)
- See [Performance Considerations](internal/website/docs/performance.md)
### TLS Certificate Verification
**Default behavior in v5**: TLS certificate verification is **disabled** for backward compatibility.
**Production recommendation**: Enable secure mode:
```bash
export MICRO_TLS_SECURE=true
```
This will be the default in v6.
## Security Updates
Security updates are published as:
- GitHub Security Advisories
- Release notes with `[SECURITY]` prefix
- CVE entries for critical issues
Subscribe to releases: https://github.com/micro/go-micro/releases
## Bug Bounty
We currently do not offer a bug bounty program, but we greatly appreciate responsible disclosure and will publicly credit researchers who report valid security issues.
## Questions?
For security questions that are not vulnerabilities, please:
- Open a discussion: https://github.com/micro/go-micro/discussions
- Join Discord: https://discord.gg/G8Gk5j3uXr
+29
View File
@@ -0,0 +1,29 @@
# Support
Go Micro is free and open source. There are two ways to get help: the community, and commercial support.
## Community support (free)
- **Documentation** — https://go-micro.dev/docs
- **Examples** — https://github.com/micro/go-micro/tree/master/examples
- **Bugs & features** — https://github.com/micro/go-micro/issues
- **Questions** — open a [Question](https://github.com/micro/go-micro/issues/new?template=question.md) issue
Community support is best-effort, from maintainers and contributors, with no response-time guarantees.
## Commercial support
If you're running Go Micro in production — or building agents and services on it and want a hand — paid support and consulting are available directly from the maintainer. This is what keeps the project maintained.
| Tier | For | What you get | How |
|------|-----|--------------|-----|
| **Community** | Everyone | Docs, examples, issues — best-effort | Free |
| **Sponsor** | Individuals & companies who rely on Go Micro | Back ongoing development; your name/logo in the README and on the site; a voice in priorities | [GitHub Sponsors](https://github.com/sponsors/asim) |
| **Support** | Teams running Go Micro in production | Priority responses, a direct line to the maintainer, prioritized bug fixes, upgrade & integration help | [Open a request](#get-in-touch) |
| **Consulting** | Teams building on Go Micro | Hands-on integration, architecture & agent-design review, training & onboarding, sponsored features | [Open a request](#get-in-touch) |
Recurring amounts are set on the [Sponsors page](https://github.com/sponsors/asim); support and consulting are scoped and quoted per engagement.
## Get in touch
Open a [**Commercial Support / Consulting**](https://github.com/micro/go-micro/issues/new?template=commercial_support.md) request — tell us what you're building, what you need, and your timeline, and we'll follow up. For anything you'd rather not discuss in public, become a [sponsor](https://github.com/sponsors/asim) and message privately.
+102
View File
@@ -0,0 +1,102 @@
package agent
import (
"bytes"
"context"
"encoding/json"
"net/http"
"net/http/httptest"
"strings"
"testing"
"go-micro.dev/v6/ai"
"go-micro.dev/v6/gateway/a2a"
)
func TestA2AStreamUsesAgentChatPathWithTools(t *testing.T) {
var sawTool bool
fakeGen = func(ctx context.Context, opts ai.Options, req *ai.Request) (*ai.Response, error) {
if opts.ToolHandler == nil {
t.Fatal("model was not wired with agent tool handler")
}
result := opts.ToolHandler(ctx, ai.ToolCall{
ID: "call-1",
Name: "echo",
Input: map[string]any{"value": "a2a-stream"},
})
if !strings.Contains(result.Content, "a2a-stream-ok") {
t.Fatalf("tool result = %q, want marker", result.Content)
}
return &ai.Response{Answer: "streamed " + result.Content}, nil
}
defer func() { fakeGen = nil }()
a := newTestAgent(Name("stream-agent"), WithTool("echo", "echo text", nil, func(ctx context.Context, input map[string]any) (string, error) {
sawTool = true
if info, ok := ai.RunInfoFrom(ctx); !ok || info.RunID == "" || info.Agent != "stream-agent" {
t.Fatalf("RunInfo = %+v ok=%v, want stream-agent run", info, ok)
}
if input["value"] != "a2a-stream" {
t.Fatalf("tool input = %+v, want a2a-stream", input)
}
return "a2a-stream-ok", nil
}))
h := a2a.NewAgentStreamHandler(
a2a.Card("stream-agent", "http://example.invalid/stream-agent", "", nil),
func(ctx context.Context, text string) (string, error) {
resp, err := a.Ask(ctx, text)
if err != nil {
return "", err
}
return resp.Reply, nil
},
a.streamAskAI,
)
body := []byte(`{"jsonrpc":"2.0","id":1,"method":"message/stream","params":{"message":{"role":"user","parts":[{"kind":"text","text":"run stream tool"}],"kind":"message"}}}`)
req := httptest.NewRequest(http.MethodPost, "/", bytes.NewReader(body))
rr := httptest.NewRecorder()
h.ServeHTTP(rr, req)
if !sawTool {
t.Fatal("A2A stream did not execute the agent tool path")
}
if ct := rr.Result().Header.Get("Content-Type"); !strings.HasPrefix(ct, "text/event-stream") {
t.Fatalf("content-type = %q, want text/event-stream", ct)
}
if !strings.Contains(rr.Body.String(), "a2a-stream-ok") {
t.Fatalf("stream body missing tool marker: %s", rr.Body.String())
}
var final struct {
Result struct {
Status struct {
State string `json:"state"`
} `json:"status"`
Artifacts []struct {
Parts []struct {
Text string `json:"text"`
} `json:"parts"`
} `json:"artifacts"`
} `json:"result"`
Error any `json:"error"`
}
for _, line := range strings.Split(strings.TrimSpace(rr.Body.String()), "\n") {
line = strings.TrimSpace(strings.TrimPrefix(strings.TrimSpace(line), "data: "))
if line == "" {
continue
}
if err := json.Unmarshal([]byte(line), &final); err != nil {
t.Fatalf("decode event %q: %v", line, err)
}
}
if final.Error != nil {
t.Fatalf("final event error: %+v", final.Error)
}
if final.Result.Status.State != "completed" {
t.Fatalf("final state = %q, want completed", final.Result.Status.State)
}
if len(final.Result.Artifacts) != 1 || len(final.Result.Artifacts[0].Parts) != 1 || !strings.Contains(final.Result.Artifacts[0].Parts[0].Text, "a2a-stream-ok") {
t.Fatalf("final artifacts = %+v, want tool marker", final.Result.Artifacts)
}
}
+616 -1
View File
@@ -1,2 +1,617 @@
// Package agent provides an interface for building robots
// Package agent provides the Agent abstraction for Go Micro.
//
// An Agent is a service with an LLM inside it. It registers a Chat
// RPC endpoint, discovers its assigned services' tools, and
// orchestrates them intelligently.
//
// agent := micro.NewAgent("task-mgr",
// micro.AgentServices("task"),
// micro.AgentPrompt("You manage tasks."),
// micro.AgentProvider("anthropic"),
// )
// agent.Run()
package agent
import (
"context"
"encoding/json"
"fmt"
"net/http"
"strings"
"sync"
"time"
"github.com/google/uuid"
pb "go-micro.dev/v6/agent/proto"
"go-micro.dev/v6/ai"
"go-micro.dev/v6/flow"
"go-micro.dev/v6/gateway/a2a"
"go-micro.dev/v6/server"
"go-micro.dev/v6/store"
_ "go-micro.dev/v6/ai/anthropic"
_ "go-micro.dev/v6/ai/atlascloud"
_ "go-micro.dev/v6/ai/gemini"
_ "go-micro.dev/v6/ai/groq"
_ "go-micro.dev/v6/ai/mistral"
_ "go-micro.dev/v6/ai/ollama"
_ "go-micro.dev/v6/ai/openai"
_ "go-micro.dev/v6/ai/together"
)
// Agent is the interface for an AI agent that manages services.
type Agent interface {
Name() string
Init(...Option)
Options() Options
Ask(ctx context.Context, message string) (*Response, error)
Stream(ctx context.Context, message string) (ai.Stream, error)
Run() error
Stop() error
String() string
}
// Response is what an agent returns from Chat.
type Response struct {
Reply string
ToolCalls []ai.ToolCall
Agent string
// RunID correlates this Ask with tool calls, trace spans, and the
// persisted run timeline. ParentID is set when this response belongs
// to a delegated sub-agent run.
RunID string
ParentID string
}
type agentImpl struct {
opts Options
model ai.Model
tools *ai.Tools
mem Memory
server server.Server
mu sync.Mutex
// ephemeral marks a short-lived sub-agent created by delegation.
// Ephemeral agents run with an isolated context: they load and
// persist no history, and have no built-in tools (so they cannot
// plan or re-delegate).
ephemeral bool
// steps counts tool executions in the current Ask, for MaxSteps.
steps int
// calls counts identical tool calls (name+args) in the current Ask,
// for LoopLimit.
calls map[string]int
// runID correlates the tool calls of the current Ask; parentRunID is
// the run that delegated to this one (set on ephemeral sub-agents).
// Both are surfaced to tool wrappers via ai.RunInfo on the context.
runID string
parentRunID string
// pause records a guardrail approval pause raised during the current
// Ask. The model provider only sees a refused tool result; the agent
// converts it into a durable paused run instead of completing the run.
pause *approvalPause
// currentRun points at the checkpoint record for the Ask currently
// holding mu. Tool execution updates it so resumed runs can reuse
// completed tool results without replaying side effects.
currentRun *flow.Run
// delegateCalls collapses concurrent equivalent delegate tool calls so a
// provider replay cannot fan out duplicate delegated side effects before the
// durable delegate-result cache is written.
delegateMu sync.Mutex
delegateCalls map[string]*delegateCall
}
// New creates a new Agent.
func New(opts ...Option) Agent {
return &agentImpl{
opts: newOptions(opts...),
}
}
// newEphemeral creates a short-lived sub-agent for a delegated subtask.
// It shares the parent's provider, model, and infrastructure but runs
// with an isolated context: it loads and persists no history and has no
// built-in tools (so it can neither plan nor re-delegate). Returns the
// concrete type because ephemeral is an internal construction detail,
// not a public option.
func newEphemeral(opts ...Option) *agentImpl {
return &agentImpl{
opts: newOptions(opts...),
ephemeral: true,
}
}
func (a *agentImpl) Name() string {
return a.opts.Name
}
func (a *agentImpl) Init(opts ...Option) {
for _, o := range opts {
o(&a.opts)
}
a.setup()
}
func (a *agentImpl) Options() Options {
return a.opts
}
func (a *agentImpl) String() string {
return "agent"
}
func (a *agentImpl) setup() {
a.setupWithToolHandler(nil)
}
func (a *agentImpl) setupWithToolHandler(handler ai.ToolHandler) {
var modelOpts []ai.Option
modelOpts = append(modelOpts, ai.WithAPIKey(a.opts.APIKey))
if a.opts.Model != "" {
modelOpts = append(modelOpts, ai.WithModel(a.opts.Model))
}
if a.opts.BaseURL != "" {
modelOpts = append(modelOpts, ai.WithBaseURL(a.opts.BaseURL))
}
// Reuse the existing tools instance: its name map is populated by
// discoverTools, and rebuilding it here would orphan a base handler that
// already captured the old instance (breaking StreamAsk tool resolution).
if a.tools == nil {
a.tools = ai.NewTools(a.opts.Registry, ai.ToolClient(a.opts.Client))
}
if handler == nil {
handler = a.toolHandler()
}
modelOpts = append(modelOpts, ai.WithToolHandler(handler))
a.model = ai.New(a.opts.Provider, modelOpts...)
if a.model != nil {
a.model = a.tracedModel(a.model)
}
if a.mem != nil {
return
}
// Memory is pluggable. Use the configured one, otherwise the default
// store-backed memory — except ephemeral sub-agents, which keep an
// isolated, non-persistent context.
switch {
case a.opts.Memory != nil:
a.mem = a.opts.Memory
case a.ephemeral:
a.mem = NewInMemory(a.opts.HistoryLimit)
case a.opts.MemoryCompaction.MaxMessages > 0:
a.mem = NewCompactingMemoryWithOptions(a.stateStore(), "history", a.opts.MemoryCompaction)
case a.opts.MemoryRetrievalLimit > 0:
a.mem = NewRetrievalMemory(a.stateStore(), "history", a.opts.MemoryRetrievalLimit)
default:
a.mem = NewMemory(a.stateStore(), "history", a.opts.HistoryLimit)
}
}
// stateStore returns the agent's own state store, scoped to its name so
// memory and plan live in their own table ("agent/{name}") rather than a
// shared global one. The scoped handle injects the database/table per
// operation without mutating the underlying store.
func (a *agentImpl) stateStore() store.Store {
s := a.opts.Store
if s == nil {
s = store.DefaultStore
}
return store.Scope(s, "agent", a.opts.Name)
}
// Ask sends a message and returns the agent's response.
// This is the programmatic API for direct use.
func (a *agentImpl) Ask(ctx context.Context, message string) (*Response, error) {
return a.ask(ctx, message, a.parentRunID)
}
// Stream sends a message and returns a streaming model response. Tool-calling
// agent runs still use Ask; Stream is for chat turns where immediate token
// delivery is more important than tool orchestration.
func (a *agentImpl) Stream(ctx context.Context, message string) (ai.Stream, error) {
a.mu.Lock()
defer a.mu.Unlock()
if a.model == nil {
a.setup()
}
toolList, err := a.discoverTools()
if err != nil {
return nil, fmt.Errorf("discover tools: %w", err)
}
messages := append([]ai.Message(nil), a.mem.Messages()...)
messages = append(messages, ai.Message{Role: "user", Content: message})
stream, err := a.model.Stream(ctx, &ai.Request{
Prompt: message,
SystemPrompt: a.buildPrompt(),
Tools: toolList,
Messages: messages,
})
if err != nil {
return nil, err
}
a.mem.Add("user", message)
return &memoryRecordingStream{stream: stream, memory: a.mem}, nil
}
// Pending returns checkpointed agent runs that have not completed. It mirrors
// flow.Pending for startup recovery loops that drain durable agent work.
func Pending(ctx context.Context, ag Agent) ([]flow.Run, error) {
a, ok := ag.(*agentImpl)
if !ok {
return nil, fmt.Errorf("agent pending: unsupported agent implementation %T", ag)
}
return a.pending(ctx)
}
// ResumePending resumes every checkpointed agent run that has not completed
// yet, in the same oldest-first order returned by Pending.
//
// It is a convenience for service startup and recovery loops: after recreating
// an agent with the same checkpoint store, call ResumePending to drain the
// durable backlog without listing and resuming each run manually. If any run
// fails again, ResumePending stops and returns that run id with the error so
// callers can log, alert, or retry later without hiding the failing run.
func ResumePending(ctx context.Context, ag Agent) (string, error) {
a, ok := ag.(*agentImpl)
if !ok {
return "", fmt.Errorf("agent resume pending: unsupported agent implementation %T", ag)
}
runs, err := a.pending(ctx)
if err != nil {
return "", err
}
for _, run := range runs {
if _, err := a.resume(ctx, run.ID); err != nil {
return run.ID, err
}
}
return "", nil
}
func (a *agentImpl) ask(ctx context.Context, message, parentRunID string) (*Response, error) {
a.mu.Lock()
defer a.mu.Unlock()
if a.model == nil {
a.setup()
}
return a.askLocked(ctx, uuid.New().String(), message, parentRunID, nil, true)
}
func (a *agentImpl) askLocked(ctx context.Context, runID, message, parentRunID string, existing *flow.Run, addUserMessage bool) (*Response, error) {
toolList, err := a.discoverTools()
if err != nil {
return nil, fmt.Errorf("discover tools: %w", err)
}
if addUserMessage {
a.mem.Add("user", message)
}
a.steps = 0
a.calls = map[string]int{}
a.pause = nil
// Correlate this run's tool calls and surface lineage to wrappers.
a.runID = runID
ctx = ai.WithRunInfo(ctx, ai.RunInfo{
RunID: a.runID,
ParentID: parentRunID,
Agent: a.opts.Name,
})
run := a.newCheckpointRun(runID, message, parentRunID, existing)
a.currentRun = &run
defer func() { a.currentRun = nil }()
if err := a.saveRun(ctx, run); err != nil {
return nil, err
}
ctx, endRun := a.startRun(ctx, message)
if existing != nil {
a.recordTimelineEvent(ctx, RunEvent{Time: time.Now(), RunID: runID, ParentID: parentRunID, Agent: a.opts.Name, Kind: "resume", Name: run.State.Stage})
}
defer func() { endRun(err) }()
messages := a.mem.Messages()
if recall, ok := a.mem.(MemoryRecall); ok && a.opts.MemoryRecallLimit > 0 {
if recalled := recall.Recall(message, a.opts.MemoryRecallLimit); len(recalled) > 0 {
messages = append([]ai.Message{{
Role: "system",
Content: "Relevant recalled memory follows; use it as durable prior context without assuming the whole conversation was replayed.",
}}, append(recalled, messages...)...)
}
}
// Some providers satisfy a saved plan one outstanding item per turn,
// especially when the final item delegates to another agent. Allow enough
// continuations for the services → agents → workflows harness to complete
// every planned side effect without weakening the final unfinished-plan guard.
const maxPlanCompletionTurns = 6
var resp *ai.Response
for planCompletionTurn := 0; ; planCompletionTurn++ {
resp, err = ai.GenerateWithRetry(ctx, a.model, &ai.Request{
Prompt: message,
SystemPrompt: a.buildPrompt(),
Tools: toolList,
Messages: messages,
}, ai.GeneratePolicy{
Timeout: a.opts.ModelTimeout,
MaxAttempts: a.opts.ModelMaxAttempts,
Backoff: a.opts.ModelRetryBackoff,
})
if err != nil {
run.Status = agentRunFailureStatus(err)
err = agentOperationalError(err)
if a.currentRun != nil {
run.Steps = a.currentRun.Steps
}
if len(run.Steps) == 0 {
run.Steps = []flow.StepRecord{{Name: agentAskStep}}
}
run.Steps[0].Status = run.Status
run.Steps[0].Error = err.Error()
_ = a.saveRun(ctx, run)
return nil, err
}
if a.pause != nil && a.opts.Checkpoint != nil {
run.Status = "paused"
run.State.Stage = agentApprovalStep
run.State.Data = []byte(message)
if a.pause.Tool == toolHumanInput {
run.State.Stage = agentInputStep
_ = run.State.Set(inputPause{OriginalMessage: message, Prompt: a.pause.Message})
}
run.Steps[0].Status = "paused"
run.Steps[0].Error = a.pause.Message
run.Steps[0].Result = a.pause.Tool
if err := a.saveRun(ctx, run); err != nil {
return nil, err
}
return nil, fmt.Errorf("agent run %s paused for approval: %s", run.ID, a.pause.Message)
}
if len(resp.ToolCalls) == 0 {
if calls, answer, ok := a.executeTextToolCalls(ctx, resp.Reply, toolList); ok {
resp.ToolCalls = calls
if resp.Answer == "" {
resp.Answer = answer
}
trimmedReply := strings.TrimSpace(resp.Reply)
if strings.HasPrefix(trimmedReply, "{") || strings.HasPrefix(trimmedReply, "[") || strings.HasPrefix(trimmedReply, "```") {
resp.Reply = ""
}
}
} else if calls, answer, ok := a.executeAdditionalTextToolCalls(ctx, resp.Reply, toolList, resp.ToolCalls); ok {
resp.ToolCalls = append(resp.ToolCalls, calls...)
if answer != "" {
if resp.Answer == "" {
resp.Answer = answer
} else {
resp.Answer += "\n" + answer
}
}
}
if a.opts.Checkpoint != nil {
if unfinished := a.unfinishedPlanSteps(); len(unfinished) > 0 && planCompletionTurn < maxPlanCompletionTurns {
if resp.Reply != "" {
a.mem.Add("assistant", resp.Reply)
}
if resp.Answer != "" {
a.mem.Add("assistant", resp.Answer)
}
message = fmt.Sprintf("Continue the same run by calling the required tool(s) for the unfinished plan steps below. Do not repeat completed work, do not provide a final answer yet, and complete at least one unfinished step this turn if a matching tool is available. Unfinished plan steps: %s", strings.Join(unfinished, ", "))
a.mem.Add("user", message)
messages = a.mem.Messages()
continue
}
}
break
}
if resp.Reply != "" {
a.mem.Add("assistant", resp.Reply)
}
if resp.Answer != "" {
a.mem.Add("assistant", resp.Answer)
}
reply := resp.Reply
if resp.Answer != "" {
if reply != "" {
reply += "\n\n"
}
reply += resp.Answer
}
res := &Response{
Reply: reply,
ToolCalls: resp.ToolCalls,
Agent: a.opts.Name,
RunID: a.runID,
ParentID: parentRunID,
}
if a.opts.Checkpoint != nil {
if unfinished := a.unfinishedPlanSteps(); len(unfinished) > 0 {
err = fmt.Errorf("agent run %s has unfinished plan steps: %s", run.ID, strings.Join(unfinished, ", "))
run.Status = "failed"
run.State.Stage = agentAskStep
run.State.Data = []byte(message)
if a.currentRun != nil {
run.Steps = a.currentRun.Steps
}
if len(run.Steps) == 0 {
run.Steps = []flow.StepRecord{{Name: agentAskStep}}
}
run.Steps[0].Status = "failed"
run.Steps[0].Error = err.Error()
_ = a.saveRun(ctx, run)
return nil, err
}
}
run.Status = "done"
run.State.Stage = ""
if b, marshalErr := json.Marshal(res); marshalErr == nil {
run.State.Data = b
}
if a.currentRun != nil {
run.Steps = a.currentRun.Steps
}
if len(run.Steps) == 0 {
run.Steps = []flow.StepRecord{{Name: agentAskStep}}
}
run.Steps[0].Status = "done"
run.Steps[0].Attempts++
run.Steps[0].Result = reply
if err := a.saveRun(ctx, run); err != nil {
return nil, err
}
return res, nil
}
// Chat implements the proto AgentHandler interface for RPC.
// @example {"message": "What tasks are overdue?"}
func (a *agentImpl) Chat(ctx context.Context, req *pb.ChatRequest, rsp *pb.ChatResponse) error {
resp, err := a.ask(ctx, req.Message, req.ParentId)
if err != nil {
return err
}
rsp.Reply = resp.Reply
rsp.Agent = resp.Agent
rsp.RunId = resp.RunID
rsp.ParentId = resp.ParentID
for _, tc := range resp.ToolCalls {
input, _ := json.Marshal(tc.Input)
rsp.ToolCalls = append(rsp.ToolCalls, &pb.ToolCall{
Id: tc.ID,
Name: tc.Name,
Input: string(input),
Result: tc.Result,
})
}
return nil
}
// Run starts the agent as a service with a Chat RPC endpoint.
func (a *agentImpl) Run() error {
if a.model == nil {
a.setup()
}
serverOpts := []server.Option{
server.Name(a.opts.Name),
server.Address(a.opts.Address),
server.Registry(a.opts.Registry),
server.Metadata(map[string]string{
"type": "agent",
"services": strings.Join(a.opts.Services, ","),
}),
}
if a.opts.Broker != nil {
serverOpts = append(serverOpts, server.Broker(a.opts.Broker))
}
a.server = server.NewServer(serverOpts...)
_ = pb.RegisterAgentHandler(a.server, a)
if err := a.server.Start(); err != nil {
return fmt.Errorf("failed to start agent: %w", err)
}
fmt.Printf("Agent %s registered (manages: %s)\n", a.opts.Name, strings.Join(a.opts.Services, ", "))
// Optionally serve the agent directly over the A2A protocol, calling
// Ask in-process — no separate gateway needed to be queried by URL.
if a.opts.A2AAddress != "" {
card := a2a.Card(a.opts.Name, "http://localhost"+a.opts.A2AAddress, "", a.opts.Services)
handler := a2a.NewAgentStreamHandler(card, func(ctx context.Context, text string) (string, error) {
resp, err := a.Ask(ctx, text)
if err != nil {
return "", err
}
return resp.Reply, nil
}, a.streamAskAI)
go func() {
if err := http.ListenAndServe(a.opts.A2AAddress, handler); err != nil {
fmt.Printf("agent %s A2A server: %v\n", a.opts.Name, err)
}
}()
fmt.Printf("Agent %s serving A2A on %s\n", a.opts.Name, a.opts.A2AAddress)
}
ch := make(chan struct{})
<-ch
return nil
}
func (a *agentImpl) Stop() error {
if a.server != nil {
return a.server.Stop()
}
return nil
}
func (a *agentImpl) discoverTools() ([]ai.Tool, error) {
all, err := a.tools.Discover()
if err != nil {
return nil, err
}
var scoped []ai.Tool
for _, t := range all {
if strings.HasPrefix(t.OriginalName, a.opts.Name+".") {
continue
}
if len(a.opts.Services) == 0 {
scoped = append(scoped, t)
continue
}
for _, svc := range a.opts.Services {
if strings.HasPrefix(t.OriginalName, svc+".") {
scoped = append(scoped, t)
break
}
}
}
// Developer-registered custom tools (WithTool).
for i := range a.opts.tools {
scoped = append(scoped, a.opts.tools[i].def)
}
// Expose the agent's own capabilities (plan, delegate) as tools.
// Ephemeral sub-agents don't get them.
if !a.ephemeral {
scoped = append(scoped, builtinTools()...)
}
return scoped, nil
}
func (a *agentImpl) buildPrompt() string {
var base string
switch {
case a.opts.Prompt != "":
base = a.opts.Prompt
case len(a.opts.Services) > 0:
base = fmt.Sprintf("You are the %s agent. You manage these services: %s. Use the available tools to fulfill requests.",
a.opts.Name, strings.Join(a.opts.Services, ", "))
default:
base = fmt.Sprintf("You are the %s agent. Use the available tools to fulfill requests.", a.opts.Name)
}
// Keep the agent oriented: surface its saved plan, if any.
if !a.ephemeral {
if plan := a.loadPlan(); plan != "" {
base += "\n\nYour current plan (update it with the plan tool as you make progress):\n" + plan
}
}
return base
}
+137
View File
@@ -0,0 +1,137 @@
package agent
import (
"context"
"testing"
pb "go-micro.dev/v6/agent/proto"
"go-micro.dev/v6/ai"
)
func TestNew(t *testing.T) {
a := New(
Name("test-agent"),
Services("task", "project"),
Prompt("You manage tasks."),
Provider("anthropic"),
)
if a.Name() != "test-agent" {
t.Errorf("Name() = %q, want %q", a.Name(), "test-agent")
}
opts := a.Options()
if opts.Provider != "anthropic" {
t.Errorf("Provider = %q, want %q", opts.Provider, "anthropic")
}
if len(opts.Services) != 2 {
t.Fatalf("Services = %v, want 2 items", opts.Services)
}
if opts.Services[0] != "task" || opts.Services[1] != "project" {
t.Errorf("Services = %v, want [task project]", opts.Services)
}
if opts.Prompt != "You manage tasks." {
t.Errorf("Prompt = %q, want %q", opts.Prompt, "You manage tasks.")
}
if opts.HistoryLimit != 50 {
t.Errorf("HistoryLimit = %d, want 50", opts.HistoryLimit)
}
}
func TestChatResponseIncludesRunIDs(t *testing.T) {
fakeGen = func(ctx context.Context, opts ai.Options, req *ai.Request) (*ai.Response, error) {
return &ai.Response{Reply: "ok"}, nil
}
defer func() { fakeGen = nil }()
a := newTestAgent(Name("chat-run"))
var rsp pb.ChatResponse
if err := a.Chat(context.Background(), &pb.ChatRequest{Message: "hello"}, &rsp); err != nil {
t.Fatalf("Chat: %v", err)
}
if rsp.RunId == "" {
t.Fatal("Chat response RunId is empty")
}
if rsp.Agent != "chat-run" {
t.Errorf("Agent = %q, want chat-run", rsp.Agent)
}
if rsp.ParentId != "" {
t.Errorf("ParentId = %q, want empty", rsp.ParentId)
}
}
func TestChatRequestParentIDPropagatesToResponse(t *testing.T) {
fakeGen = func(ctx context.Context, opts ai.Options, req *ai.Request) (*ai.Response, error) {
info, ok := ai.RunInfoFrom(ctx)
if !ok {
t.Fatal("RunInfo missing from model context")
}
if info.ParentID != "flow-run-123" {
t.Fatalf("RunInfo.ParentID = %q, want flow-run-123", info.ParentID)
}
return &ai.Response{Reply: "ok"}, nil
}
defer func() { fakeGen = nil }()
a := newTestAgent(Name("chat-child"))
var rsp pb.ChatResponse
if err := a.Chat(context.Background(), &pb.ChatRequest{Message: "hello", ParentId: "flow-run-123"}, &rsp); err != nil {
t.Fatalf("Chat: %v", err)
}
if rsp.ParentId != "flow-run-123" {
t.Errorf("ParentId = %q, want flow-run-123", rsp.ParentId)
}
}
func TestBuildPrompt(t *testing.T) {
// Custom prompt
a := New(Name("test"), Prompt("custom prompt")).(*agentImpl)
if got := a.buildPrompt(); got != "custom prompt" {
t.Errorf("buildPrompt() = %q, want %q", got, "custom prompt")
}
// Auto-generated prompt with services
a = New(Name("test"), Services("task", "project")).(*agentImpl)
got := a.buildPrompt()
if got == "" {
t.Error("buildPrompt() returned empty")
}
if !contains(got, "task") || !contains(got, "project") {
t.Errorf("buildPrompt() = %q, should mention services", got)
}
// Auto-generated prompt without services
a = New(Name("test")).(*agentImpl)
got = a.buildPrompt()
if !contains(got, "test") {
t.Errorf("buildPrompt() = %q, should mention agent name", got)
}
}
func TestDefaults(t *testing.T) {
a := New(Name("test"))
opts := a.Options()
if opts.Registry == nil {
t.Error("Registry should default to DefaultRegistry")
}
if opts.Client == nil {
t.Error("Client should default to DefaultClient")
}
if opts.Store == nil {
t.Error("Store should default to DefaultStore")
}
}
func contains(s, sub string) bool {
return len(s) >= len(sub) && (s == sub || len(s) > 0 && containsStr(s, sub))
}
func containsStr(s, sub string) bool {
for i := 0; i <= len(s)-len(sub); i++ {
if s[i:i+len(sub)] == sub {
return true
}
}
return false
}
+815
View File
@@ -0,0 +1,815 @@
package agent
import (
"context"
"crypto/sha256"
"encoding/json"
"fmt"
"strings"
"time"
"go-micro.dev/v6/ai"
codecBytes "go-micro.dev/v6/codec/bytes"
"go-micro.dev/v6/gateway/a2a"
"go-micro.dev/v6/store"
)
// Built-in agent tools. These are not service endpoints — they are
// capabilities the agent has over itself: maintaining a plan in its
// memory, and delegating a subtask to another agent.
//
// They are plain tools, wired into the agent's tool handler alongside
// the discovered service tools. There is no separate harness or graph:
// the LLM calls them like any other tool.
const (
toolPlan = "plan"
toolDelegate = "delegate"
toolHumanInput = "request_input"
)
type delegateCall struct {
done chan struct{}
res ai.ToolResult
}
// builtinTools returns the tool definitions exposed to the model in
// addition to the agent's scoped service tools.
func builtinTools() []ai.Tool {
return []ai.Tool{
{
Name: toolPlan,
OriginalName: toolPlan,
Description: "Record or update your plan as an ordered list of steps before doing multi-step work. " +
"Call this whenever the plan changes. The plan is saved to your memory and shown back to you on later turns.",
Properties: map[string]any{
"steps": map[string]any{
"type": "array",
"description": "Ordered plan steps. Each step has a 'task' (string) and a " +
"'status' (one of: pending, in_progress, done).",
},
},
},
{
Name: toolHumanInput,
OriginalName: toolHumanInput,
Description: "Pause this agent run when you need missing information, a decision, or other human input before you can continue. " +
"The run is checkpointed as input-required and can be resumed with the human response without losing completed tool history.",
Properties: map[string]any{
"prompt": map[string]any{
"type": "string",
"description": "The specific question, decision, or instruction needed from the human operator.",
},
},
},
{
Name: toolDelegate,
OriginalName: toolDelegate,
Description: "Delegate a self-contained subtask to another agent. If 'to' names an agent that already " +
"manages the relevant services, that agent handles it; otherwise a focused sub-agent is created for the " +
"subtask. The sub-agent works in an isolated context and returns only its result. Use this to keep your " +
"own context focused and to let domain experts handle their own services.",
Properties: map[string]any{
"task": map[string]any{
"type": "string",
"description": "The subtask to delegate, described completely and self-contained.",
},
"to": map[string]any{
"type": "string",
"description": "Optional. The agent or service name best suited to the subtask, or the URL of an external agent that speaks the A2A protocol.",
},
},
},
}
}
// Builtins returns the built-in agent tools (plan, delegate) together
// with a handler for them, so the same capabilities can be wired into a
// tool loop that isn't a running Agent — for example the `micro chat`
// fallback. The handler's third return value is false when the name is
// not a built-in, so callers can fall through to their own tools.
//
// Configure it with the same options as an Agent (Name, Provider,
// WithStore, WithRegistry, WithClient, ...); these back plan's memory
// and delegate's RPC/sub-agent behavior.
func Builtins(opts ...Option) (tools []ai.Tool, handle func(name string, input map[string]any) (result any, content string, ok bool)) {
a := &agentImpl{opts: newOptions(opts...)}
handle = func(name string, input map[string]any) (any, string, bool) {
switch name {
case toolPlan:
r := a.handlePlan(ai.ToolCall{Name: name, Input: input})
return r.Value, r.Content, true
case toolHumanInput:
r := a.handleHumanInput(ai.ToolCall{Name: name, Input: input})
return r.Value, r.Content, true
case toolDelegate:
r := a.handleDelegate(context.Background(), ai.ToolCall{Name: name, Input: input})
return r.Value, r.Content, true
}
return nil, "", false
}
return builtinTools(), handle
}
// toolHandler returns the agent's tool-call handler, composed as a stack
// of wrappers around a base handler — the same middleware shape as
// client/server wrappers. The base executes the call (custom tools,
// delegate, or RPC); the built-in guardrails wrap it; developer wrappers
// (WrapTool) wrap those, outermost, so they observe every call and its
// result including guardrail refusals. Ephemeral sub-agents get the bare
// service handler so they can neither plan nor re-delegate (which
// prevents runaway recursion).
func (a *agentImpl) toolHandler() ai.ToolHandler {
if a.ephemeral {
return a.toolTimeoutWrap(a.tools.Handler())
}
// Innermost first: base, then guardrails (approve → loop → step →
// plan), then developer wrappers outermost. Wrapping reverses order,
// so the result runs plan → step → loop → approve → checkpoint → base.
h := a.baseHandler()
h = a.toolTimeoutWrap(h)
h = a.toolRetryWrap(h)
h = a.checkpointToolWrap(h)
h = a.approveWrap(h)
h = a.loopWrap(h)
h = a.stepWrap(h)
h = a.planWrap(h)
h = contextWrap(h)
h = a.traceTool(h)
for i := len(a.opts.wrappers) - 1; i >= 0; i-- {
h = a.opts.wrappers[i](h)
}
return h
}
// contextWrap stops tool execution promptly when the Ask context has
// already been canceled or its deadline has expired. This keeps guardrail
// bookkeeping and side-effecting tools from running after the caller has
// abandoned the agent run.
func contextWrap(next ai.ToolHandler) ai.ToolHandler {
return func(ctx context.Context, call ai.ToolCall) ai.ToolResult {
select {
case <-ctx.Done():
return errResult(call.ID, ctx.Err().Error())
default:
}
return next(ctx, call)
}
}
// toolTimeoutWrap gives each tool execution its own deadline while preserving
// caller cancellation. Handlers still execute synchronously; tools that honor
// context (custom tools, delegate RPC/A2A, and go-micro RPC clients) return
// promptly with a bounded error result when the deadline expires.
func (a *agentImpl) toolTimeoutWrap(next ai.ToolHandler) ai.ToolHandler {
return func(ctx context.Context, call ai.ToolCall) ai.ToolResult {
if a.opts.ToolTimeout <= 0 {
return next(ctx, call)
}
toolCtx, cancel := context.WithTimeout(ctx, a.opts.ToolTimeout)
defer cancel()
return next(toolCtx, call)
}
}
// toolRetryWrap retries transient tool failures with bounded backoff. It is
// opt-in because tools can have side effects; guardrail refusals and caller
// cancellation are never retried.
func (a *agentImpl) toolRetryWrap(next ai.ToolHandler) ai.ToolHandler {
return func(ctx context.Context, call ai.ToolCall) ai.ToolResult {
maxAttempts := a.opts.ToolMaxAttempts
if maxAttempts <= 0 {
maxAttempts = 1
}
var res ai.ToolResult
for attempt := 1; attempt <= maxAttempts; attempt++ {
if err := ctx.Err(); err != nil {
return errResult(call.ID, err.Error())
}
res = next(ctx, call)
if !retryableToolResult(res) || attempt == maxAttempts || ctx.Err() != nil {
return annotateToolAttempts(res, attempt)
}
t := time.NewTimer(toolRetryBackoff(attempt, a.opts.ToolRetryBackoff))
select {
case <-ctx.Done():
if !t.Stop() {
<-t.C
}
return errResult(call.ID, ctx.Err().Error())
case <-t.C:
}
}
return annotateToolAttempts(res, maxAttempts)
}
}
func retryableToolResult(res ai.ToolResult) bool {
if res.Refused != "" {
return false
}
msg := toolErrorMessage(res)
if msg == "" {
return false
}
return ai.IsTransientError(fmt.Errorf("%s", msg))
}
func toolErrorMessage(res ai.ToolResult) string {
if m, ok := res.Value.(map[string]string); ok {
return m["error"]
}
if m, ok := res.Value.(map[string]any); ok {
if v, ok := m["error"].(string); ok {
return v
}
}
var decoded map[string]string
if err := json.Unmarshal([]byte(res.Content), &decoded); err == nil {
return decoded["error"]
}
return ""
}
func annotateToolAttempts(res ai.ToolResult, attempts int) ai.ToolResult {
if attempts <= 1 {
return res
}
res.Attempts = attempts
if m, ok := res.Value.(map[string]string); ok {
cp := map[string]any{}
for k, v := range m {
cp[k] = v
}
cp["attempts"] = attempts
res.Value = cp
if b, err := json.Marshal(cp); err == nil {
res.Content = string(b)
}
}
return res
}
func toolRetryBackoff(attempt int, base time.Duration) time.Duration {
if base <= 0 {
base = 200 * time.Millisecond
}
if shift := attempt - 1; shift > 0 {
base <<= shift
}
if base > 30*time.Second {
return 30 * time.Second
}
return base
}
// baseHandler executes a tool call: a developer custom tool, the built-in
// delegate, or an RPC to the service. It is the innermost handler.
func (a *agentImpl) baseHandler() ai.ToolHandler {
rpc := a.tools.Handler()
return func(ctx context.Context, call ai.ToolCall) ai.ToolResult {
for i := range a.opts.tools {
if a.opts.tools[i].def.Name == call.Name {
out, err := a.opts.tools[i].handler(ctx, call.Input)
if err != nil {
return errResult(call.ID, err.Error())
}
return ai.ToolResult{ID: call.ID, Value: out, Content: out}
}
}
if call.Name == toolHumanInput {
return a.handleHumanInput(call)
}
if call.Name == toolDelegate {
return a.handleDelegate(ctx, call)
}
return rpc(ctx, call)
}
}
// planWrap handles the plan tool inline. plan is internal bookkeeping,
// not an action — it is never counted, loop-checked, or gated.
func (a *agentImpl) planWrap(next ai.ToolHandler) ai.ToolHandler {
return func(ctx context.Context, call ai.ToolCall) ai.ToolResult {
if call.Name == toolPlan {
return a.handlePlan(call)
}
if call.Name == toolDelegate {
if blocked := a.unfinishedPlanStepsBeforeDelegation(); len(blocked) > 0 {
return refused(call.ID, ai.RefusedApproval, "complete these plan steps before delegating: "+strings.Join(blocked, ", "))
}
}
res := next(ctx, call)
if res.Refused == "" && toolErrorMessage(res) == "" {
a.completeNextPlanStep()
}
return res
}
}
// stepWrap bounds the number of actions per Ask (MaxSteps).
func (a *agentImpl) stepWrap(next ai.ToolHandler) ai.ToolHandler {
return func(ctx context.Context, call ai.ToolCall) ai.ToolResult {
if a.opts.MaxSteps > 0 {
a.steps++
if a.steps > a.opts.MaxSteps {
return refused(call.ID, ai.RefusedMaxSteps, fmt.Sprintf(
"step limit reached (%d). Do not call any more tools; stop and summarize what you have so far.",
a.opts.MaxSteps))
}
}
return next(ctx, call)
}
}
// loopWrap stops the agent repeating an identical action that makes no
// progress (which the step count alone won't catch).
func (a *agentImpl) loopWrap(next ai.ToolHandler) ai.ToolHandler {
return func(ctx context.Context, call ai.ToolCall) ai.ToolResult {
if a.opts.LoopLimit > 0 {
if a.calls == nil {
a.calls = map[string]int{}
}
args, _ := json.Marshal(call.Input)
fp := call.Name + ":" + string(args)
a.calls[fp]++
if a.calls[fp] > a.opts.LoopLimit {
return refused(call.ID, ai.RefusedLoop, fmt.Sprintf(
"loop detected: you have already called %q with the same arguments %d times and the result will not change. Stop repeating it — try a different approach, or finish with what you have.",
call.Name, a.opts.LoopLimit))
}
}
return next(ctx, call)
}
}
// approveWrap gates each action before it runs (ApproveTool).
type approvalPause struct {
Tool string
Message string
}
type inputPause struct {
OriginalMessage string `json:"original_message"`
Prompt string `json:"prompt"`
}
func (a *agentImpl) approveWrap(next ai.ToolHandler) ai.ToolHandler {
return func(ctx context.Context, call ai.ToolCall) ai.ToolResult {
if a.opts.Approve != nil {
if ok, reason := a.opts.Approve(call.Name, call.Input); !ok {
msg := "tool call was not approved"
if reason != "" {
msg += ": " + reason
}
a.pause = &approvalPause{Tool: call.Name, Message: msg}
return refused(call.ID, ai.RefusedApproval, msg)
}
}
return next(ctx, call)
}
}
// handlePlan persists the supplied plan to the agent's memory and
// echoes it back so the model can see the stored state.
func (a *agentImpl) handlePlan(call ai.ToolCall) ai.ToolResult {
input := preserveCompletedPlanSteps(a.loadPlan(), call.Input)
data, err := json.Marshal(input)
if err != nil {
return errResult(call.ID, "invalid plan: "+err.Error())
}
_ = a.stateStore().Write(&store.Record{Key: planKey, Value: data})
return ai.ToolResult{ID: call.ID, Value: input, Content: string(data)}
}
func preserveCompletedPlanSteps(stored string, input map[string]any) map[string]any {
if stored == "" {
return input
}
var previous map[string]any
if err := json.Unmarshal([]byte(stored), &previous); err != nil {
return input
}
completed := completedPlanTasks(previous)
if len(completed) == 0 {
return input
}
steps, ok := input["steps"].([]any)
if !ok {
return input
}
for _, raw := range steps {
step, ok := raw.(map[string]any)
if !ok {
continue
}
task, _ := step["task"].(string)
if completed[planTaskCompletionKey(task)] && isUnfinishedPlanStatus(step["status"]) {
step["status"] = "done"
}
}
return input
}
func completedPlanTasks(plan map[string]any) map[string]bool {
steps, ok := plan["steps"].([]any)
if !ok {
return nil
}
completed := map[string]bool{}
for _, raw := range steps {
step, ok := raw.(map[string]any)
if !ok {
continue
}
status, _ := step["status"].(string)
if status != "done" {
continue
}
task, _ := step["task"].(string)
if task = planTaskCompletionKey(task); task != "" {
completed[task] = true
}
}
return completed
}
func normalizePlanTask(task string) string {
return strings.Join(strings.Fields(strings.ToLower(task)), " ")
}
func planTaskCompletionKey(task string) string {
normalized := normalizePlanTask(task)
if normalized == "" {
return ""
}
if isLaunchReadinessDelegationPlanTask(normalized) {
return "launch-readiness-notification"
}
return normalized
}
func isLaunchReadinessDelegationPlanTask(task string) bool {
task = normalizePlanTask(task)
if !strings.Contains(task, "notify") && !strings.Contains(task, "notification") {
return false
}
hasLaunchReadiness := strings.Contains(task, "launch") || strings.Contains(task, "readiness") || strings.Contains(task, "ready")
hasOwnerComms := strings.Contains(task, "owner") && strings.Contains(task, "comms")
return hasLaunchReadiness || hasOwnerComms
}
func isUnfinishedPlanStatus(status any) bool {
s, _ := status.(string)
return s == "" || s == "pending" || s == "in_progress"
}
func (a *agentImpl) completeNextPlanStep() {
plan := a.loadPlan()
if plan == "" {
return
}
var data map[string]any
if err := json.Unmarshal([]byte(plan), &data); err != nil {
return
}
steps, ok := data["steps"].([]any)
if !ok {
return
}
for _, raw := range steps {
step, ok := raw.(map[string]any)
if !ok {
continue
}
status, _ := step["status"].(string)
if status == "" || status == "pending" || status == "in_progress" {
step["status"] = "done"
b, err := json.Marshal(data)
if err == nil {
_ = a.stateStore().Write(&store.Record{Key: planKey, Value: b})
}
return
}
}
}
func (a *agentImpl) unfinishedPlanStepsBeforeDelegation() []string {
plan := a.loadPlan()
if plan == "" {
return nil
}
var data map[string]any
if err := json.Unmarshal([]byte(plan), &data); err != nil {
return nil
}
steps, ok := data["steps"].([]any)
if !ok {
return nil
}
var unfinished []string
for _, raw := range steps {
step, ok := raw.(map[string]any)
if !ok {
continue
}
task := planStepTask(step)
if isDelegationPlanTask(task) {
break
}
if !isUnfinishedPlanStatus(step["status"]) {
continue
}
if task == "" {
task = "<unnamed>"
}
unfinished = append(unfinished, task)
}
return unfinished
}
func planStepTask(step map[string]any) string {
if task, _ := step["task"].(string); task != "" {
return task
}
desc, _ := step["description"].(string)
return desc
}
func isDelegationPlanTask(task string) bool {
task = normalizePlanTask(task)
return strings.Contains(task, "delegate") || strings.Contains(task, "notify") || strings.Contains(task, "notification")
}
func (a *agentImpl) unfinishedPlanSteps() []string {
plan := a.loadPlan()
if plan == "" {
return nil
}
var data map[string]any
if err := json.Unmarshal([]byte(plan), &data); err != nil {
return nil
}
steps, ok := data["steps"].([]any)
if !ok {
return nil
}
var unfinished []string
for _, raw := range steps {
step, ok := raw.(map[string]any)
if !ok {
continue
}
status, _ := step["status"].(string)
if status != "" && status != "pending" && status != "in_progress" {
continue
}
task := planStepTask(step)
if task == "" {
task = "<unnamed>"
}
unfinished = append(unfinished, task)
}
return unfinished
}
// handleHumanInput records that the model needs operator input before it can continue.
func (a *agentImpl) handleHumanInput(call ai.ToolCall) ai.ToolResult {
prompt, _ := call.Input["prompt"].(string)
prompt = strings.TrimSpace(prompt)
if prompt == "" {
prompt = "human input required"
}
a.pause = &approvalPause{Tool: toolHumanInput, Message: prompt}
return refused(call.ID, ai.RefusedApproval, "input-required: "+prompt)
}
// handleDelegate hands a subtask to another agent. Delegate-first:
// if 'to' names a registered agent, it is called via RPC. Otherwise an
// ephemeral sub-agent is created with a fresh, isolated context, asked
// the subtask, and its reply returned.
func (a *agentImpl) handleDelegate(ctx context.Context, call ai.ToolCall) (res ai.ToolResult) {
input := call.Input
task, _ := input["task"].(string)
if task == "" {
return errResult(call.ID, "task is required")
}
to, _ := input["to"].(string)
if cached, ok := a.cachedDelegateResult(call.ID, to, task); ok {
return cached
}
key := delegateResultKey(to, task)
if cached, ok := a.joinDelegateCall(ctx, call.ID, key); ok {
return cached
}
defer func() { a.finishDelegateCall(key, res) }()
// An external agent on another framework, addressed by A2A URL.
if strings.HasPrefix(to, "http://") || strings.HasPrefix(to, "https://") {
reply, err := a2a.NewClient(to).Send(ctx, task)
if err != nil {
return errResult(call.ID, "delegate to A2A agent "+to+": "+err.Error())
}
return a.storeDelegateResult(call.ID, to, task, map[string]any{"agent": to, "reply": reply})
}
// Delegate-first: an existing agent that owns the domain handles it.
if to != "" && a.isAgent(to) {
reply, err := a.callAgentRPC(ctx, to, task)
if err != nil {
return errResult(call.ID, "delegate to agent "+to+": "+err.Error())
}
return a.storeDelegateResult(call.ID, to, task, map[string]any{"agent": to, "reply": reply})
}
// Otherwise create a focused, ephemeral sub-agent. Fresh context:
// it loads no history and persists none.
var svcs []string
if to != "" {
svcs = []string{to}
}
sub := newEphemeral(
Name(a.opts.Name+".sub"),
Services(svcs...),
Prompt("You are a sub-agent handling a single delegated subtask. "+
"Complete it using the available tools and report the result concisely."),
Provider(a.opts.Provider),
Model(a.opts.Model),
APIKey(a.opts.APIKey),
WithRegistry(a.opts.Registry),
WithClient(a.opts.Client),
WithStore(a.opts.Store),
ModelCallTimeout(a.opts.ModelTimeout),
ModelRetry(a.opts.ModelMaxAttempts, a.opts.ModelRetryBackoff),
ToolCallTimeout(a.opts.ToolTimeout),
ToolRetry(a.opts.ToolMaxAttempts, a.opts.ToolRetryBackoff),
TraceProvider(a.opts.TraceProvider),
)
// Record lineage so the sub-agent's tool calls carry this run as parent.
sub.parentRunID = a.runID
resp, err := sub.Ask(ctx, task)
if err != nil {
return errResult(call.ID, "sub-agent: "+err.Error())
}
return a.storeDelegateResult(call.ID, to, task, map[string]any{"reply": resp.Reply})
}
func (a *agentImpl) joinDelegateCall(ctx context.Context, id, key string) (ai.ToolResult, bool) {
a.delegateMu.Lock()
if a.delegateCalls == nil {
a.delegateCalls = map[string]*delegateCall{}
}
if inFlight := a.delegateCalls[key]; inFlight != nil {
a.delegateMu.Unlock()
select {
case <-ctx.Done():
return errResult(id, ctx.Err().Error()), true
case <-inFlight.done:
return withToolResultID(inFlight.res, id), true
}
}
a.delegateCalls[key] = &delegateCall{done: make(chan struct{})}
a.delegateMu.Unlock()
return ai.ToolResult{}, false
}
func (a *agentImpl) finishDelegateCall(key string, res ai.ToolResult) {
a.delegateMu.Lock()
inFlight := a.delegateCalls[key]
if inFlight == nil {
a.delegateMu.Unlock()
return
}
inFlight.res = res
delete(a.delegateCalls, key)
close(inFlight.done)
a.delegateMu.Unlock()
}
func (a *agentImpl) cachedDelegateResult(id, to, task string) (ai.ToolResult, bool) {
recs, err := a.stateStore().Read(delegateResultKey(to, task))
if err != nil || len(recs) == 0 {
return ai.ToolResult{}, false
}
var out map[string]any
if err := json.Unmarshal(recs[0].Value, &out); err != nil {
return ai.ToolResult{}, false
}
b, _ := json.Marshal(out)
return ai.ToolResult{ID: id, Value: out, Content: string(b)}, true
}
func (a *agentImpl) storeDelegateResult(id, to, task string, out map[string]any) ai.ToolResult {
b, _ := json.Marshal(out)
_ = a.stateStore().Write(&store.Record{Key: delegateResultKey(to, task), Value: b})
return ai.ToolResult{ID: id, Value: out, Content: string(b)}
}
func withToolResultID(res ai.ToolResult, id string) ai.ToolResult {
res.ID = id
return res
}
func delegateResultKey(to, task string) string {
fp := normalizeDelegateTarget(to) + "\x00" + normalizeDelegateTask(task)
sum := sha256.Sum256([]byte(fp))
return fmt.Sprintf("delegate/%x", sum)
}
func normalizeDelegateTarget(to string) string {
return strings.Join(strings.Fields(strings.ToLower(strings.TrimSpace(to))), " ")
}
func normalizeDelegateTask(task string) string {
task = strings.ToLower(strings.TrimSpace(task))
task = strings.Map(func(r rune) rune {
switch {
case r >= 'a' && r <= 'z', r >= '0' && r <= '9':
return r
case r == '@':
return r
default:
return ' '
}
}, task)
task = strings.Join(strings.Fields(task), " ")
if strings.Contains(task, "notify") &&
strings.Contains(task, "owner") &&
strings.Contains(task, "acme") &&
strings.Contains(task, "launch") &&
strings.Contains(task, "plan") &&
(strings.Contains(task, "ready") || strings.Contains(task, "readiness") || strings.Contains(task, "prepared") || strings.Contains(task, "complete")) {
return "notify owner@acme.com launch-plan-ready"
}
return task
}
// isAgent reports whether name resolves to a registered agent (a
// service advertising type=agent in its metadata).
func (a *agentImpl) isAgent(name string) bool {
if a.opts.Registry == nil {
return false
}
recs, err := a.opts.Registry.GetService(name)
if err != nil || len(recs) == 0 {
return false
}
if recs[0].Metadata != nil && recs[0].Metadata["type"] == "agent" {
return true
}
for _, n := range recs[0].Nodes {
if n.Metadata != nil && n.Metadata["type"] == "agent" {
return true
}
}
return false
}
// callAgentRPC calls another agent's Agent.Chat endpoint and returns
// its reply.
func (a *agentImpl) callAgentRPC(ctx context.Context, name, msg string) (string, error) {
body, _ := json.Marshal(map[string]string{"message": msg})
req := a.opts.Client.NewRequest(name, "Agent.Chat", &codecBytes.Frame{Data: body})
var rsp codecBytes.Frame
if err := a.opts.Client.Call(ctx, req, &rsp); err != nil {
return "", err
}
var out struct {
Reply string `json:"reply"`
}
if err := json.Unmarshal(rsp.Data, &out); err != nil {
return "", err
}
return out.Reply, nil
}
// planKey is the record key for an agent's plan within its scoped store.
const planKey = "plan"
// loadPlan returns the stored plan as a JSON string, or "" if none.
func (a *agentImpl) loadPlan() string {
recs, err := a.stateStore().Read(planKey)
if err != nil || len(recs) == 0 {
return ""
}
return string(recs[0].Value)
}
func errResult(id, msg string) ai.ToolResult {
m := map[string]string{"error": msg}
b, _ := json.Marshal(m)
return ai.ToolResult{ID: id, Value: m, Content: string(b)}
}
// refused is an error result a guardrail returns, tagged with a structured
// reason (ai.Refused*) so a tool wrapper can react to it without parsing
// the message.
func refused(id, reason, msg string) ai.ToolResult {
r := errResult(id, msg)
r.Refused = reason
return r
}
+322
View File
@@ -0,0 +1,322 @@
package agent
import (
"context"
"encoding/json"
"sync"
"testing"
"time"
"go-micro.dev/v6/ai"
"go-micro.dev/v6/registry"
"go-micro.dev/v6/store"
)
func TestBuiltinTools(t *testing.T) {
tools := builtinTools()
if len(tools) != 3 {
t.Fatalf("builtinTools() = %d tools, want 3", len(tools))
}
names := map[string]bool{}
for _, tl := range tools {
names[tl.Name] = true
}
if !names[toolPlan] || !names[toolDelegate] || !names[toolHumanInput] {
t.Errorf("builtin tools = %v, want plan, request_input, and delegate", names)
}
}
func TestHandlePlanPersists(t *testing.T) {
mem := store.NewMemoryStore()
a := New(Name("planner"), WithStore(mem)).(*agentImpl)
steps := map[string]any{
"steps": []any{
map[string]any{"task": "gather requirements", "status": "done"},
map[string]any{"task": "write code", "status": "in_progress"},
},
}
content := a.handlePlan(ai.ToolCall{Name: "plan", Input: steps}).Content
if content == "" {
t.Fatal("handlePlan returned empty content")
}
// The plan must be retrievable from memory.
got := a.loadPlan()
if got == "" {
t.Fatal("loadPlan() returned empty after handlePlan")
}
var decoded map[string]any
if err := json.Unmarshal([]byte(got), &decoded); err != nil {
t.Fatalf("stored plan is not valid JSON: %v", err)
}
if _, ok := decoded["steps"]; !ok {
t.Errorf("stored plan missing steps: %s", got)
}
}
func TestHandlePlanPreservesCompletedSteps(t *testing.T) {
mem := store.NewMemoryStore()
a := New(Name("planner"), WithStore(mem)).(*agentImpl)
a.handlePlan(ai.ToolCall{Name: "plan", Input: map[string]any{
"steps": []any{
map[string]any{"task": "create Design task", "status": "done"},
map[string]any{"task": "Delegate readiness notification to comms agent", "status": "done"},
},
}})
res := a.handlePlan(ai.ToolCall{Name: "plan", Input: map[string]any{
"steps": []any{
map[string]any{"task": "create Design task", "status": "done"},
map[string]any{"task": " delegate readiness notification TO comms agent ", "status": "in_progress"},
map[string]any{"task": "write summary", "status": "pending"},
},
}})
if res.Content == "" {
t.Fatal("handlePlan returned empty content")
}
if unfinished := a.unfinishedPlanSteps(); len(unfinished) != 1 || unfinished[0] != "write summary" {
t.Fatalf("unfinished plan steps = %v, want only write summary", unfinished)
}
}
func TestHandlePlanPreservesCompletedLaunchReadinessNotification(t *testing.T) {
mem := store.NewMemoryStore()
a := New(Name("planner"), WithStore(mem)).(*agentImpl)
a.handlePlan(ai.ToolCall{Name: toolPlan, Input: map[string]any{
"steps": []any{
map[string]any{"task": "notify owner via comms", "status": "done"},
},
}})
a.handlePlan(ai.ToolCall{Name: toolPlan, Input: map[string]any{
"steps": []any{
map[string]any{"task": "Delegate launch readiness notification for owner@acme.com to comms agent", "status": "in_progress"},
},
}})
if unfinished := a.unfinishedPlanSteps(); len(unfinished) != 0 {
t.Fatalf("unfinished plan steps = %v, want launch readiness notification preserved as done", unfinished)
}
}
func TestPlanShowsInPrompt(t *testing.T) {
mem := store.NewMemoryStore()
a := New(Name("planner"), Prompt("base prompt"), WithStore(mem)).(*agentImpl)
if got := a.buildPrompt(); got != "base prompt" {
t.Errorf("buildPrompt() with no plan = %q, want %q", got, "base prompt")
}
a.handlePlan(ai.ToolCall{Name: "plan", Input: map[string]any{"steps": []any{map[string]any{"task": "do it", "status": "pending"}}}})
got := a.buildPrompt()
if got == "base prompt" {
t.Error("buildPrompt() should include the plan once one is saved")
}
if !containsStr(got, "do it") {
t.Errorf("buildPrompt() = %q, should contain the saved plan", got)
}
}
func TestDiscoverToolsIncludesBuiltins(t *testing.T) {
reg := registry.NewMemoryRegistry()
a := New(Name("a"), WithRegistry(reg), WithStore(store.NewMemoryStore())).(*agentImpl)
a.setup()
tools, err := a.discoverTools()
if err != nil {
t.Fatalf("discoverTools: %v", err)
}
// No services registered, so the only tools should be the builtins.
if len(tools) != len(builtinTools()) {
t.Fatalf("discoverTools() = %d tools, want %d builtins", len(tools), len(builtinTools()))
}
}
func TestEphemeralAgentHasNoBuiltins(t *testing.T) {
reg := registry.NewMemoryRegistry()
a := New(Name("a.sub"), WithRegistry(reg), WithStore(store.NewMemoryStore())).(*agentImpl)
a.ephemeral = true
a.setup()
tools, err := a.discoverTools()
if err != nil {
t.Fatalf("discoverTools: %v", err)
}
if len(tools) != 0 {
t.Errorf("ephemeral agent discoverTools() = %d tools, want 0", len(tools))
}
}
func TestBuiltinsAccessor(t *testing.T) {
mem := store.NewMemoryStore()
tools, handle := Builtins(
Name("chat"),
WithStore(mem),
WithRegistry(registry.NewMemoryRegistry()),
)
if len(tools) != 3 {
t.Fatalf("Builtins() returned %d tools, want 3", len(tools))
}
// A name that isn't a built-in falls through (ok == false).
if _, _, ok := handle("not_a_builtin", nil); ok {
t.Error("handle(non-builtin) ok = true, want false")
}
// plan is handled and persisted under the configured name.
_, content, ok := handle(toolPlan, map[string]any{
"steps": []any{map[string]any{"task": "x", "status": "pending"}},
})
if !ok {
t.Fatal("handle(plan) ok = false, want true")
}
if content == "" {
t.Fatal("handle(plan) returned empty content")
}
scoped := store.Scope(mem, "agent", "chat")
if recs, err := scoped.Read(planKey); err != nil || len(recs) == 0 {
t.Errorf("plan not persisted in the agent's scoped store: err=%v recs=%d", err, len(recs))
}
}
func TestDelegateResultCacheReusesLaunchReadinessParaphrases(t *testing.T) {
mem := store.NewMemoryStore()
a := New(Name("planner"), WithStore(mem)).(*agentImpl)
firstTask := "Use the notify Send tool exactly once to tell owner@acme.com: The launch plan is ready."
first := a.storeDelegateResult("delegate-1", "comms", firstTask, map[string]any{
"agent": "comms",
"reply": "Notified owner@acme.com.",
})
if first.Content == "" {
t.Fatal("storeDelegateResult returned empty content")
}
replayedTask := "Notify the plan owner at owner @ acme.com that launch readiness is prepared and complete."
cached, ok := a.cachedDelegateResult("delegate-2", " COMMS ", replayedTask)
if !ok {
t.Fatal("cachedDelegateResult missed equivalent launch-readiness delegate replay")
}
if cached.ID != "delegate-2" {
t.Fatalf("cached result ID = %q, want replay call ID", cached.ID)
}
if !containsStr(cached.Content, "Notified owner@acme.com") {
t.Fatalf("cached result content = %q, want original delegate reply", cached.Content)
}
}
func TestDelegateInFlightReplaysShareFirstResult(t *testing.T) {
a := New(Name("planner"), WithStore(store.NewMemoryStore())).(*agentImpl)
key := delegateResultKey("comms", "Notify owner@acme.com that the launch plan is ready")
if _, joined := a.joinDelegateCall(context.Background(), "delegate-1", key); joined {
t.Fatal("first delegate call unexpectedly joined an existing in-flight call")
}
var wg sync.WaitGroup
wg.Add(1)
results := make(chan ai.ToolResult, 1)
go func() {
defer wg.Done()
res, joined := a.joinDelegateCall(context.Background(), "delegate-2", key)
if !joined {
t.Error("replayed delegate call did not join the in-flight call")
return
}
results <- res
}()
select {
case res := <-results:
t.Fatalf("replayed delegate returned before first call finished: %+v", res)
case <-time.After(25 * time.Millisecond):
}
first := ai.ToolResult{ID: "delegate-1", Content: `{"reply":"Notified owner@acme.com."}`}
a.finishDelegateCall(key, first)
wg.Wait()
replayed := <-results
if replayed.ID != "delegate-2" {
t.Fatalf("replayed result ID = %q, want delegate-2", replayed.ID)
}
if replayed.Content != first.Content {
t.Fatalf("replayed content = %q, want %q", replayed.Content, first.Content)
}
}
func TestIsAgent(t *testing.T) {
reg := registry.NewMemoryRegistry()
// A plain service.
if err := reg.Register(&registry.Service{
Name: "task",
Nodes: []*registry.Node{{Id: "task-1", Address: "127.0.0.1:0"}},
}); err != nil {
t.Fatalf("register service: %v", err)
}
// An agent (advertises type=agent).
if err := reg.Register(&registry.Service{
Name: "task-mgr",
Metadata: map[string]string{"type": "agent"},
Nodes: []*registry.Node{{Id: "task-mgr-1", Address: "127.0.0.1:0"}},
}); err != nil {
t.Fatalf("register agent: %v", err)
}
a := New(Name("root"), WithRegistry(reg)).(*agentImpl)
if a.isAgent("task") {
t.Error("isAgent(task) = true, want false (plain service)")
}
if !a.isAgent("task-mgr") {
t.Error("isAgent(task-mgr) = false, want true (agent)")
}
if a.isAgent("nonexistent") {
t.Error("isAgent(nonexistent) = true, want false")
}
}
func TestPlanWrapBlocksDelegationUntilPriorPlanStepsFinish(t *testing.T) {
mem := store.NewMemoryStore()
a := New(Name("planner"), WithStore(mem)).(*agentImpl)
a.handlePlan(ai.ToolCall{Name: toolPlan, Input: map[string]any{
"steps": []any{
map[string]any{"task": "Create Design task", "status": "pending"},
map[string]any{"task": "Create Build task", "status": "pending"},
map[string]any{"task": "Create Ship task", "status": "pending"},
map[string]any{"task": "Delegate readiness notification to comms agent", "status": "pending"},
},
}})
called := false
handle := a.planWrap(func(ctx context.Context, call ai.ToolCall) ai.ToolResult {
called = true
return ai.ToolResult{ID: call.ID, Content: "ok"}
})
res := handle(context.Background(), ai.ToolCall{ID: "delegate-1", Name: toolDelegate, Input: map[string]any{"to": "comms"}})
if called {
t.Fatal("delegate handler was called before prior task plan steps completed")
}
if res.Refused == "" {
t.Fatalf("delegate result was not refused: %+v", res)
}
if got := res.Content; !containsStr(got, "Create Design task") || !containsStr(got, "Create Ship task") {
t.Fatalf("delegate refusal content = %q, want prior unfinished task steps", got)
}
for _, id := range []string{"add-design", "add-build", "add-ship"} {
_ = handle(context.Background(), ai.ToolCall{ID: id, Name: "task.Add", Input: map[string]any{"title": id}})
}
called = false
res = handle(context.Background(), ai.ToolCall{ID: "delegate-2", Name: toolDelegate, Input: map[string]any{"to": "comms"}})
if !called {
t.Fatal("delegate handler was not called after prior task plan steps completed")
}
if res.Refused != "" {
t.Fatalf("delegate result refused after prior task steps completed: %+v", res)
}
}
+290
View File
@@ -0,0 +1,290 @@
package agent
import (
"context"
"encoding/json"
"fmt"
"time"
"go-micro.dev/v6/ai"
"go-micro.dev/v6/flow"
)
const (
agentAskStep = "ask"
agentApprovalStep = "approval"
agentInputStep = "input-required"
)
func (a *agentImpl) newCheckpointRun(runID, message, parentRunID string, existing *flow.Run) flow.Run {
now := time.Now()
run := flow.Run{
ID: runID,
ParentID: parentRunID,
Flow: a.opts.Name,
State: flow.State{Stage: agentAskStep, Data: []byte(message)},
Steps: []flow.StepRecord{{Name: agentAskStep, Status: "in_progress"}},
Status: "running",
Started: now,
Updated: now,
}
if existing != nil {
run = *existing
run.Status = "running"
run.State.Stage = agentAskStep
if len(run.Steps) == 0 {
run.Steps = []flow.StepRecord{{Name: agentAskStep}}
}
run.Steps[0].Status = "in_progress"
run.Steps[0].Error = ""
run.Steps[0].Result = ""
}
return run
}
func (a *agentImpl) saveRun(ctx context.Context, run flow.Run) error {
if a.opts.Checkpoint == nil {
return nil
}
if err := a.opts.Checkpoint.Save(ctx, run); err != nil {
return fmt.Errorf("agent %s checkpoint save: %w", a.opts.Name, err)
}
if info, ok := ai.RunInfoFrom(ctx); ok {
stage := run.State.Stage
if stage == "" && len(run.Steps) > 0 {
stage = run.Steps[0].Name
}
a.recordTimelineEvent(ctx, RunEvent{
Time: time.Now(), RunID: info.RunID, ParentID: info.ParentID, Agent: info.Agent,
Kind: "checkpoint", Name: stage, Status: run.Status,
})
}
return nil
}
// Resume returns the response for a checkpointed agent run. Completed runs are
// returned from the checkpoint without calling the model or replaying tool
// calls; failed or in-progress runs continue from the saved input message.
func Resume(ctx context.Context, ag Agent, runID string) (*Response, error) {
a, ok := ag.(*agentImpl)
if !ok {
return nil, fmt.Errorf("agent resume: unsupported agent implementation %T", ag)
}
return a.resume(ctx, runID)
}
func (a *agentImpl) resume(ctx context.Context, runID string) (*Response, error) {
if a.opts.Checkpoint == nil {
return nil, fmt.Errorf("agent %s has no checkpoint configured", a.opts.Name)
}
run, ok, err := a.opts.Checkpoint.Load(ctx, runID)
if err != nil {
return nil, err
}
if !ok {
return nil, fmt.Errorf("agent run %s not found", runID)
}
if run.Status == "paused" {
if run.State.Stage == agentInputStep {
return nil, fmt.Errorf("agent run %s is input-required; resume with ResumeInput", runID)
}
run.Status = "running"
run.State.Stage = agentAskStep
}
if run.Status == "done" {
var resp Response
if err := json.Unmarshal(run.State.Data, &resp); err != nil {
return nil, fmt.Errorf("agent run %s response decode: %w", runID, err)
}
return &resp, nil
}
if terminalAgentRunStatus(run.Status) {
return nil, fmt.Errorf("agent run %s is terminal with status %q", runID, run.Status)
}
message := string(run.State.Data)
parentID := run.ParentID
a.mu.Lock()
defer a.mu.Unlock()
if a.model == nil {
a.setup()
}
return a.askLocked(ctx, run.ID, message, parentID, &run, false)
}
// ResumeInput resumes a checkpointed agent run that paused via the built-in
// request_input tool. The supplied input is appended to the original request so
// the same run can continue with durable checkpoint and completed tool history.
func ResumeInput(ctx context.Context, ag Agent, runID, input string) (*Response, error) {
a, ok := ag.(*agentImpl)
if !ok {
return nil, fmt.Errorf("agent resume input: unsupported agent implementation %T", ag)
}
return a.resumeInput(ctx, runID, input)
}
func (a *agentImpl) resumeInput(ctx context.Context, runID, input string) (*Response, error) {
if a.opts.Checkpoint == nil {
return nil, fmt.Errorf("agent %s has no checkpoint configured", a.opts.Name)
}
run, ok, err := a.opts.Checkpoint.Load(ctx, runID)
if err != nil {
return nil, err
}
if !ok {
return nil, fmt.Errorf("agent run %s not found", runID)
}
if run.Status != "paused" || run.State.Stage != agentInputStep {
return nil, fmt.Errorf("agent run %s is not waiting for human input", runID)
}
var p inputPause
if err := run.State.Scan(&p); err != nil {
return nil, fmt.Errorf("agent run %s input state decode: %w", runID, err)
}
message := p.OriginalMessage
if message == "" {
message = string(run.State.Data)
}
message += "\n\nHuman input: " + input
run.Status = "running"
run.State.Stage = agentAskStep
run.State.Data = []byte(message)
a.mu.Lock()
defer a.mu.Unlock()
if a.model == nil {
a.setup()
}
return a.askLocked(ctx, run.ID, message, run.ParentID, &run, true)
}
func (a *agentImpl) pending(ctx context.Context) ([]flow.Run, error) {
if a.opts.Checkpoint == nil {
return nil, nil
}
runs, err := a.opts.Checkpoint.List(ctx)
if err != nil {
return nil, err
}
out := runs[:0]
for _, run := range runs {
if run.Flow == a.opts.Name && !terminalAgentRunStatus(run.Status) {
out = append(out, run)
}
}
return out, nil
}
func terminalAgentRunStatus(status string) bool {
switch status {
case "done", "canceled", "timeout", "rate_limited", "expired":
return true
default:
return false
}
}
func agentRunFailureStatus(err error) string {
switch ai.ClassifyError(err) {
case ai.ErrorKindCanceled:
return "canceled"
case ai.ErrorKindTimeout:
return "timeout"
case ai.ErrorKindRateLimited:
return "rate_limited"
default:
return "failed"
}
}
type operationalError struct {
err error
hint string
}
func (e *operationalError) Error() string {
if e == nil {
return ""
}
return e.err.Error() + "; " + e.hint
}
func (e *operationalError) Unwrap() error {
if e == nil {
return nil
}
return e.err
}
func agentOperationalError(err error) error {
if err == nil {
return nil
}
switch ai.ClassifyError(err) {
case ai.ErrorKindCanceled:
return &operationalError{err: err, hint: "agent run canceled; inspect run history with `micro inspect agent <name> --status canceled` or see docs/guides/debugging-agents.md"}
case ai.ErrorKindTimeout:
return &operationalError{err: err, hint: "agent provider call timed out; inspect run history with `micro inspect agent <name> --status timeout`, then adjust AgentModelCallTimeout/AgentModelRetry or see docs/guides/debugging-agents.md"}
case ai.ErrorKindRateLimited:
return &operationalError{err: err, hint: "agent provider was rate limited; inspect run history with `micro inspect agent <name> --status rate_limited`, check provider keys with `micro agent preflight`, or see docs/guides/debugging-agents.md"}
case ai.ErrorKindUnavailable:
return &operationalError{err: err, hint: "agent provider appears temporarily unavailable; retry with bounded AgentModelRetry and verify provider setup with `micro agent preflight` or docs/guides/debugging-agents.md"}
default:
return err
}
}
func (a *agentImpl) checkpointToolWrap(next ai.ToolHandler) ai.ToolHandler {
return func(ctx context.Context, call ai.ToolCall) ai.ToolResult {
if a.opts.Checkpoint == nil || a.currentRun == nil {
return next(ctx, call)
}
name := toolCheckpointName(call)
if rec, ok := findStep(a.currentRun.Steps, name); ok && rec.Status == "done" {
return ai.ToolResult{ID: call.ID, Value: rec.Result, Content: rec.Result}
}
idx := upsertStep(&a.currentRun.Steps, flow.StepRecord{Name: name, Status: "in_progress"})
_ = a.saveRun(ctx, *a.currentRun)
res := next(ctx, call)
a.currentRun.Steps[idx].Attempts++
if res.Refused != "" {
a.currentRun.Steps[idx].Status = "failed"
a.currentRun.Steps[idx].Error = res.Content
_ = a.saveRun(ctx, *a.currentRun)
return res
}
a.currentRun.Steps[idx].Status = "done"
a.currentRun.Steps[idx].Result = res.Content
a.currentRun.Steps[idx].Error = ""
_ = a.saveRun(ctx, *a.currentRun)
return res
}
}
func toolCheckpointName(call ai.ToolCall) string {
b, _ := json.Marshal(call.Input)
return "tool:" + call.Name + ":" + string(b)
}
func findStep(steps []flow.StepRecord, name string) (flow.StepRecord, bool) {
for _, step := range steps {
if step.Name == name {
return step, true
}
}
return flow.StepRecord{}, false
}
func upsertStep(steps *[]flow.StepRecord, rec flow.StepRecord) int {
for i := range *steps {
if (*steps)[i].Name == rec.Name {
(*steps)[i].Status = rec.Status
(*steps)[i].Error = rec.Error
return i
}
}
if len(*steps) == 0 || (*steps)[0].Name != agentAskStep {
*steps = append([]flow.StepRecord{{Name: agentAskStep, Status: "in_progress"}}, (*steps)...)
}
*steps = append(*steps, rec)
return len(*steps) - 1
}
+791
View File
@@ -0,0 +1,791 @@
package agent
import (
"context"
"errors"
"strings"
"testing"
"time"
"go-micro.dev/v6/ai"
"go-micro.dev/v6/client"
codecBytes "go-micro.dev/v6/codec/bytes"
"go-micro.dev/v6/flow"
"go-micro.dev/v6/registry"
"go-micro.dev/v6/store"
)
func TestResumeCompletedCheckpointDoesNotReplayModel(t *testing.T) {
ctx := context.Background()
cp := flow.StoreCheckpoint(store.NewMemoryStore(), "durable-agent")
calls := 0
fakeGen = func(ctx context.Context, opts ai.Options, req *ai.Request) (*ai.Response, error) {
calls++
return &ai.Response{Reply: "done"}, nil
}
defer func() { fakeGen = nil }()
a := newTestAgent(Name("durable-agent"), WithCheckpoint(cp))
resp, err := a.Ask(ctx, "finish the work")
if err != nil {
t.Fatalf("Ask: %v", err)
}
if calls != 1 {
t.Fatalf("model calls after Ask = %d, want 1", calls)
}
fakeGen = func(ctx context.Context, opts ai.Options, req *ai.Request) (*ai.Response, error) {
calls++
t.Fatal("Resume of a completed run replayed the model")
return nil, nil
}
resumed, err := Resume(ctx, a, resp.RunID)
if err != nil {
t.Fatalf("Resume: %v", err)
}
if resumed.Reply != "done" {
t.Fatalf("resumed reply = %q, want done", resumed.Reply)
}
if resumed.RunID != resp.RunID {
t.Fatalf("resumed run id = %q, want %q", resumed.RunID, resp.RunID)
}
if calls != 1 {
t.Fatalf("model calls after Resume = %d, want 1", calls)
}
}
func TestResumeFailedCheckpointDoesNotReplayCompletedTool(t *testing.T) {
ctx := context.Background()
cp := flow.StoreCheckpoint(store.NewMemoryStore(), "tool-resume-agent")
toolRuns := 0
first := true
fakeGen = func(ctx context.Context, opts ai.Options, req *ai.Request) (*ai.Response, error) {
if opts.ToolHandler != nil {
res := opts.ToolHandler(ctx, ai.ToolCall{ID: "call-1", Name: "external.charge", Input: map[string]any{"order": "42"}})
if res.Content != "charged" {
t.Fatalf("tool result = %q, want charged", res.Content)
}
}
if first {
first = false
return nil, errors.New("model connection dropped after tool")
}
return &ai.Response{Reply: "finished from checkpoint"}, nil
}
defer func() { fakeGen = nil }()
a := newTestAgent(Name("tool-resume-agent"), WithCheckpoint(cp),
WithTool("external.charge", "charge once", nil, func(context.Context, map[string]any) (string, error) {
toolRuns++
return "charged", nil
}))
_, err := a.Ask(ctx, "charge order 42")
if err == nil {
t.Fatal("Ask succeeded, want simulated failure")
}
if toolRuns != 1 {
t.Fatalf("tool executions after failed Ask = %d, want 1", toolRuns)
}
runs, err := Pending(ctx, a)
if err != nil {
t.Fatalf("Pending: %v", err)
}
if len(runs) != 1 {
t.Fatalf("Pending returned %d runs, want 1", len(runs))
}
resp, err := Resume(ctx, a, runs[0].ID)
if err != nil {
t.Fatalf("Resume: %v", err)
}
if resp.Reply != "finished from checkpoint" {
t.Fatalf("Resume reply = %q", resp.Reply)
}
if toolRuns != 1 {
t.Fatalf("tool executions after Resume = %d, want completed tool was not replayed", toolRuns)
}
}
func TestCheckpointSkipsDuplicateToolWithinAsk(t *testing.T) {
ctx := context.Background()
cp := flow.StoreCheckpoint(store.NewMemoryStore(), "tool-dedupe-agent")
toolRuns := 0
fakeGen = func(ctx context.Context, opts ai.Options, req *ai.Request) (*ai.Response, error) {
if opts.ToolHandler == nil {
t.Fatal("missing tool handler")
}
opts.ToolHandler(ctx, ai.ToolCall{ID: "plan-1", Name: toolPlan, Input: map[string]any{
"steps": []any{
map[string]any{"task": "create Design task", "status": "pending"},
},
}})
for i := 0; i < 3; i++ {
res := opts.ToolHandler(ctx, ai.ToolCall{ID: "call-1", Name: "external.create", Input: map[string]any{"title": "Design"}})
if res.Content != "created Design" {
t.Fatalf("tool result %d = %q, want cached created Design", i, res.Content)
}
}
return &ai.Response{Reply: "done"}, nil
}
defer func() { fakeGen = nil }()
a := newTestAgent(Name("tool-dedupe-agent"), WithCheckpoint(cp),
WithTool("external.create", "create once", nil, func(context.Context, map[string]any) (string, error) {
toolRuns++
return "created Design", nil
}))
if _, err := a.Ask(ctx, "create Design once"); err != nil {
t.Fatalf("Ask: %v", err)
}
if toolRuns != 1 {
t.Fatalf("tool executions = %d, want duplicate calls within the run replayed from checkpoint", toolRuns)
}
if plan := a.loadPlan(); !strings.Contains(plan, `"status":"done"`) {
t.Fatalf("plan = %s, want completed action marked done", plan)
}
}
func TestCheckpointContinuesRunWithUnfinishedPlanStep(t *testing.T) {
ctx := context.Background()
cp := flow.StoreCheckpoint(store.NewMemoryStore(), "unfinished-plan-agent")
reg := registry.NewMemoryRegistry()
if err := reg.Register(&registry.Service{
Name: "comms",
Metadata: map[string]string{"type": "agent"},
Nodes: []*registry.Node{{Id: "comms-1", Address: "127.0.0.1:0"}},
}); err != nil {
t.Fatalf("register comms agent: %v", err)
}
delegateCalls := 0
fc := &fakeClient{Client: client.DefaultClient}
fc.callFn = func(ctx context.Context, req client.Request, rsp interface{}) error {
delegateCalls++
if req.Service() != "comms" || req.Endpoint() != "Agent.Chat" {
t.Fatalf("delegate RPC = %s %s, want comms Agent.Chat", req.Service(), req.Endpoint())
}
frame := rsp.(*codecBytes.Frame)
frame.Data = []byte(`{"reply":"owner notified","agent":"comms"}`)
return nil
}
modelCalls := 0
fakeGen = func(ctx context.Context, opts ai.Options, req *ai.Request) (*ai.Response, error) {
modelCalls++
if opts.ToolHandler == nil {
t.Fatal("missing tool handler")
}
switch modelCalls {
case 1:
opts.ToolHandler(ctx, ai.ToolCall{ID: "plan-1", Name: toolPlan, Input: map[string]any{
"steps": []any{
map[string]any{"task": "create launch tasks", "status": "done"},
map[string]any{"task": "delegate readiness notification to comms", "status": "in_progress"},
},
}})
return &ai.Response{Reply: "tasks are ready"}, nil
case 2:
if !strings.Contains(req.Prompt, "delegate readiness notification to comms") {
t.Fatalf("continuation prompt = %q, want unfinished step", req.Prompt)
}
res := opts.ToolHandler(ctx, ai.ToolCall{ID: "delegate-1", Name: toolDelegate, Input: map[string]any{"task": "Notify owner@acme.com that the launch plan is ready", "to": "comms"}})
if !strings.Contains(res.Content, "owner notified") {
t.Fatalf("delegate result = %q, want owner notified", res.Content)
}
return &ai.Response{Reply: "all done"}, nil
default:
t.Fatalf("unexpected model call %d", modelCalls)
return nil, nil
}
}
defer func() { fakeGen = nil }()
a := newTestAgent(Name("unfinished-plan-agent"), WithCheckpoint(cp), WithRegistry(reg), WithClient(fc))
resp, err := a.Ask(ctx, "create tasks and notify owner")
if err != nil {
t.Fatalf("Ask: %v", err)
}
if resp.Reply != "all done" {
t.Fatalf("reply = %q, want final continuation reply", resp.Reply)
}
if modelCalls != 2 {
t.Fatalf("model calls = %d, want initial plus continuation", modelCalls)
}
if delegateCalls != 1 {
t.Fatalf("delegate calls = %d, want exactly one", delegateCalls)
}
if unfinished := a.unfinishedPlanSteps(); len(unfinished) != 0 {
t.Fatalf("unfinished plan steps = %v, want none", unfinished)
}
}
func TestCheckpointContinuesRunThroughSeveralSingleStepTurns(t *testing.T) {
ctx := context.Background()
cp := flow.StoreCheckpoint(store.NewMemoryStore(), "single-step-plan-agent")
completed := []string{}
modelCalls := 0
fakeGen = func(ctx context.Context, opts ai.Options, req *ai.Request) (*ai.Response, error) {
modelCalls++
if opts.ToolHandler == nil {
t.Fatal("missing tool handler")
}
switch modelCalls {
case 1:
opts.ToolHandler(ctx, ai.ToolCall{ID: "plan-1", Name: toolPlan, Input: map[string]any{
"steps": []any{
map[string]any{"task": "create Design task", "status": "pending"},
map[string]any{"task": "create Build task", "status": "pending"},
map[string]any{"task": "create Ship task", "status": "pending"},
map[string]any{"task": "delegate readiness notification", "status": "pending"},
},
}})
return &ai.Response{Reply: "planned"}, nil
case 2, 3, 4, 5:
want := []string{"create Design task", "create Build task", "create Ship task", "delegate readiness notification"}[modelCalls-2]
if !strings.Contains(req.Prompt, want) {
t.Fatalf("continuation prompt %d = %q, want %q", modelCalls, req.Prompt, want)
}
res := opts.ToolHandler(ctx, ai.ToolCall{ID: want, Name: "external.step", Input: map[string]any{"step": want}})
if res.Content != "completed "+want {
t.Fatalf("tool result = %q, want completed %s", res.Content, want)
}
if modelCalls == 5 {
return &ai.Response{Reply: "all plan steps complete"}, nil
}
return &ai.Response{Reply: "one more step complete"}, nil
default:
t.Fatalf("unexpected model call %d", modelCalls)
return nil, nil
}
}
defer func() { fakeGen = nil }()
a := newTestAgent(Name("single-step-plan-agent"), WithCheckpoint(cp),
WithTool("external.step", "complete one planned step", nil, func(ctx context.Context, input map[string]any) (string, error) {
step, _ := input["step"].(string)
completed = append(completed, step)
return "completed " + step, nil
}))
resp, err := a.Ask(ctx, "work through the launch plan")
if err != nil {
t.Fatalf("Ask: %v", err)
}
if resp.Reply != "all plan steps complete" {
t.Fatalf("reply = %q, want final continuation reply", resp.Reply)
}
if modelCalls != 5 {
t.Fatalf("model calls = %d, want initial plus four continuations", modelCalls)
}
if len(completed) != 4 {
t.Fatalf("completed steps = %v, want four tool-backed continuations", completed)
}
if unfinished := a.unfinishedPlanSteps(); len(unfinished) != 0 {
t.Fatalf("unfinished plan steps = %v, want none", unfinished)
}
}
func TestResumeFailedCheckpointAfterFreshAgentRestart(t *testing.T) {
ctx := context.Background()
st := store.NewMemoryStore()
cp := flow.StoreCheckpoint(st, "restart-resume-agent")
toolRuns := 0
modelCalls := 0
failFirst := true
fakeGen = func(ctx context.Context, opts ai.Options, req *ai.Request) (*ai.Response, error) {
modelCalls++
if opts.ToolHandler != nil {
res := opts.ToolHandler(ctx, ai.ToolCall{ID: "call-1", Name: "external.provision", Input: map[string]any{"service": "api"}})
if res.Content != "provisioned" {
t.Fatalf("tool result = %q, want provisioned", res.Content)
}
}
if failFirst {
failFirst = false
return nil, errors.New("process stopped after tool checkpoint")
}
return &ai.Response{Reply: "resumed after restart"}, nil
}
defer func() { fakeGen = nil }()
newAgent := func() *agentImpl {
return newTestAgent(Name("restart-resume-agent"), WithStore(st), WithCheckpoint(cp),
WithTool("external.provision", "provision service once", nil, func(context.Context, map[string]any) (string, error) {
toolRuns++
return "provisioned", nil
}))
}
first := newAgent()
_, err := first.Ask(ctx, "provision api")
if err == nil {
t.Fatal("Ask succeeded, want simulated process stop")
}
if toolRuns != 1 {
t.Fatalf("tool executions after failed Ask = %d, want 1", toolRuns)
}
runs, err := Pending(ctx, first)
if err != nil {
t.Fatalf("Pending before restart: %v", err)
}
if len(runs) != 1 {
t.Fatalf("Pending before restart returned %d runs, want 1", len(runs))
}
summaries, err := ListRunSummaries(st, "restart-resume-agent")
if err != nil {
t.Fatalf("ListRunSummaries before restart: %v", err)
}
if len(summaries) != 1 {
t.Fatalf("run summaries before restart = %d, want 1", len(summaries))
}
if summaries[0].RunID != runs[0].ID || summaries[0].Status != "error" || summaries[0].Checkpoint != "failed" || summaries[0].Stage != agentAskStep {
t.Fatalf("summary before restart = %#v, want failed ask checkpoint for %s", summaries[0], runs[0].ID)
}
if summaries[0].Events < 4 || summaries[0].LastError == "" {
t.Fatalf("summary before restart lacks debug history/error: %#v", summaries[0])
}
restarted := newAgent()
resp, err := Resume(ctx, restarted, runs[0].ID)
if err != nil {
t.Fatalf("Resume after restart: %v", err)
}
if resp.Reply != "resumed after restart" || resp.RunID != runs[0].ID {
t.Fatalf("response = %#v, want resumed reply on original run id", resp)
}
if toolRuns != 1 {
t.Fatalf("tool executions after restart resume = %d, want checkpointed tool not replayed", toolRuns)
}
if modelCalls != 2 {
t.Fatalf("model calls = %d, want initial call plus resumed call", modelCalls)
}
loaded, ok, err := cp.Load(ctx, runs[0].ID)
if err != nil || !ok {
t.Fatalf("Load resumed run ok=%v err=%v", ok, err)
}
if loaded.Status != "done" || loaded.ParentID != runs[0].ParentID {
t.Fatalf("loaded run status/parent = %s/%s, want done/%s", loaded.Status, loaded.ParentID, runs[0].ParentID)
}
summaries, err = ListRunSummaries(st, "restart-resume-agent")
if err != nil {
t.Fatalf("ListRunSummaries after restart: %v", err)
}
if len(summaries) != 1 {
t.Fatalf("run summaries after restart = %d, want 1", len(summaries))
}
if summaries[0].RunID != runs[0].ID || summaries[0].Status != "done" || summaries[0].Checkpoint != "done" || summaries[0].Stage != agentAskStep {
t.Fatalf("summary after restart = %#v, want done ask checkpoint for %s", summaries[0], runs[0].ID)
}
if summaries[0].Events < 7 {
t.Fatalf("summary after restart recorded %d events, want durable failure/resume/done history", summaries[0].Events)
}
events, err := LoadRunEvents(st, "restart-resume-agent", runs[0].ID)
if err != nil {
t.Fatalf("LoadRunEvents after restart: %v", err)
}
seen := map[string]bool{"run": false, "tool": false, "checkpoint": false, "error": false, "resume": false, "done": false}
for _, e := range events {
if _, ok := seen[e.Kind]; ok {
seen[e.Kind] = true
}
}
for kind, ok := range seen {
if !ok {
t.Fatalf("events after restart missing %s: %#v", kind, events)
}
}
}
func TestResumePendingAfterFreshAgentRestartDoesNotReplayCompletedTool(t *testing.T) {
ctx := context.Background()
st := store.NewMemoryStore()
cp := flow.StoreCheckpoint(st, "startup-resume-agent")
toolRuns := 0
failFirst := true
fakeGen = func(ctx context.Context, opts ai.Options, req *ai.Request) (*ai.Response, error) {
if opts.ToolHandler != nil {
res := opts.ToolHandler(ctx, ai.ToolCall{ID: "call-1", Name: "external.allocate", Input: map[string]any{"cluster": "blue"}})
if res.Content != "allocated" {
t.Fatalf("tool result = %q, want allocated", res.Content)
}
}
if failFirst {
failFirst = false
return nil, errors.New("process stopped before final response")
}
return &ai.Response{Reply: "startup recovery complete"}, nil
}
defer func() { fakeGen = nil }()
newAgent := func() *agentImpl {
return newTestAgent(Name("startup-resume-agent"), WithStore(st), WithCheckpoint(cp),
WithTool("external.allocate", "allocate capacity once", nil, func(context.Context, map[string]any) (string, error) {
toolRuns++
return "allocated", nil
}))
}
first := newAgent()
_, err := first.Ask(ctx, "allocate blue capacity")
if err == nil {
t.Fatal("Ask succeeded, want simulated process stop")
}
if toolRuns != 1 {
t.Fatalf("tool executions after failed Ask = %d, want 1", toolRuns)
}
restarted := newAgent()
failedRun, err := ResumePending(ctx, restarted)
if err != nil {
t.Fatalf("ResumePending after restart: failedRun=%q err=%v", failedRun, err)
}
if failedRun != "" {
t.Fatalf("failed run = %q, want none", failedRun)
}
if toolRuns != 1 {
t.Fatalf("tool executions after ResumePending = %d, want completed tool not replayed", toolRuns)
}
runs, err := Pending(ctx, restarted)
if err != nil {
t.Fatalf("Pending after ResumePending: %v", err)
}
if len(runs) != 0 {
t.Fatalf("Pending after ResumePending = %#v, want none", runs)
}
summaries, err := ListRunSummaries(st, "startup-resume-agent")
if err != nil {
t.Fatalf("ListRunSummaries after ResumePending: %v", err)
}
if len(summaries) != 1 || summaries[0].Status != "done" || summaries[0].Checkpoint != "done" {
t.Fatalf("summary after ResumePending = %#v, want one done run", summaries)
}
}
func TestResumeFailedCheckpointDoesNotDuplicateCompactedMemory(t *testing.T) {
ctx := context.Background()
st := store.NewMemoryStore()
cp := flow.StoreCheckpoint(st, "memory-resume-agent")
failRetry := true
var sawRecall bool
fakeGen = func(ctx context.Context, opts ai.Options, req *ai.Request) (*ai.Response, error) {
for _, msg := range req.Messages {
if text, ok := msg.Content.(string); ok && strings.Contains(text, "alpha code is 42") {
sawRecall = true
}
}
if strings.Contains(req.Prompt, "use alpha code") && failRetry {
failRetry = false
return nil, errors.New("model connection dropped")
}
return &ai.Response{Reply: "ok"}, nil
}
defer func() { fakeGen = nil }()
a := newTestAgent(Name("memory-resume-agent"), WithStore(st), WithCheckpoint(cp), CompactMemory(4, 1), MemoryRecallLimit(2))
for _, msg := range []string{"alpha code is 42", "beta note", "gamma note"} {
if _, err := a.Ask(ctx, msg); err != nil {
t.Fatalf("Ask(%q): %v", msg, err)
}
}
_, err := a.Ask(ctx, "use alpha code now")
if err == nil {
t.Fatal("Ask succeeded, want simulated provider failure")
}
if got := countMemoryContent(a.mem.Messages(), "use alpha code now"); got != 1 {
t.Fatalf("failed Ask stored prompt %d times, want 1", got)
}
runs, err := Pending(ctx, a)
if err != nil {
t.Fatalf("Pending: %v", err)
}
if len(runs) != 1 {
t.Fatalf("Pending returned %d runs, want 1", len(runs))
}
if _, err := Resume(ctx, a, runs[0].ID); err != nil {
t.Fatalf("Resume: %v", err)
}
if got := countMemoryContent(a.mem.Messages(), "use alpha code now"); got != 1 {
t.Fatalf("resumed failed Ask stored prompt %d times, want no duplicate", got)
}
if !sawRecall {
t.Fatal("resume did not retrieve archived compacted memory")
}
if got := len(a.mem.Messages()); got > 4 {
t.Fatalf("compacted memory retained %d messages after resume, want <= 4", got)
}
}
func countMemoryContent(messages []ai.Message, needle string) int {
var count int
for _, msg := range messages {
if text, ok := msg.Content.(string); ok && strings.Contains(text, needle) {
count++
}
}
return count
}
func TestResumePendingResumesOldestAgentRunsUntilFailure(t *testing.T) {
ctx := context.Background()
cp := flow.StoreCheckpoint(store.NewMemoryStore(), "resume-pending-agent")
base := time.Date(2026, 7, 7, 12, 0, 0, 0, time.UTC)
for _, run := range []flow.Run{
{ID: "run-ok", Flow: "resume-pending-agent", Status: "failed", State: flow.State{Stage: agentAskStep, Data: []byte("ok")}, Started: base},
{ID: "run-blocked", Flow: "resume-pending-agent", Status: "failed", State: flow.State{Stage: agentAskStep, Data: []byte("block")}, Started: base.Add(time.Minute)},
{ID: "run-later", Flow: "resume-pending-agent", Status: "failed", State: flow.State{Stage: agentAskStep, Data: []byte("later")}, Started: base.Add(2 * time.Minute)},
} {
if err := cp.Save(ctx, run); err != nil {
t.Fatalf("Save(%s): %v", run.ID, err)
}
}
var prompts []string
fakeGen = func(ctx context.Context, opts ai.Options, req *ai.Request) (*ai.Response, error) {
prompts = append(prompts, req.Prompt)
if req.Prompt == "block" {
return nil, errors.New("still blocked")
}
return &ai.Response{Reply: req.Prompt + " resumed"}, nil
}
defer func() { fakeGen = nil }()
a := newTestAgent(Name("resume-pending-agent"), WithCheckpoint(cp))
failedRun, err := ResumePending(ctx, a)
if err == nil {
t.Fatal("ResumePending succeeded, want blocked run error")
}
if failedRun != "run-blocked" {
t.Fatalf("failed run = %q, want run-blocked", failedRun)
}
if got, want := strings.Join(prompts, ","), "ok,block"; got != want {
t.Fatalf("prompts = %q, want %q", got, want)
}
loaded, ok, err := cp.Load(ctx, "run-ok")
if err != nil || !ok || loaded.Status != "done" {
t.Fatalf("run-ok loaded=%v err=%v status=%q, want done", ok, err, loaded.Status)
}
loaded, ok, err = cp.Load(ctx, "run-later")
if err != nil || !ok || loaded.Status != "failed" {
t.Fatalf("run-later loaded=%v err=%v status=%q, want still failed", ok, err, loaded.Status)
}
}
func TestPendingReturnsUnfinishedAgentRuns(t *testing.T) {
ctx := context.Background()
cp := flow.StoreCheckpoint(store.NewMemoryStore(), "pending-agent")
run := flow.Run{ID: "run-1", Flow: "pending-agent", Status: "failed", State: flow.State{Stage: agentAskStep, Data: []byte("retry me")}}
if err := cp.Save(ctx, run); err != nil {
t.Fatalf("Save: %v", err)
}
a := newTestAgent(Name("pending-agent"), WithCheckpoint(cp))
runs, err := Pending(ctx, a)
if err != nil {
t.Fatalf("Pending: %v", err)
}
if len(runs) != 1 || runs[0].ID != "run-1" {
t.Fatalf("Pending = %#v, want run-1", runs)
}
}
func TestPendingSkipsTerminalCanceledAndExpiredAgentRuns(t *testing.T) {
ctx := context.Background()
cp := flow.StoreCheckpoint(store.NewMemoryStore(), "terminal-agent")
for _, run := range []flow.Run{
{ID: "active", Flow: "terminal-agent", Status: "failed", State: flow.State{Stage: agentAskStep, Data: []byte("retry me")}},
{ID: "done", Flow: "terminal-agent", Status: "done", State: flow.State{Stage: agentAskStep, Data: []byte("done")}},
{ID: "canceled", Flow: "terminal-agent", Status: "canceled", State: flow.State{Stage: agentAskStep, Data: []byte("canceled")}},
{ID: "expired", Flow: "terminal-agent", Status: "expired", State: flow.State{Stage: agentAskStep, Data: []byte("expired")}},
} {
if err := cp.Save(ctx, run); err != nil {
t.Fatalf("Save(%s): %v", run.ID, err)
}
}
a := newTestAgent(Name("terminal-agent"), WithCheckpoint(cp))
runs, err := Pending(ctx, a)
if err != nil {
t.Fatalf("Pending: %v", err)
}
if len(runs) != 1 || runs[0].ID != "active" {
t.Fatalf("Pending = %#v, want only active failed run", runs)
}
for _, id := range []string{"canceled", "expired"} {
if _, err := Resume(ctx, a, id); err == nil || !strings.Contains(err.Error(), "terminal") {
t.Fatalf("Resume(%s) err = %v, want terminal status error", id, err)
}
}
}
func TestHumanInputPauseResumesSameRunWithInput(t *testing.T) {
ctx := context.Background()
cp := flow.StoreCheckpoint(store.NewMemoryStore(), "input-agent")
calls := 0
fakeGen = func(ctx context.Context, opts ai.Options, req *ai.Request) (*ai.Response, error) {
calls++
if calls == 1 {
if opts.ToolHandler != nil {
opts.ToolHandler(ctx, ai.ToolCall{ID: "input-1", Name: toolHumanInput, Input: map[string]any{"prompt": "Which region should I deploy to?"}})
}
return &ai.Response{Reply: "waiting"}, nil
}
if !strings.Contains(req.Prompt, "Human input: us-east-1") {
t.Fatalf("resumed prompt = %q, want human input", req.Prompt)
}
return &ai.Response{Reply: "deploying to us-east-1"}, nil
}
defer func() { fakeGen = nil }()
a := newTestAgent(Name("input-agent"), WithCheckpoint(cp))
_, err := a.Ask(ctx, "deploy the service")
if err == nil {
t.Fatal("Ask succeeded, want input-required pause")
}
runs, err := Pending(ctx, a)
if err != nil {
t.Fatalf("Pending: %v", err)
}
if len(runs) != 1 || runs[0].Status != "paused" || runs[0].State.Stage != agentInputStep {
t.Fatalf("paused runs = %#v, want one input-required run", runs)
}
var pause inputPause
if err := runs[0].State.Scan(&pause); err != nil {
t.Fatalf("Scan pause: %v", err)
}
if pause.OriginalMessage != "deploy the service" || pause.Prompt != "Which region should I deploy to?" {
t.Fatalf("pause = %#v", pause)
}
if _, err := Resume(ctx, a, runs[0].ID); err == nil || !strings.Contains(err.Error(), "ResumeInput") {
t.Fatalf("Resume input-required err = %v, want guidance", err)
}
resp, err := ResumeInput(ctx, a, runs[0].ID, "us-east-1")
if err != nil {
t.Fatalf("ResumeInput: %v", err)
}
if resp.RunID != runs[0].ID || resp.Reply != "deploying to us-east-1" {
t.Fatalf("response = %#v", resp)
}
loaded, ok, err := cp.Load(ctx, runs[0].ID)
if err != nil || !ok {
t.Fatalf("Load resumed run ok=%v err=%v", ok, err)
}
if loaded.Status != "done" {
t.Fatalf("resumed run status = %q, want done", loaded.Status)
}
}
func TestHumanInputResumeHonorsCanceledContextAndLeavesRunPending(t *testing.T) {
ctx := context.Background()
cp := flow.StoreCheckpoint(store.NewMemoryStore(), "input-cancel-agent")
fakeGen = func(ctx context.Context, opts ai.Options, req *ai.Request) (*ai.Response, error) {
if opts.ToolHandler != nil {
opts.ToolHandler(ctx, ai.ToolCall{ID: "input-1", Name: toolHumanInput, Input: map[string]any{"prompt": "Approve deploy?"}})
}
return &ai.Response{Reply: "waiting"}, nil
}
defer func() { fakeGen = nil }()
a := newTestAgent(Name("input-cancel-agent"), WithCheckpoint(cp))
if _, err := a.Ask(ctx, "deploy the service"); err == nil {
t.Fatal("Ask succeeded, want input-required pause")
}
runs, err := Pending(ctx, a)
if err != nil {
t.Fatalf("Pending: %v", err)
}
if len(runs) != 1 {
t.Fatalf("Pending returned %d runs, want 1: %#v", len(runs), runs)
}
canceled, cancel := context.WithCancel(ctx)
cancel()
if _, err := ResumeInput(canceled, a, runs[0].ID, "yes"); !errors.Is(err, context.Canceled) {
t.Fatalf("ResumeInput canceled err = %v, want context.Canceled", err)
}
loaded, ok, err := cp.Load(ctx, runs[0].ID)
if err != nil || !ok {
t.Fatalf("Load paused run ok=%v err=%v", ok, err)
}
if loaded.Status != "paused" || loaded.State.Stage != agentInputStep {
t.Fatalf("run status/stage after canceled resume = %s/%s, want paused/%s", loaded.Status, loaded.State.Stage, agentInputStep)
}
var pause inputPause
if err := loaded.State.Scan(&pause); err != nil {
t.Fatalf("Scan pause after canceled resume: %v", err)
}
if pause.OriginalMessage != "deploy the service" || pause.Prompt != "Approve deploy?" {
t.Fatalf("pause after canceled resume = %#v", pause)
}
}
func TestApprovalDenialPausesCheckpointedRunAndResumeContinues(t *testing.T) {
ctx := context.Background()
cp := flow.StoreCheckpoint(store.NewMemoryStore(), "approval-agent")
calls := 0
fakeGen = func(ctx context.Context, opts ai.Options, req *ai.Request) (*ai.Response, error) {
calls++
if opts.ToolHandler != nil {
opts.ToolHandler(ctx, ai.ToolCall{ID: "call-1", Name: "external.approve", Input: map[string]any{"id": "42"}})
}
return &ai.Response{Reply: "model saw approval result"}, nil
}
defer func() { fakeGen = nil }()
approved := false
a := newTestAgent(Name("approval-agent"), WithCheckpoint(cp),
WithTool("external.approve", "guarded external action", nil, func(context.Context, map[string]any) (string, error) { return "ok", nil }),
ApproveTool(func(tool string, input map[string]any) (bool, string) {
return approved, "waiting for operator"
}))
_, err := a.Ask(ctx, "send the guarded update")
if err == nil {
t.Fatal("Ask succeeded, want paused approval error")
}
runs, err := Pending(ctx, a)
if err != nil {
t.Fatalf("Pending: %v", err)
}
if len(runs) != 1 {
t.Fatalf("Pending returned %d runs, want 1: %#v", len(runs), runs)
}
if runs[0].Status != "paused" || runs[0].State.Stage != agentApprovalStep {
t.Fatalf("run status/stage = %s/%s, want paused/%s", runs[0].Status, runs[0].State.Stage, agentApprovalStep)
}
if got := string(runs[0].State.Data); got != "send the guarded update" {
t.Fatalf("paused run data = %q", got)
}
approved = true
fakeGen = func(ctx context.Context, opts ai.Options, req *ai.Request) (*ai.Response, error) {
calls++
if opts.ToolHandler != nil {
res := opts.ToolHandler(ctx, ai.ToolCall{ID: "call-2", Name: "external.approve", Input: map[string]any{"id": "42"}})
if res.Refused != "" {
t.Fatalf("resumed call was refused: %#v", res)
}
}
return &ai.Response{Reply: "done after approval"}, nil
}
resp, err := Resume(ctx, a, runs[0].ID)
if err != nil {
t.Fatalf("Resume: %v", err)
}
if resp.Reply != "done after approval" {
t.Fatalf("Resume reply = %q", resp.Reply)
}
loaded, ok, err := cp.Load(ctx, runs[0].ID)
if err != nil || !ok {
t.Fatalf("Load resumed run ok=%v err=%v", ok, err)
}
if loaded.Status != "done" {
t.Fatalf("resumed run status = %q, want done", loaded.Status)
}
if calls != 2 {
t.Fatalf("model calls = %d, want 2", calls)
}
}
-54
View File
@@ -1,54 +0,0 @@
// Package command is an interface for defining bot commands
package command
var (
// Commmands keyed by golang/regexp patterns
// regexp.Match(key, input) is used to match
Commands = map[string]Command{}
)
// Command is the interface for specific named
// commands executed via plugins or the bot.
type Command interface {
// Executes the command with args passed in
Exec(args ...string) ([]byte, error)
// Usage of the command
Usage() string
// Description of the command
Description() string
// Name of the command
String() string
}
type cmd struct {
name string
usage string
description string
exec func(args ...string) ([]byte, error)
}
func (c *cmd) Description() string {
return c.description
}
func (c *cmd) Exec(args ...string) ([]byte, error) {
return c.exec(args...)
}
func (c *cmd) Usage() string {
return c.usage
}
func (c *cmd) String() string {
return c.name
}
// NewCommand helps quickly create a new command
func NewCommand(name, usage, description string, exec func(args ...string) ([]byte, error)) Command {
return &cmd{
name: name,
usage: usage,
description: description,
exec: exec,
}
}
-65
View File
@@ -1,65 +0,0 @@
package command
import (
"testing"
)
func TestCommand(t *testing.T) {
c := &cmd{
name: "test",
usage: "test usage",
description: "test description",
exec: func(args ...string) ([]byte, error) {
return []byte("test"), nil
},
}
if c.String() != c.name {
t.Fatalf("expected name %s got %s", c.name, c.String())
}
if c.Usage() != c.usage {
t.Fatalf("expected usage %s got %s", c.usage, c.Usage())
}
if c.Description() != c.description {
t.Fatalf("expected description %s got %s", c.description, c.Description())
}
if r, err := c.Exec(); err != nil {
t.Fatal(err)
} else if string(r) != "test" {
t.Fatalf("expected exec result test got %s", string(r))
}
}
func TestNewCommand(t *testing.T) {
c := &cmd{
name: "test",
usage: "test usage",
description: "test description",
exec: func(args ...string) ([]byte, error) {
return []byte("test"), nil
},
}
nc := NewCommand(c.name, c.usage, c.description, c.exec)
if nc.String() != c.name {
t.Fatalf("expected name %s got %s", c.name, nc.String())
}
if nc.Usage() != c.usage {
t.Fatalf("expected usage %s got %s", c.usage, nc.Usage())
}
if nc.Description() != c.description {
t.Fatalf("expected description %s got %s", c.description, nc.Description())
}
if r, err := nc.Exec(); err != nil {
t.Fatal(err)
} else if string(r) != "test" {
t.Fatalf("expected exec result test got %s", string(r))
}
}
+682
View File
@@ -0,0 +1,682 @@
package agent
import (
"context"
"errors"
"fmt"
"os"
"strings"
"testing"
"time"
"go-micro.dev/v6/ai"
"go-micro.dev/v6/registry"
"go-micro.dev/v6/store"
)
type conformanceProvider struct {
name string
model string
key string
live bool
}
func TestAgentProviderConformanceMatrix(t *testing.T) {
providers := []conformanceProvider{
{name: "fake"},
{name: "openai", key: "OPENAI_API_KEY", model: "GO_MICRO_CONFORMANCE_OPENAI_MODEL", live: true},
{name: "anthropic", key: "ANTHROPIC_API_KEY", model: "GO_MICRO_CONFORMANCE_ANTHROPIC_MODEL", live: true},
{name: "atlascloud", key: "ATLASCLOUD_API_KEY", model: "GO_MICRO_CONFORMANCE_ATLASCLOUD_MODEL", live: true},
{name: "gemini", key: "GEMINI_API_KEY", model: "GO_MICRO_CONFORMANCE_GEMINI_MODEL", live: true},
{name: "groq", key: "GROQ_API_KEY", model: "GO_MICRO_CONFORMANCE_GROQ_MODEL", live: true},
{name: "mistral", key: "MISTRAL_API_KEY", model: "GO_MICRO_CONFORMANCE_MISTRAL_MODEL", live: true},
{name: "together", key: "TOGETHER_API_KEY", model: "GO_MICRO_CONFORMANCE_TOGETHER_MODEL", live: true},
}
selected := selectedConformanceProviders(os.Getenv("GO_MICRO_AGENT_CONFORMANCE_PROVIDERS"))
for _, provider := range providers {
provider := provider
if len(selected) > 0 && !selected[provider.name] {
continue
}
t.Run(provider.name, func(t *testing.T) {
runAgentConformanceScenario(t, provider)
})
}
}
func selectedConformanceProviders(csv string) map[string]bool {
out := map[string]bool{}
for _, part := range strings.Split(csv, ",") {
part = strings.TrimSpace(part)
if part != "" {
out[part] = true
}
}
return out
}
func runAgentConformanceScenario(t *testing.T, provider conformanceProvider) {
t.Helper()
if provider.live {
if os.Getenv(provider.key) == "" {
t.Skipf("%s not set; skipping live %s conformance", provider.key, provider.name)
}
if os.Getenv("GO_MICRO_AGENT_CONFORMANCE_LIVE") == "" {
t.Skipf("GO_MICRO_AGENT_CONFORMANCE_LIVE not set; skipping live %s conformance", provider.name)
}
} else {
fakeGen = func(ctx context.Context, opts ai.Options, req *ai.Request) (*ai.Response, error) {
if err := validateConformanceRequest(req, opts); err != nil {
return nil, err
}
plan := opts.ToolHandler(ctx, ai.ToolCall{
ID: "fake-plan-1",
Name: "plan",
Input: map[string]any{"steps": []map[string]any{
{"description": "call conformance_echo", "status": "pending"},
{"description": "attempt guarded delegate", "status": "pending"},
}},
})
echo := opts.ToolHandler(ctx, ai.ToolCall{
ID: "fake-call-1",
Name: "conformance_echo",
Input: map[string]any{"value": "agent-conformance"},
})
delegate := opts.ToolHandler(ctx, ai.ToolCall{
ID: "fake-delegate-1",
Name: "delegate",
Input: map[string]any{"task": "summarize the conformance marker", "to": "blocked-reviewer"},
})
if plan.Content == "" {
return nil, errors.New("empty plan result")
}
if echo.Content == "" {
return nil, errors.New("empty tool result")
}
if delegate.Refused != ai.RefusedApproval {
return nil, fmt.Errorf("delegate refusal = %q, want %q", delegate.Refused, ai.RefusedApproval)
}
return &ai.Response{
Reply: "planned, called conformance_echo, and handled guarded delegate refusal",
Answer: echo.Content + " " + delegate.Content,
ToolCalls: []ai.ToolCall{
{ID: "fake-plan-1", Name: "plan", Input: map[string]any{}},
{ID: "fake-call-1", Name: "conformance_echo", Input: map[string]any{"value": "agent-conformance"}, Result: echo.Content},
{ID: "fake-delegate-1", Name: "delegate", Input: map[string]any{"task": "summarize the conformance marker", "to": "blocked-reviewer"}, Error: delegate.Content},
},
}, nil
}
defer func() { fakeGen = nil }()
}
var sawTool bool
var sawRunInfo bool
var sawBlockedDelegate bool
agentOpts := []Option{
Name("conformance-" + provider.name),
Provider(provider.name),
APIKey(os.Getenv(provider.key)),
Prompt(conformanceSystemPrompt(provider.name)),
WithRegistry(registry.NewMemoryRegistry()),
WithStore(store.NewMemoryStore()),
WithMemory(NewInMemory(8)),
ModelCallTimeout(45 * time.Second),
ApproveTool(func(tool string, input map[string]any) (bool, string) {
if tool == "delegate" {
sawBlockedDelegate = true
return false, "cross-provider conformance blocks delegate side effects"
}
return true, ""
}),
WithTool("conformance_echo", "Echo a conformance value and return a deterministic marker.", map[string]any{
"value": map[string]any{"type": "string", "description": "value to echo"},
}, func(ctx context.Context, input map[string]any) (string, error) {
sawTool = true
info, ok := ai.RunInfoFrom(ctx)
if !ok {
return "", errors.New("missing run info")
}
if info.RunID == "" || info.Agent != "conformance-"+provider.name {
return "", fmt.Errorf("unexpected run info: %+v", info)
}
sawRunInfo = true
if input["value"] != "agent-conformance" {
return "", fmt.Errorf("unexpected value %v", input["value"])
}
return `{"marker":"agent-conformance-ok"}`, nil
}),
}
if provider.model != "" {
if model := os.Getenv(provider.model); model != "" {
agentOpts = append(agentOpts, Model(model))
}
}
a := New(agentOpts...)
resp, err := askWithConformanceRetry(context.Background(), a, "Run the provider conformance check.", &sawTool, &sawBlockedDelegate)
if err != nil {
t.Fatalf("Ask: %v", err)
}
if resp.RunID == "" {
t.Fatal("RunID is empty")
}
if resp.Agent != "conformance-"+provider.name {
t.Fatalf("Agent = %q", resp.Agent)
}
if !sawTool {
t.Fatal("provider did not request the conformance tool")
}
if !sawRunInfo {
t.Fatal("tool did not receive RunInfo")
}
if !sawBlockedDelegate {
t.Fatal("provider did not exercise the guarded delegate path")
}
if !strings.Contains(resp.Reply, "agent-conformance-ok") && !strings.Contains(resp.Reply, "agent-conformance") {
t.Fatalf("reply %q does not include conformance marker", resp.Reply)
}
}
func askWithConformanceRetry(ctx context.Context, a Agent, initialPrompt string, sawTool, sawBlockedDelegate *bool) (*Response, error) {
const maxAttempts = 4
prompt := initialPrompt
var resp *Response
for attempt := 1; attempt <= maxAttempts; attempt++ {
var err error
resp, err = a.Ask(ctx, prompt)
if err != nil {
return nil, err
}
sawRequiredTool := sawTool == nil || *sawTool
sawRequiredDelegate := sawBlockedDelegate == nil || *sawBlockedDelegate
hasMarker := responseHasConformanceMarker(resp)
if sawRequiredTool && sawRequiredDelegate && hasMarker {
return resp, nil
}
if attempt == maxAttempts {
break
}
prompt = nextConformanceRetryPrompt(sawRequiredTool, sawRequiredDelegate, hasMarker, attempt+1)
}
missing := missingConformanceRequirements(sawTool, sawBlockedDelegate, responseHasConformanceMarker(resp))
if len(missing) > 0 {
return resp, fmt.Errorf("provider conformance incomplete after %d attempts: missing %s", maxAttempts, strings.Join(missing, ", "))
}
return resp, nil
}
func askWithConformanceToolRetry(ctx context.Context, a Agent, initialPrompt string, sawTool *bool) (*Response, error) {
return askWithConformanceRetry(ctx, a, initialPrompt, sawTool, nil)
}
func missingConformanceRequirements(sawTool, sawBlockedDelegate *bool, hasMarker bool) []string {
var missing []string
if sawTool != nil && !*sawTool {
missing = append(missing, "conformance_echo")
}
if sawBlockedDelegate != nil && !*sawBlockedDelegate {
missing = append(missing, "guarded delegate")
}
if !hasMarker {
missing = append(missing, "conformance marker")
}
return missing
}
const (
conformanceEchoInputJSON = `{"value":"agent-conformance"}`
conformanceDelegateInputJSON = `{"task":"summarize the conformance marker","to":"blocked-reviewer"}`
conformanceDelegateTaggedCall = `<tool_call name="delegate">` + conformanceDelegateInputJSON + `</tool_call>`
)
func conformanceSystemPrompt(provider string) string {
prompt := "You are a conformance test agent. Create a short plan, use conformance_echo exactly once with input " + conformanceEchoInputJSON + ", then attempt to delegate a summary to blocked-reviewer with input " + conformanceDelegateInputJSON + ". You must complete both tool calls before any final answer; a final answer that only mentions the steps without calling both tools is invalid. If the delegate is refused, explain the refusal and answer with the echo result."
if provider == "atlascloud" {
prompt += " AtlasCloud/minimax conformance note: the delegate attempt is mandatory after conformance_echo. If native tool_calls are unavailable, emit the delegate as " + conformanceDelegateTaggedCall + " rather than answering in prose."
}
return prompt
}
func TestAgentProviderConformanceAtlasCloudPromptRequiresTaggedDelegateFallback(t *testing.T) {
prompt := conformanceSystemPrompt("atlascloud")
for _, want := range []string{
"delegate attempt is mandatory",
"You must complete both tool calls before any final answer",
"<tool_call name=\"delegate\">",
`{"task":"summarize the conformance marker","to":"blocked-reviewer"}`,
} {
if !strings.Contains(prompt, want) {
t.Fatalf("atlascloud conformance prompt %q missing %q", prompt, want)
}
}
if strings.Contains(conformanceSystemPrompt("openai"), "AtlasCloud/minimax") {
t.Fatal("non-AtlasCloud prompt should not include provider-specific fallback guidance")
}
}
func TestAgentProviderConformanceRetryPromptsRequireBothTools(t *testing.T) {
for name, prompt := range map[string]string{
"missing tool": nextConformanceRetryPrompt(false, false, false, 2),
"missing delegate": nextConformanceRetryPrompt(true, false, true, 2),
} {
for _, want := range []string{
"delegate exactly once",
conformanceDelegateTaggedCall,
"do not",
} {
if !strings.Contains(prompt, want) {
t.Fatalf("%s retry prompt %q missing %q", name, prompt, want)
}
}
}
}
func TestAgentProviderConformanceFinalDelegateRetryUsesTaggedCall(t *testing.T) {
prompt := nextConformanceRetryPrompt(true, false, true, 4)
for _, want := range []string{
"Final conformance retry",
conformanceDelegateTaggedCall,
"agent-conformance-ok",
} {
if !strings.Contains(prompt, want) {
t.Fatalf("final delegate retry prompt %q missing %q", prompt, want)
}
}
}
func nextConformanceRetryPrompt(sawTool, sawBlockedDelegate, hasMarker bool, attempt int) string {
if attempt >= 4 && sawTool && !sawBlockedDelegate {
return "Final conformance retry: emit exactly this tagged tool call so the harness can execute the guarded delegate refusal, then include agent-conformance-ok and the refusal in the final answer: " + conformanceDelegateTaggedCall
}
switch {
case !sawTool:
return "The previous response did not call the required conformance_echo tool. Retry the same conformance check now: first call conformance_echo exactly once with input " + conformanceEchoInputJSON + ", then call delegate exactly once with input " + conformanceDelegateInputJSON + "; do not provide a final answer until both tool calls have been attempted. If native delegate tool_calls are unavailable after conformance_echo, emit exactly " + conformanceDelegateTaggedCall + ". The delegate is expected to be refused by policy; include that refusal and the agent-conformance marker in the final answer."
case !sawBlockedDelegate:
return "The previous response called conformance_echo but did not attempt the required guarded delegation. Continue the same conformance check now: call delegate exactly once with input " + conformanceDelegateInputJSON + "; do not answer in prose until that delegate call has been attempted. If native tool_calls are unavailable, emit exactly " + conformanceDelegateTaggedCall + ". The delegate is expected to be refused by policy; include that refusal and the agent-conformance marker in the final answer."
case !hasMarker:
return "The previous response completed the required tool calls but omitted the conformance marker. Continue the same conformance check now: do not call more tools; answer with the prior echo result marker agent-conformance-ok and mention the guarded delegate refusal."
default:
return "Retry the provider conformance check and include the agent-conformance marker in the final answer."
}
}
func responseHasConformanceMarker(resp *Response) bool {
if resp == nil {
return false
}
return strings.Contains(resp.Reply, "agent-conformance-ok") || strings.Contains(resp.Reply, "agent-conformance")
}
func validateConformanceRequest(req *ai.Request, opts ai.Options) error {
if req.Prompt == "" {
return errors.New("missing prompt")
}
if len(req.Messages) == 0 || req.Messages[len(req.Messages)-1].Role != "user" {
return fmt.Errorf("missing user history: %+v", req.Messages)
}
if len(req.Tools) == 0 {
return errors.New("missing tools")
}
if opts.ToolHandler == nil {
return errors.New("missing tool handler")
}
return nil
}
func TestAgentProviderConformanceFakeError(t *testing.T) {
fakeGen = func(ctx context.Context, opts ai.Options, req *ai.Request) (*ai.Response, error) {
return nil, errors.New("conformance provider failure")
}
defer func() { fakeGen = nil }()
a := New(
Name("conformance-error"),
Provider("fake"),
WithRegistry(registry.NewMemoryRegistry()),
WithStore(store.NewMemoryStore()),
WithMemory(NewInMemory(4)),
)
_, err := a.Ask(context.Background(), "fail deterministically")
if err == nil || !strings.Contains(err.Error(), "conformance provider failure") {
t.Fatalf("Ask error = %v, want conformance provider failure", err)
}
}
func TestAgentProviderConformanceRetriesMissingTool(t *testing.T) {
var attempts int
fakeGen = func(ctx context.Context, opts ai.Options, req *ai.Request) (*ai.Response, error) {
attempts++
if err := validateConformanceRequest(req, opts); err != nil {
return nil, err
}
if attempts == 1 {
return &ai.Response{Reply: "I can confirm agent-conformance in prose only."}, nil
}
echo := opts.ToolHandler(ctx, ai.ToolCall{
ID: "fake-call-1",
Name: "conformance_echo",
Input: map[string]any{"value": "agent-conformance"},
})
return &ai.Response{
Reply: "called conformance_echo",
Answer: echo.Content,
ToolCalls: []ai.ToolCall{
{ID: "fake-call-1", Name: "conformance_echo", Input: map[string]any{"value": "agent-conformance"}, Result: echo.Content},
},
}, nil
}
defer func() { fakeGen = nil }()
var sawTool bool
a := New(
Name("conformance-retry"),
Provider("fake"),
WithRegistry(registry.NewMemoryRegistry()),
WithStore(store.NewMemoryStore()),
WithMemory(NewInMemory(4)),
WithTool("conformance_echo", "Echo a conformance value.", map[string]any{
"value": map[string]any{"type": "string"},
}, func(ctx context.Context, input map[string]any) (string, error) {
sawTool = true
return `{"marker":"agent-conformance-ok"}`, nil
}),
)
resp, err := askWithConformanceToolRetry(context.Background(), a, "Run the provider conformance check.", &sawTool)
if err != nil {
t.Fatalf("Ask: %v", err)
}
if attempts != 2 {
t.Fatalf("attempts = %d, want retry after missing tool", attempts)
}
if !sawTool {
t.Fatal("retry did not execute conformance_echo")
}
if !strings.Contains(resp.Reply, "agent-conformance-ok") {
t.Fatalf("Reply = %q, want tool result marker", resp.Reply)
}
}
func TestAgentProviderConformanceRetriesMissingMarker(t *testing.T) {
var attempts int
fakeGen = func(ctx context.Context, opts ai.Options, req *ai.Request) (*ai.Response, error) {
attempts++
if err := validateConformanceRequest(req, opts); err != nil {
return nil, err
}
if attempts == 1 {
return &ai.Response{Reply: "called conformance_echo and handled guarded delegate refusal without the required marker"}, nil
}
return &ai.Response{Reply: "agent-conformance-ok after guarded delegate refusal"}, nil
}
defer func() { fakeGen = nil }()
sawTool := true
sawBlockedDelegate := true
a := New(
Name("conformance-retry-marker"),
Provider("fake"),
WithRegistry(registry.NewMemoryRegistry()),
WithStore(store.NewMemoryStore()),
WithMemory(NewInMemory(4)),
WithTool("conformance_echo", "Echo a conformance value.", map[string]any{
"value": map[string]any{"type": "string"},
}, func(ctx context.Context, input map[string]any) (string, error) {
return `{"marker":"agent-conformance-ok"}`, nil
}),
)
resp, err := askWithConformanceRetry(context.Background(), a, "Run the provider conformance check.", &sawTool, &sawBlockedDelegate)
if err != nil {
t.Fatalf("Ask: %v", err)
}
if attempts != 2 {
t.Fatalf("attempts = %d, want retry after missing marker", attempts)
}
if !strings.Contains(resp.Reply, "agent-conformance-ok") {
t.Fatalf("Reply = %q, want conformance marker", resp.Reply)
}
}
func TestAgentProviderConformanceRetriesMissingDelegate(t *testing.T) {
var attempts int
fakeGen = func(ctx context.Context, opts ai.Options, req *ai.Request) (*ai.Response, error) {
attempts++
if err := validateConformanceRequest(req, opts); err != nil {
return nil, err
}
echo := opts.ToolHandler(ctx, ai.ToolCall{
ID: "fake-call-1",
Name: "conformance_echo",
Input: map[string]any{"value": "agent-conformance"},
})
if attempts == 1 {
return &ai.Response{
Reply: "called conformance_echo but skipped delegate",
Answer: echo.Content,
ToolCalls: []ai.ToolCall{
{ID: "fake-call-1", Name: "conformance_echo", Input: map[string]any{"value": "agent-conformance"}, Result: echo.Content},
},
}, nil
}
delegate := opts.ToolHandler(ctx, ai.ToolCall{
ID: "fake-delegate-1",
Name: "delegate",
Input: map[string]any{"task": "summarize the conformance marker", "to": "blocked-reviewer"},
})
return &ai.Response{
Reply: "called conformance_echo and handled guarded delegate refusal",
Answer: echo.Content + " " + delegate.Content,
ToolCalls: []ai.ToolCall{
{ID: "fake-call-1", Name: "conformance_echo", Input: map[string]any{"value": "agent-conformance"}, Result: echo.Content},
{ID: "fake-delegate-1", Name: "delegate", Input: map[string]any{"task": "summarize the conformance marker", "to": "blocked-reviewer"}, Error: delegate.Content},
},
}, nil
}
defer func() { fakeGen = nil }()
var sawTool bool
var sawBlockedDelegate bool
a := New(
Name("conformance-retry-delegate"),
Provider("fake"),
WithRegistry(registry.NewMemoryRegistry()),
WithStore(store.NewMemoryStore()),
WithMemory(NewInMemory(4)),
ApproveTool(func(tool string, input map[string]any) (bool, string) {
if tool == "delegate" {
sawBlockedDelegate = true
return false, "cross-provider conformance blocks delegate side effects"
}
return true, ""
}),
WithTool("conformance_echo", "Echo a conformance value.", map[string]any{
"value": map[string]any{"type": "string"},
}, func(ctx context.Context, input map[string]any) (string, error) {
sawTool = true
return `{"marker":"agent-conformance-ok"}`, nil
}),
)
resp, err := askWithConformanceRetry(context.Background(), a, "Run the provider conformance check.", &sawTool, &sawBlockedDelegate)
if err != nil {
t.Fatalf("Ask: %v", err)
}
if attempts != 2 {
t.Fatalf("attempts = %d, want retry after missing delegate", attempts)
}
if !sawBlockedDelegate {
t.Fatal("retry did not attempt guarded delegate")
}
if !strings.Contains(resp.Reply, "agent-conformance-ok") && !strings.Contains(resp.Reply, "agent-conformance") {
t.Fatalf("Reply = %q, want conformance marker", resp.Reply)
}
}
func TestAgentProviderConformanceFailsWhenDelegateStillMissing(t *testing.T) {
var attempts int
fakeGen = func(ctx context.Context, opts ai.Options, req *ai.Request) (*ai.Response, error) {
attempts++
if err := validateConformanceRequest(req, opts); err != nil {
return nil, err
}
echo := opts.ToolHandler(ctx, ai.ToolCall{
ID: fmt.Sprintf("fake-call-%d", attempts),
Name: "conformance_echo",
Input: map[string]any{"value": "agent-conformance"},
})
return &ai.Response{
Reply: "called conformance_echo with agent-conformance-ok but skipped delegate",
Answer: echo.Content,
ToolCalls: []ai.ToolCall{
{ID: fmt.Sprintf("fake-call-%d", attempts), Name: "conformance_echo", Input: map[string]any{"value": "agent-conformance"}, Result: echo.Content},
},
}, nil
}
defer func() { fakeGen = nil }()
var sawTool bool
var sawBlockedDelegate bool
a := New(
Name("conformance-retry-delegate-exhausted"),
Provider("fake"),
WithRegistry(registry.NewMemoryRegistry()),
WithStore(store.NewMemoryStore()),
WithMemory(NewInMemory(4)),
ApproveTool(func(tool string, input map[string]any) (bool, string) {
if tool == "delegate" {
sawBlockedDelegate = true
return false, "cross-provider conformance blocks delegate side effects"
}
return true, ""
}),
WithTool("conformance_echo", "Echo a conformance value.", map[string]any{
"value": map[string]any{"type": "string"},
}, func(ctx context.Context, input map[string]any) (string, error) {
sawTool = true
return `{"marker":"agent-conformance-ok"}`, nil
}),
)
_, err := askWithConformanceRetry(context.Background(), a, "Run the provider conformance check.", &sawTool, &sawBlockedDelegate)
if err == nil || !strings.Contains(err.Error(), "guarded delegate") {
t.Fatalf("Ask error = %v, want missing guarded delegate", err)
}
if attempts != 4 {
t.Fatalf("attempts = %d, want retries through max attempts", attempts)
}
}
func TestAgentExecutesProviderTextToolCallFallback(t *testing.T) {
fakeGen = func(ctx context.Context, opts ai.Options, req *ai.Request) (*ai.Response, error) {
if opts.ToolHandler == nil {
return nil, errors.New("missing tool handler")
}
return &ai.Response{
Reply: `{"name":"conformance_echo","input":{"value":"agent-conformance"}}`,
}, nil
}
defer func() { fakeGen = nil }()
var sawTool bool
a := New(
Name("conformance-text-tool"),
Provider("fake"),
WithRegistry(registry.NewMemoryRegistry()),
WithStore(store.NewMemoryStore()),
WithMemory(NewInMemory(4)),
WithTool("conformance_echo", "Echo a conformance value.", map[string]any{
"value": map[string]any{"type": "string"},
}, func(ctx context.Context, input map[string]any) (string, error) {
sawTool = true
if input["value"] != "agent-conformance" {
return "", fmt.Errorf("unexpected value %v", input["value"])
}
return `{"marker":"agent-conformance-ok"}`, nil
}),
)
resp, err := a.Ask(context.Background(), "Run the text tool call fallback.")
if err != nil {
t.Fatalf("Ask: %v", err)
}
if !sawTool {
t.Fatal("text tool call fallback did not execute the tool")
}
if len(resp.ToolCalls) != 1 || resp.ToolCalls[0].Name != "conformance_echo" {
t.Fatalf("ToolCalls = %+v, want conformance_echo", resp.ToolCalls)
}
if !strings.Contains(resp.Reply, "agent-conformance-ok") {
t.Fatalf("Reply = %q, want tool result marker", resp.Reply)
}
if strings.Contains(resp.Reply, `"name":"conformance_echo"`) {
t.Fatalf("Reply = %q, want tool result instead of raw JSON", resp.Reply)
}
}
func TestAgentExecutesTextToolCallFallbackAfterStructuredToolCall(t *testing.T) {
fakeGen = func(ctx context.Context, opts ai.Options, req *ai.Request) (*ai.Response, error) {
if opts.ToolHandler == nil {
return nil, errors.New("missing tool handler")
}
echo := opts.ToolHandler(ctx, ai.ToolCall{
ID: "structured-echo-1",
Name: "conformance_echo",
Input: map[string]any{"value": "agent-conformance"},
})
return &ai.Response{
Reply: echo.Content + "\n<tool_call name=\"delegate\">{\"task\":\"summarize the conformance marker\",\"to\":\"blocked-reviewer\"}</tool_call>",
Answer: echo.Content,
ToolCalls: []ai.ToolCall{
{ID: "structured-echo-1", Name: "conformance_echo", Input: map[string]any{"value": "agent-conformance"}, Result: echo.Content},
},
}, nil
}
defer func() { fakeGen = nil }()
var sawTool bool
var sawBlockedDelegate bool
a := New(
Name("conformance-mixed-text-tool"),
Provider("fake"),
WithRegistry(registry.NewMemoryRegistry()),
WithStore(store.NewMemoryStore()),
WithMemory(NewInMemory(4)),
ApproveTool(func(tool string, input map[string]any) (bool, string) {
if tool == "delegate" {
sawBlockedDelegate = true
return false, "cross-provider conformance blocks delegate side effects"
}
return true, ""
}),
WithTool("conformance_echo", "Echo a conformance value.", map[string]any{
"value": map[string]any{"type": "string"},
}, func(ctx context.Context, input map[string]any) (string, error) {
sawTool = true
return `{"marker":"agent-conformance-ok"}`, nil
}),
)
resp, err := a.Ask(context.Background(), "Run the mixed structured/text tool fallback.")
if err != nil {
t.Fatalf("Ask: %v", err)
}
if !sawTool {
t.Fatal("structured conformance_echo did not execute")
}
if !sawBlockedDelegate {
t.Fatal("tagged text delegate fallback did not execute")
}
if len(resp.ToolCalls) != 2 {
t.Fatalf("ToolCalls = %+v, want structured echo and text delegate", resp.ToolCalls)
}
if resp.ToolCalls[1].Name != "delegate" || resp.ToolCalls[1].Error != ai.RefusedApproval {
t.Fatalf("delegate ToolCall = %+v, want refused delegate", resp.ToolCalls[1])
}
if !strings.Contains(resp.Reply, "agent-conformance-ok") {
t.Fatalf("Reply = %q, want conformance marker", resp.Reply)
}
}
+92
View File
@@ -0,0 +1,92 @@
package agent
import (
"context"
"strings"
"testing"
"go-micro.dev/v6/ai"
"go-micro.dev/v6/registry"
"go-micro.dev/v6/store"
)
// toolContent runs a tool call through a handler and returns the content
// shown to the model — the part these tests assert on.
func toolContent(h ai.ToolHandler, name string, input map[string]any) string {
return h(context.Background(), ai.ToolCall{Name: name, Input: input}).Content
}
// MaxSteps refuses tool calls once the per-Ask limit is exceeded; plan
// is bookkeeping and is never counted.
func TestMaxStepsStopsActions(t *testing.T) {
a := newTestAgent(Name("limited"), MaxSteps(2))
h := a.toolHandler()
// plan must not consume a step.
a.steps = 0
toolContent(h, toolPlan, map[string]any{"steps": []any{}})
if a.steps != 0 {
t.Fatalf("plan consumed a step: steps=%d", a.steps)
}
// First two actions are allowed (they fall through to RPC, which
// fails harmlessly — we only care they weren't refused by the limit).
for i := 1; i <= 2; i++ {
content := toolContent(h, "demo_Svc_Do", map[string]any{})
if strings.Contains(content, "step limit") {
t.Fatalf("action %d wrongly hit the step limit", i)
}
}
// Third action exceeds MaxSteps(2) and must be refused.
content := toolContent(h, "demo_Svc_Do", map[string]any{})
if !strings.Contains(content, "step limit") {
t.Errorf("third action should hit the step limit; got %q", content)
}
}
// ApproveTool blocks an action when the hook denies it, and the denial
// reason is surfaced to the model.
func TestApproveToolBlocks(t *testing.T) {
var sawTool string
a := newTestAgent(Name("gated"),
ApproveTool(func(tool string, input map[string]any) (bool, string) {
sawTool = tool
return false, "needs sign-off"
}),
)
content := toolContent(a.toolHandler(), "demo_Svc_Do", map[string]any{})
if sawTool != "demo_Svc_Do" {
t.Errorf("approver saw %q, want demo_Svc_Do", sawTool)
}
if !strings.Contains(content, "not approved") || !strings.Contains(content, "needs sign-off") {
t.Errorf("blocked call should surface the reason; got %q", content)
}
}
// A denying approver must not gate the internal plan tool.
func TestApproveToolDoesNotGatePlan(t *testing.T) {
mem := store.NewMemoryStore()
a := New(
Name("gated"),
Provider("fake"),
WithRegistry(registry.NewMemoryRegistry()),
WithStore(mem),
ApproveTool(func(tool string, input map[string]any) (bool, string) {
return false, "deny everything"
}),
).(*agentImpl)
a.setup()
content := toolContent(a.toolHandler(), toolPlan, map[string]any{
"steps": []any{map[string]any{"task": "x", "status": "pending"}},
})
if strings.Contains(content, "not approved") {
t.Errorf("plan must not be gated by ApproveTool; got %q", content)
}
if recs, _ := store.Scope(mem, "agent", "gated").Read(planKey); len(recs) == 0 {
t.Error("plan should have been persisted despite the denying approver")
}
}
-22
View File
@@ -1,22 +0,0 @@
# Discord input for micro-bot
[Discord](https://discordapp.com) support for micro bot based on [discordgo](github.com/bwmarrin/discordgo).
This was originally written by Aleksandr Tihomirov (@zet4) and can be found at https://github.com/zet4/micro-misc/.
## Options
### discord_token
You have to supply an application token via `--discord_token`.
Head over to Discord's [developer introduction](https://discordapp.com/developers/docs/intro)
to learn how to create applications and how the API works.
### discord_prefix
Set a command prefix with `--discord_prefix`. The default prefix is `Micro `.
You can mention the bot or use the prefix to run a command.
### discord_whitelist
Pass a list of comma-separated user IDs with `--discord_whitelist`. Only allow
these users to use the bot.
-94
View File
@@ -1,94 +0,0 @@
package discord
import (
"errors"
"strings"
"sync"
"github.com/bwmarrin/discordgo"
"github.com/micro/go-micro/agent/input"
"github.com/micro/go-micro/util/log"
)
type discordConn struct {
master *discordInput
exit chan struct{}
recv chan *discordgo.Message
sync.Mutex
}
func newConn(master *discordInput) *discordConn {
conn := &discordConn{
master: master,
exit: make(chan struct{}),
recv: make(chan *discordgo.Message),
}
conn.master.session.AddHandler(func(s *discordgo.Session, m *discordgo.MessageCreate) {
if m.Author.ID == master.botID {
return
}
whitelisted := false
for _, ID := range conn.master.whitelist {
if m.Author.ID == ID {
whitelisted = true
break
}
}
if len(master.whitelist) > 0 && !whitelisted {
return
}
var valid bool
m.Message.Content, valid = conn.master.prefixfn(m.Message.Content)
if !valid {
return
}
conn.recv <- m.Message
})
return conn
}
func (dc *discordConn) Recv(event *input.Event) error {
for {
select {
case <-dc.exit:
return errors.New("connection closed")
case msg := <-dc.recv:
event.From = msg.ChannelID + ":" + msg.Author.ID
event.To = dc.master.botID
event.Type = input.TextEvent
event.Data = []byte(msg.Content)
return nil
}
}
}
func (dc *discordConn) Send(e *input.Event) error {
fields := strings.Split(e.To, ":")
_, err := dc.master.session.ChannelMessageSend(fields[0], string(e.Data))
if err != nil {
log.Log("[bot][loop][send]", err)
}
return nil
}
func (dc *discordConn) Close() error {
if err := dc.master.session.Close(); err != nil {
return err
}
select {
case <-dc.exit:
return nil
default:
close(dc.exit)
}
return nil
}
-153
View File
@@ -1,153 +0,0 @@
package discord
import (
"fmt"
"sync"
"errors"
"strings"
"github.com/bwmarrin/discordgo"
"github.com/micro/cli"
"github.com/micro/go-micro/agent/input"
)
func init() {
input.Inputs["discord"] = newInput()
}
func newInput() *discordInput {
return &discordInput{}
}
type discordInput struct {
token string
whitelist []string
prefix string
prefixfn func(string) (string, bool)
botID string
session *discordgo.Session
sync.Mutex
running bool
exit chan struct{}
}
func (d *discordInput) Flags() []cli.Flag {
return []cli.Flag{
cli.StringFlag{
Name: "discord_token",
EnvVar: "MICRO_DISCORD_TOKEN",
Usage: "Discord token (prefix with Bot if it's for bot account)",
},
cli.StringFlag{
Name: "discord_whitelist",
EnvVar: "MICRO_DISCORD_WHITELIST",
Usage: "Discord Whitelist (seperated by ,)",
},
cli.StringFlag{
Name: "discord_prefix",
Usage: "Discord Prefix",
EnvVar: "MICRO_DISCORD_PREFIX",
Value: "Micro ",
},
}
}
func (d *discordInput) Init(ctx *cli.Context) error {
token := ctx.String("discord_token")
whitelist := ctx.String("discord_whitelist")
prefix := ctx.String("discord_prefix")
if len(token) == 0 {
return errors.New("require token")
}
d.token = token
d.prefix = prefix
if len(whitelist) > 0 {
d.whitelist = strings.Split(whitelist, ",")
}
return nil
}
func (d *discordInput) Start() error {
if len(d.token) == 0 {
return errors.New("missing discord configuration")
}
d.Lock()
defer d.Unlock()
if d.running {
return nil
}
var err error
d.session, err = discordgo.New(d.token)
if err != nil {
return err
}
u, err := d.session.User("@me")
if err != nil {
return err
}
d.botID = u.ID
d.prefixfn = CheckPrefixFactory(fmt.Sprintf("<@%s> ", d.botID), fmt.Sprintf("<@!%s> ", d.botID), d.prefix)
d.exit = make(chan struct{})
d.running = true
return nil
}
func (d *discordInput) Stream() (input.Conn, error) {
d.Lock()
defer d.Unlock()
if !d.running {
return nil, errors.New("not running")
}
//Fire-n-forget close just in case...
d.session.Close()
conn := newConn(d)
if err := d.session.Open(); err != nil {
return nil, err
}
return conn, nil
}
func (d *discordInput) Stop() error {
d.Lock()
defer d.Unlock()
if !d.running {
return nil
}
close(d.exit)
d.running = false
return nil
}
func (d *discordInput) String() string {
return "discord"
}
// CheckPrefixFactory Creates a prefix checking function and stuff.
func CheckPrefixFactory(prefixes ...string) func(string) (string, bool) {
return func(content string) (string, bool) {
for _, prefix := range prefixes {
if strings.HasPrefix(content, prefix) {
return strings.TrimPrefix(content, prefix), true
}
}
return "", false
}
}
-55
View File
@@ -1,55 +0,0 @@
// Package input is an interface for bot inputs
package input
import (
"github.com/micro/cli"
)
type EventType string
const (
TextEvent EventType = "text"
)
var (
// Inputs keyed by name
// Example slack or hipchat
Inputs = map[string]Input{}
)
// Event is the unit sent and received
type Event struct {
Type EventType
From string
To string
Data []byte
Meta map[string]interface{}
}
// Input is an interface for sources which
// provide a way to communicate with the bot.
// Slack, HipChat, XMPP, etc.
type Input interface {
// Provide cli flags
Flags() []cli.Flag
// Initialise input using cli context
Init(*cli.Context) error
// Stream events from the input
Stream() (Conn, error)
// Start the input
Start() error
// Stop the input
Stop() error
// name of the input
String() string
}
// Conn interface provides a way to
// send and receive events. Send and
// Recv both block until succeeding
// or failing.
type Conn interface {
Close() error
Recv(*Event) error
Send(*Event) error
}
-160
View File
@@ -1,160 +0,0 @@
package slack
import (
"errors"
"fmt"
"strings"
"sync"
"time"
"github.com/micro/go-micro/agent/input"
"github.com/nlopes/slack"
)
// Satisfies the input.Conn interface
type slackConn struct {
auth *slack.AuthTestResponse
rtm *slack.RTM
exit chan bool
sync.Mutex
names map[string]string
}
func (s *slackConn) run() {
// func retrieves user names and maps to IDs
setNames := func() {
names := make(map[string]string)
users, err := s.rtm.Client.GetUsers()
if err != nil {
return
}
for _, user := range users {
names[user.ID] = user.Name
}
s.Lock()
s.names = names
s.Unlock()
}
setNames()
t := time.NewTicker(time.Minute)
defer t.Stop()
for {
select {
case <-s.exit:
return
case <-t.C:
setNames()
}
}
}
func (s *slackConn) getName(id string) string {
s.Lock()
name := s.names[id]
s.Unlock()
return name
}
func (s *slackConn) Close() error {
select {
case <-s.exit:
return nil
default:
close(s.exit)
}
return nil
}
func (s *slackConn) Recv(event *input.Event) error {
if event == nil {
return errors.New("event cannot be nil")
}
for {
select {
case <-s.exit:
return errors.New("connection closed")
case e := <-s.rtm.IncomingEvents:
switch ev := e.Data.(type) {
case *slack.MessageEvent:
// only accept type message
if ev.Type != "message" {
continue
}
// only accept DMs or messages to me
switch {
case strings.HasPrefix(ev.Channel, "D"):
case strings.HasPrefix(ev.Text, s.auth.User):
case strings.HasPrefix(ev.Text, fmt.Sprintf("<@%s>", s.auth.UserID)):
default:
continue
}
// Strip username from text
switch {
case strings.HasPrefix(ev.Text, s.auth.User):
args := strings.Split(ev.Text, " ")[1:]
ev.Text = strings.Join(args, " ")
event.To = s.auth.User
case strings.HasPrefix(ev.Text, fmt.Sprintf("<@%s>", s.auth.UserID)):
args := strings.Split(ev.Text, " ")[1:]
ev.Text = strings.Join(args, " ")
event.To = s.auth.UserID
}
if event.Meta == nil {
event.Meta = make(map[string]interface{})
}
// fill in the blanks
event.From = ev.Channel + ":" + ev.User
event.Type = input.TextEvent
event.Data = []byte(ev.Text)
event.Meta["reply"] = ev
return nil
case *slack.InvalidAuthEvent:
return errors.New("invalid credentials")
}
}
}
}
func (s *slackConn) Send(event *input.Event) error {
var channel, message, name string
if len(event.To) == 0 {
return errors.New("require Event.To")
}
parts := strings.Split(event.To, ":")
if len(parts) == 2 {
channel = parts[0]
name = s.getName(parts[1])
// try using reply meta
} else if ev, ok := event.Meta["reply"]; ok {
channel = ev.(*slack.MessageEvent).Channel
name = s.getName(ev.(*slack.MessageEvent).User)
}
// don't know where to send the message
if len(channel) == 0 {
return errors.New("could not determine who message is to")
}
if len(name) == 0 || strings.HasPrefix(channel, "D") {
message = string(event.Data)
} else {
message = fmt.Sprintf("@%s: %s", name, string(event.Data))
}
s.rtm.SendMessage(s.rtm.NewOutgoingMessage(message, channel))
return nil
}
-147
View File
@@ -1,147 +0,0 @@
package slack
import (
"errors"
"sync"
"github.com/micro/cli"
"github.com/micro/go-micro/agent/input"
"github.com/nlopes/slack"
)
type slackInput struct {
debug bool
token string
sync.Mutex
running bool
exit chan bool
api *slack.Client
}
func init() {
input.Inputs["slack"] = NewInput()
}
func (p *slackInput) Flags() []cli.Flag {
return []cli.Flag{
cli.BoolFlag{
Name: "slack_debug",
Usage: "Slack debug output",
EnvVar: "MICRO_SLACK_DEBUG",
},
cli.StringFlag{
Name: "slack_token",
Usage: "Slack token",
EnvVar: "MICRO_SLACK_TOKEN",
},
}
}
func (p *slackInput) Init(ctx *cli.Context) error {
debug := ctx.Bool("slack_debug")
token := ctx.String("slack_token")
if len(token) == 0 {
return errors.New("missing slack token")
}
p.debug = debug
p.token = token
return nil
}
func (p *slackInput) Stream() (input.Conn, error) {
p.Lock()
defer p.Unlock()
if !p.running {
return nil, errors.New("not running")
}
// test auth
auth, err := p.api.AuthTest()
if err != nil {
return nil, err
}
rtm := p.api.NewRTM()
exit := make(chan bool)
go rtm.ManageConnection()
go func() {
select {
case <-p.exit:
select {
case <-exit:
return
default:
close(exit)
}
case <-exit:
}
rtm.Disconnect()
}()
conn := &slackConn{
auth: auth,
rtm: rtm,
exit: exit,
names: make(map[string]string),
}
go conn.run()
return conn, nil
}
func (p *slackInput) Start() error {
if len(p.token) == 0 {
return errors.New("missing slack token")
}
p.Lock()
defer p.Unlock()
if p.running {
return nil
}
api := slack.New(p.token, slack.OptionDebug(p.debug))
// test auth
_, err := api.AuthTest()
if err != nil {
return err
}
p.api = api
p.exit = make(chan bool)
p.running = true
return nil
}
func (p *slackInput) Stop() error {
p.Lock()
defer p.Unlock()
if !p.running {
return nil
}
close(p.exit)
p.running = false
return nil
}
func (p *slackInput) String() string {
return "slack"
}
func NewInput() input.Input {
return &slackInput{}
}
-18
View File
@@ -1,18 +0,0 @@
# Telegram Messenger input for micro bot
[Telegram](https://telegram.org) support for micro bot based on [telegram-bot-api](https://github.com/go-telegram-bot-api/telegram-bot-api).
## Options
### --telegram_token (required)
Sets bot's token for interacting with API.
Head over to Telegram's [API documentation](https://core.telegram.org/bots/api)
to learn how to create bots and how the API works.
### --telegram_debug
Sets the debug flag to make the bot's output verbose.
### --telegram_whitelist
Sets a list of comma-separated nicknames (without @ symbol in the beginning) for interacting with bot. Only these users can use the bot.
-115
View File
@@ -1,115 +0,0 @@
package telegram
import (
"errors"
"strings"
"sync"
"github.com/forestgiant/sliceutil"
"github.com/micro/go-micro/agent/input"
"github.com/micro/go-micro/util/log"
"gopkg.in/telegram-bot-api.v4"
)
type telegramConn struct {
input *telegramInput
recv <-chan tgbotapi.Update
exit chan bool
syncCond *sync.Cond
mutex sync.Mutex
}
func newConn(input *telegramInput) (*telegramConn, error) {
conn := &telegramConn{
input: input,
}
conn.syncCond = sync.NewCond(&conn.mutex)
go conn.run()
return conn, nil
}
func (tc *telegramConn) run() {
u := tgbotapi.NewUpdate(0)
u.Timeout = 60
updates, err := tc.input.api.GetUpdatesChan(u)
if err != nil {
return
}
tc.recv = updates
tc.syncCond.Signal()
for {
select {
case <-tc.exit:
return
}
}
}
func (tc *telegramConn) Close() error {
return nil
}
func (tc *telegramConn) Recv(event *input.Event) error {
if event == nil {
return errors.New("event cannot be nil")
}
for {
if tc.recv == nil {
tc.mutex.Lock()
tc.syncCond.Wait()
}
update := <-tc.recv
if update.Message == nil || (len(tc.input.whitelist) > 0 && !sliceutil.Contains(tc.input.whitelist, update.Message.From.UserName)) {
continue
}
if event.Meta == nil {
event.Meta = make(map[string]interface{})
}
event.Type = input.TextEvent
event.From = update.Message.From.UserName
event.To = tc.input.api.Self.UserName
event.Data = []byte(update.Message.Text)
event.Meta["chatId"] = update.Message.Chat.ID
event.Meta["chatType"] = update.Message.Chat.Type
event.Meta["messageId"] = update.Message.MessageID
return nil
}
}
func (tc *telegramConn) Send(event *input.Event) error {
messageText := strings.TrimSpace(string(event.Data))
chatId := event.Meta["chatId"].(int64)
chatType := ChatType(event.Meta["chatType"].(string))
msgConfig := tgbotapi.NewMessage(chatId, messageText)
msgConfig.ParseMode = tgbotapi.ModeHTML
if sliceutil.Contains([]ChatType{Group, Supergroup}, chatType) {
msgConfig.ReplyToMessageID = event.Meta["messageId"].(int)
}
_, err := tc.input.api.Send(msgConfig)
if err != nil {
// probably it could be because of nested HTML tags -- telegram doesn't allow nested tags
log.Log("[telegram][Send] error:", err)
msgConfig.Text = "This bot couldn't send the response (Internal error)"
tc.input.api.Send(msgConfig)
}
return nil
}
-101
View File
@@ -1,101 +0,0 @@
package telegram
import (
"errors"
"strings"
"sync"
"github.com/micro/cli"
"github.com/micro/go-micro/agent/input"
"gopkg.in/telegram-bot-api.v4"
)
type telegramInput struct {
sync.Mutex
debug bool
token string
whitelist []string
api *tgbotapi.BotAPI
}
type ChatType string
const (
Private ChatType = "private"
Group ChatType = "group"
Supergroup ChatType = "supergroup"
)
func init() {
input.Inputs["telegram"] = &telegramInput{}
}
func (ti *telegramInput) Flags() []cli.Flag {
return []cli.Flag{
cli.BoolFlag{
Name: "telegram_debug",
EnvVar: "MICRO_TELEGRAM_DEBUG",
Usage: "Telegram debug output",
},
cli.StringFlag{
Name: "telegram_token",
EnvVar: "MICRO_TELEGRAM_TOKEN",
Usage: "Telegram token",
},
cli.StringFlag{
Name: "telegram_whitelist",
EnvVar: "MICRO_TELEGRAM_WHITELIST",
Usage: "Telegram bot's users (comma-separated values)",
},
}
}
func (ti *telegramInput) Init(ctx *cli.Context) error {
ti.debug = ctx.Bool("telegram_debug")
ti.token = ctx.String("telegram_token")
whitelist := ctx.String("telegram_whitelist")
if whitelist != "" {
ti.whitelist = strings.Split(whitelist, ",")
}
if len(ti.token) == 0 {
return errors.New("missing telegram token")
}
return nil
}
func (ti *telegramInput) Stream() (input.Conn, error) {
ti.Lock()
defer ti.Unlock()
return newConn(ti)
}
func (ti *telegramInput) Start() error {
ti.Lock()
defer ti.Unlock()
api, err := tgbotapi.NewBotAPI(ti.token)
if err != nil {
return err
}
ti.api = api
api.Debug = ti.debug
return nil
}
func (ti *telegramInput) Stop() error {
return nil
}
func (p *telegramInput) String() string {
return "telegram"
}
+249
View File
@@ -0,0 +1,249 @@
package agent
import (
"context"
"io"
"strings"
"testing"
"go-micro.dev/v6/ai"
"go-micro.dev/v6/client"
codecBytes "go-micro.dev/v6/codec/bytes"
"go-micro.dev/v6/registry"
"go-micro.dev/v6/store"
)
// fakeGen drives the fake provider's Generate. Tests set it and reset
// it with a deferred cleanup. Tests in this package are not parallel,
// so a package-level hook is safe.
var fakeGen func(ctx context.Context, opts ai.Options, req *ai.Request) (*ai.Response, error)
var fakeStream func(ctx context.Context, opts ai.Options, req *ai.Request) (ai.Stream, error)
type fakeModel struct{ opts ai.Options }
func (m *fakeModel) Init(opts ...ai.Option) error {
for _, o := range opts {
o(&m.opts)
}
return nil
}
func (m *fakeModel) Options() ai.Options { return m.opts }
func (m *fakeModel) Generate(ctx context.Context, req *ai.Request, _ ...ai.GenerateOption) (*ai.Response, error) {
if fakeGen != nil {
return fakeGen(ctx, m.opts, req)
}
return &ai.Response{Reply: "ok"}, nil
}
func (m *fakeModel) Stream(ctx context.Context, req *ai.Request, _ ...ai.GenerateOption) (ai.Stream, error) {
if fakeStream != nil {
return fakeStream(ctx, m.opts, req)
}
return &sliceStream{chunks: []string{"ok"}}, nil
}
func (m *fakeModel) String() string { return "fake" }
type sliceStream struct {
chunks []string
idx int
closed bool
}
func (s *sliceStream) Recv() (*ai.Response, error) {
if s.idx >= len(s.chunks) {
return nil, io.EOF
}
chunk := s.chunks[s.idx]
s.idx++
return &ai.Response{Reply: chunk}, nil
}
func (s *sliceStream) Close() error {
s.closed = true
return nil
}
func init() {
ai.Register("fake", func(opts ...ai.Option) ai.Model {
m := &fakeModel{}
_ = m.Init(opts...)
return m
})
}
// fakeClient embeds the default client (so NewRequest works) and
// overrides Call with a test-supplied function.
type fakeClient struct {
client.Client
callFn func(ctx context.Context, req client.Request, rsp interface{}) error
}
func (c *fakeClient) Call(ctx context.Context, req client.Request, rsp interface{}, opts ...client.CallOption) error {
return c.callFn(ctx, req, rsp)
}
func newTestAgent(opts ...Option) *agentImpl {
base := []Option{
Provider("fake"),
WithRegistry(registry.NewMemoryRegistry()),
WithStore(store.NewMemoryStore()),
}
a := New(append(base, opts...)...).(*agentImpl)
a.setup()
return a
}
// The model is offered the plan and delegate tools, and calling the
// plan tool persists the plan to memory.
func TestAskExposesAndRunsPlan(t *testing.T) {
var sawPlan, sawDelegate bool
fakeGen = func(ctx context.Context, opts ai.Options, req *ai.Request) (*ai.Response, error) {
for _, tl := range req.Tools {
switch tl.Name {
case toolPlan:
sawPlan = true
case toolDelegate:
sawDelegate = true
}
}
// Simulate the model recording a plan.
if opts.ToolHandler != nil {
opts.ToolHandler(context.Background(), ai.ToolCall{
Name: toolPlan,
Input: map[string]any{
"steps": []any{map[string]any{"task": "step one", "status": "pending"}},
},
})
}
return &ai.Response{Answer: "done"}, nil
}
defer func() { fakeGen = nil }()
a := newTestAgent(Name("worker"))
resp, err := a.Ask(context.Background(), "do some multi-step work")
if err != nil {
t.Fatalf("Ask: %v", err)
}
if !sawPlan || !sawDelegate {
t.Errorf("model should be offered plan and delegate tools: plan=%v delegate=%v", sawPlan, sawDelegate)
}
if resp.Reply == "" {
t.Error("Ask returned empty reply")
}
if plan := a.loadPlan(); !strings.Contains(plan, "step one") {
t.Errorf("plan tool result not persisted; loadPlan() = %q", plan)
}
}
// Delegating with no matching agent creates an ephemeral sub-agent with
// a fresh, isolated context (no builtin tools) and returns its reply.
func TestDelegateEphemeral(t *testing.T) {
fakeGen = func(ctx context.Context, opts ai.Options, req *ai.Request) (*ai.Response, error) {
if strings.Contains(req.SystemPrompt, "sub-agent") {
for _, tl := range req.Tools {
if tl.Name == toolPlan || tl.Name == toolDelegate {
t.Errorf("ephemeral sub-agent must not have builtin tool %q", tl.Name)
}
}
return &ai.Response{Reply: "subtask complete"}, nil
}
return &ai.Response{Reply: "parent"}, nil
}
defer func() { fakeGen = nil }()
a := newTestAgent(Name("root"))
content := a.handleDelegate(context.Background(), ai.ToolCall{Name: "delegate", Input: map[string]any{"task": "summarize the report"}}).Content
if !strings.Contains(content, "subtask complete") {
t.Errorf("delegate should return the sub-agent's reply; got %q", content)
}
}
// Delegating to a name that resolves to a registered agent goes over
// RPC to that agent rather than spawning a sub-agent.
func TestDelegateToRegisteredAgent(t *testing.T) {
reg := registry.NewMemoryRegistry()
if err := reg.Register(&registry.Service{
Name: "comms",
Metadata: map[string]string{"type": "agent"},
Nodes: []*registry.Node{{Id: "comms-1", Address: "127.0.0.1:0"}},
}); err != nil {
t.Fatalf("register agent: %v", err)
}
var calledService, calledEndpoint string
fc := &fakeClient{Client: client.DefaultClient}
fc.callFn = func(ctx context.Context, req client.Request, rsp interface{}) error {
calledService, calledEndpoint = req.Service(), req.Endpoint()
frame := rsp.(*codecBytes.Frame)
frame.Data = []byte(`{"reply":"notified alice","agent":"comms"}`)
return nil
}
// fakeGen guards against the ephemeral path being taken by mistake.
fakeGen = func(ctx context.Context, opts ai.Options, req *ai.Request) (*ai.Response, error) {
t.Error("delegate to a registered agent must not spawn a sub-agent")
return &ai.Response{}, nil
}
defer func() { fakeGen = nil }()
a := newTestAgent(Name("root"), WithRegistry(reg), WithClient(fc))
content := a.handleDelegate(context.Background(), ai.ToolCall{Name: "delegate", Input: map[string]any{"task": "notify alice", "to": "comms"}}).Content
if calledService != "comms" || calledEndpoint != "Agent.Chat" {
t.Errorf("expected RPC to comms Agent.Chat, got %s %s", calledService, calledEndpoint)
}
if !strings.Contains(content, "notified alice") {
t.Errorf("delegate-first result missing agent reply; got %q", content)
}
}
// Delegate requires a task.
func TestDelegateRequiresTask(t *testing.T) {
a := newTestAgent(Name("root"))
content := a.handleDelegate(context.Background(), ai.ToolCall{Name: "delegate", Input: map[string]any{}}).Content
if !strings.Contains(content, "error") {
t.Errorf("delegate with no task should error; got %q", content)
}
}
func TestCompactingMemorySummarizesAndRecallsArchivedContext(t *testing.T) {
var sawSummary, sawRecall bool
fakeGen = func(ctx context.Context, opts ai.Options, req *ai.Request) (*ai.Response, error) {
for _, msg := range req.Messages {
text := msg.Content.(string)
if strings.Contains(text, "Conversation memory summary") && strings.Contains(text, "alpha project") {
sawSummary = true
}
if strings.Contains(text, "alpha project budget is 42") {
sawRecall = true
}
}
return &ai.Response{Reply: "ok"}, nil
}
defer func() { fakeGen = nil }()
a := newTestAgent(Name("memory"), CompactMemory(4, 2), MemoryRecallLimit(3))
turns := []string{
"alpha project budget is 42",
"beta project owner is sam",
"gamma project deadline is monday",
"delta project status is green",
"epsilon project risk is low",
}
for _, turn := range turns {
if _, err := a.Ask(context.Background(), turn); err != nil {
t.Fatalf("Ask(%q): %v", turn, err)
}
}
if got := len(a.mem.Messages()); got > 4 {
t.Fatalf("compacted memory retained %d messages, want <= 4", got)
}
if _, err := a.Ask(context.Background(), "what was the alpha budget?"); err != nil {
t.Fatalf("Ask recall: %v", err)
}
if !sawSummary {
t.Error("model request did not include a deterministic compacted summary")
}
if !sawRecall {
t.Error("model request did not recall archived matching context")
}
}
+71
View File
@@ -0,0 +1,71 @@
package agent
import (
"strings"
"testing"
)
// Repeating the same tool call with the same arguments is refused once it
// exceeds LoopLimit, and the model is told to change approach.
func TestLoopDetectionStopsRepeats(t *testing.T) {
a := newTestAgent(Name("looper"), LoopLimit(3))
h := a.toolHandler()
// First 3 identical calls are allowed (they fall through to RPC,
// which fails harmlessly — we only care they weren't refused as loops).
for i := 1; i <= 3; i++ {
content := toolContent(h, "demo_Svc_Do", map[string]any{"q": "x"})
if strings.Contains(content, "loop detected") {
t.Fatalf("call %d wrongly flagged as a loop", i)
}
}
// The 4th identical call is refused as a loop.
content := toolContent(h, "demo_Svc_Do", map[string]any{"q": "x"})
if !strings.Contains(content, "loop detected") {
t.Errorf("4th identical call should be refused as a loop; got %q", content)
}
}
// Different arguments are not a loop, even past the limit.
func TestLoopDetectionAllowsDistinctCalls(t *testing.T) {
a := newTestAgent(Name("distinct"), LoopLimit(2))
h := a.toolHandler()
for i := 0; i < 5; i++ {
content := toolContent(h, "demo_Svc_Do", map[string]any{"q": i}) // distinct args each time
if strings.Contains(content, "loop detected") {
t.Fatalf("distinct call %d wrongly flagged as a loop", i)
}
}
}
// LoopLimit(0) disables detection.
func TestLoopDetectionDisabled(t *testing.T) {
a := newTestAgent(Name("noloop"), LoopLimit(0))
h := a.toolHandler()
for i := 0; i < 6; i++ {
content := toolContent(h, "demo_Svc_Do", map[string]any{"q": "same"})
if strings.Contains(content, "loop detected") {
t.Fatalf("loop detection should be disabled with LoopLimit(0)")
}
}
}
// It defaults on (lenient) so repeated identical calls are caught without
// any configuration.
func TestLoopDetectionDefaultOn(t *testing.T) {
a := New(Name("d"), Provider("fake")).(*agentImpl)
a.setup()
if a.opts.LoopLimit <= 0 {
t.Fatalf("LoopLimit should default on, got %d", a.opts.LoopLimit)
}
h := a.toolHandler()
var lastContent string
for i := 0; i < a.opts.LoopLimit+1; i++ {
lastContent = toolContent(h, "demo_Svc_Do", map[string]any{})
}
if !strings.Contains(lastContent, "loop detected") {
t.Errorf("default loop detection should catch repeated calls; got %q", lastContent)
}
}
+320
View File
@@ -0,0 +1,320 @@
package agent
import (
"encoding/json"
"fmt"
"sort"
"strings"
"sync"
"go-micro.dev/v6/ai"
"go-micro.dev/v6/store"
)
// Memory is an agent's conversation memory. Like the rest of the
// framework it is pluggable: the default is store-backed and durable
// across restarts, but any implementation can be supplied with
// WithMemory — in-process, a database, or a semantic/vector store.
type Memory interface {
// Add appends a message to the conversation.
Add(role, content string)
// Messages returns the retained conversation, oldest first.
Messages() []ai.Message
// Clear resets the conversation.
Clear()
}
// MemorySummaryFunc turns older conversation messages into a compact
// replacement message for active context. It is called while the default
// memory is locked, so implementations should be deterministic and avoid
// calling back into the same memory instance.
type MemorySummaryFunc func([]ai.Message) ai.Message
// MemoryCompaction configures deterministic, store-backed context compaction
// for the default memory implementation. When the retained conversation grows
// past MaxMessages, older turns are collapsed into a summary message while the
// newest KeepRecent turns stay verbatim for provider-neutral continuity.
type MemoryCompaction struct {
MaxMessages int
KeepRecent int
Summarize MemorySummaryFunc
}
// MemoryRecall is implemented by memory backends that can retrieve durable
// prior context relevant to a new turn without replaying every stored message.
type MemoryRecall interface {
Recall(query string, limit int) []ai.Message
}
// NewMemory returns the default store-backed memory: an in-process
// conversation buffer (truncated to limit) that persists to the store
// under key, so an agent picks up where it left off after a restart.
// A nil store or empty key yields non-persistent memory.
func NewMemory(s store.Store, key string, limit int) Memory {
m := &storeMemory{store: s, key: key, hist: ai.NewHistory(limit)}
m.load()
return m
}
// NewRetrievalMemory returns store-backed memory that keeps a bounded active
// conversation and archives every turn for retrieval. It is useful when callers
// want relevant durable recall without summary compaction in the active context.
// A nil store or empty key keeps only the active in-process buffer.
func NewRetrievalMemory(s store.Store, key string, activeLimit int) Memory {
m := &storeMemory{store: s, key: key, hist: ai.NewHistory(activeLimit), retrieveAll: true}
m.load()
return m
}
// NewCompactingMemory returns store-backed memory with explicit compaction and
// retrieval controls. It keeps all messages in the backing store, compacts older
// turns into a deterministic summary when the conversation exceeds maxMessages,
// and lets callers recall relevant prior turns with Recall.
func NewCompactingMemory(s store.Store, key string, maxMessages, keepRecent int) Memory {
return NewCompactingMemoryWithOptions(s, key, MemoryCompaction{MaxMessages: maxMessages, KeepRecent: keepRecent})
}
// NewCompactingMemoryWithOptions returns store-backed memory configured with
// explicit compaction options, including an optional summarization hook.
func NewCompactingMemoryWithOptions(s store.Store, key string, compaction MemoryCompaction) Memory {
maxMessages := compaction.MaxMessages
keepRecent := compaction.KeepRecent
if keepRecent <= 0 {
keepRecent = maxMessages / 2
}
if keepRecent < 1 {
keepRecent = 1
}
m := &storeMemory{
store: s,
key: key,
// Use an unlimited buffer here; compaction, not truncation, decides
// what remains in active context so a summary can preserve older turns.
hist: ai.NewHistory(0),
compaction: MemoryCompaction{
MaxMessages: maxMessages,
KeepRecent: keepRecent,
Summarize: compaction.Summarize,
},
}
m.load()
m.compact()
return m
}
// NewInMemory returns conversation memory that is not persisted.
func NewInMemory(limit int) Memory {
return &storeMemory{hist: ai.NewHistory(limit)}
}
// storeMemory is the default Memory: an ai.History buffer optionally
// persisted to a store.
type storeMemory struct {
mu sync.Mutex
store store.Store
key string
hist *ai.History
compaction MemoryCompaction
archive []ai.Message
retrieveAll bool
}
func (m *storeMemory) Add(role, content string) {
m.mu.Lock()
if m.retrieveAll {
m.archive = append(m.archive, ai.Message{Role: role, Content: content})
}
m.hist.Add(role, content)
m.mu.Unlock()
m.compact()
m.save()
}
func (m *storeMemory) Messages() []ai.Message {
m.mu.Lock()
defer m.mu.Unlock()
return m.hist.Messages()
}
func (m *storeMemory) Clear() {
m.mu.Lock()
m.hist.Reset()
m.archive = nil
m.mu.Unlock()
m.save()
}
// Recall returns archived messages whose content contains words from query.
// It is deterministic and provider-neutral: no embeddings or model calls are
// required, but semantic/vector stores can replace Memory for richer retrieval.
// When created with NewRetrievalMemory the archive contains every persisted
// turn; when created with NewCompactingMemory it contains compacted older turns.
func (m *storeMemory) Recall(query string, limit int) []ai.Message {
m.mu.Lock()
defer m.mu.Unlock()
if limit <= 0 {
limit = 5
}
terms := recallTerms(query)
type match struct {
msg ai.Message
score int
index int
}
matches := make([]match, 0, len(m.archive))
for i := len(m.archive) - 1; i >= 0; i-- {
msg := m.archive[i]
if score := recallScore(msg, terms); score > 0 {
matches = append(matches, match{msg: msg, score: score, index: i})
}
}
sort.SliceStable(matches, func(i, j int) bool {
if matches[i].score != matches[j].score {
return matches[i].score > matches[j].score
}
return matches[i].index > matches[j].index
})
if len(matches) > limit {
matches = matches[:limit]
}
out := make([]ai.Message, 0, len(matches))
for _, match := range matches {
out = append(out, match.msg)
}
return out
}
func (m *storeMemory) load() {
if m.store == nil || m.key == "" {
return
}
recs, err := m.store.Read(m.key)
if err != nil || len(recs) == 0 {
return
}
var state memoryState
if err := json.Unmarshal(recs[0].Value, &state); err != nil {
var msgs []ai.Message
if err := json.Unmarshal(recs[0].Value, &msgs); err != nil {
return
}
state.Messages = msgs
}
m.mu.Lock()
m.archive = state.Archive
if m.retrieveAll && len(m.archive) == 0 {
m.archive = append(m.archive, state.Messages...)
}
for _, msg := range state.Messages {
m.hist.Add(msg.Role, msg.Content)
}
m.mu.Unlock()
}
func (m *storeMemory) save() {
if m.store == nil || m.key == "" {
return
}
m.mu.Lock()
data, err := json.Marshal(memoryState{
Messages: m.hist.Messages(),
Archive: m.archive,
})
m.mu.Unlock()
if err != nil {
return
}
_ = m.store.Write(&store.Record{Key: m.key, Value: data})
}
func (m *storeMemory) compact() {
if m.compaction.MaxMessages <= 0 {
return
}
m.mu.Lock()
defer m.mu.Unlock()
msgs := m.hist.Messages()
if len(msgs) <= m.compaction.MaxMessages {
return
}
keep := m.compaction.KeepRecent
if keep <= 0 || keep >= m.compaction.MaxMessages {
keep = m.compaction.MaxMessages - 1
}
if keep < 1 {
keep = 1
}
cut := len(msgs) - keep
older := msgs[:cut]
recent := msgs[cut:]
m.archive = append(m.archive, older...)
summarize := m.compaction.Summarize
if summarize == nil {
summarize = defaultMemorySummary
}
summary := summarize(older)
if summary.Role == "" {
summary.Role = "system"
}
m.hist.Reset()
m.hist.Add(summary.Role, summary.Content)
for _, msg := range recent {
m.hist.Add(msg.Role, msg.Content)
}
}
func defaultMemorySummary(msgs []ai.Message) ai.Message {
return ai.Message{
Role: "system",
Content: fmt.Sprintf("Conversation memory summary: %s", summarizeMessages(msgs)),
}
}
func summarizeMessages(msgs []ai.Message) string {
var b strings.Builder
for i, msg := range msgs {
if i > 0 {
b.WriteString(" | ")
}
fmt.Fprintf(&b, "%s: %s", msg.Role, compactText(fmt.Sprint(msg.Content), 120))
}
return b.String()
}
func compactText(s string, max int) string {
s = strings.Join(strings.Fields(s), " ")
if max > 0 && len(s) > max {
return s[:max] + "…"
}
return s
}
func recallScore(msg ai.Message, terms []string) int {
text := strings.ToLower(fmt.Sprint(msg.Content))
score := 0
for _, term := range terms {
if strings.Contains(text, term) {
score++
}
}
return score
}
func recallTerms(query string) []string {
seen := map[string]bool{}
var terms []string
for _, term := range strings.Fields(strings.ToLower(query)) {
term = strings.Trim(term, ".,!?;:\"'()[]{}")
if len(term) < 3 || seen[term] {
continue
}
seen[term] = true
terms = append(terms, term)
}
return terms
}
type memoryState struct {
Messages []ai.Message `json:"messages"`
Archive []ai.Message `json:"archive,omitempty"`
}
+229
View File
@@ -0,0 +1,229 @@
package agent
import (
"context"
"errors"
"strconv"
"strings"
"testing"
"go-micro.dev/v6/ai"
"go-micro.dev/v6/registry"
"go-micro.dev/v6/store"
)
func TestStoreMemoryPersists(t *testing.T) {
st := store.NewMemoryStore()
m := NewMemory(st, "agent/x/history", 10)
m.Add("user", "hello")
m.Add("assistant", "hi there")
// A fresh memory over the same store/key restores the conversation.
reloaded := NewMemory(st, "agent/x/history", 10)
if got := len(reloaded.Messages()); got != 2 {
t.Fatalf("restored %d messages, want 2", got)
}
}
func TestInMemoryNotPersisted(t *testing.T) {
m := NewInMemory(10)
m.Add("user", "x")
if got := len(m.Messages()); got != 1 {
t.Fatalf("got %d messages, want 1", got)
}
if got := len(NewInMemory(10).Messages()); got != 0 {
t.Errorf("a separate in-memory should be empty, got %d", got)
}
}
func TestMemoryClearPersists(t *testing.T) {
st := store.NewMemoryStore()
m := NewMemory(st, "agent/y/history", 10)
m.Add("user", "x")
m.Clear()
if got := len(m.Messages()); got != 0 {
t.Errorf("after Clear got %d messages, want 0", got)
}
if got := len(NewMemory(st, "agent/y/history", 10).Messages()); got != 0 {
t.Errorf("cleared state should persist, reload got %d", got)
}
}
func TestWithMemoryUsed(t *testing.T) {
custom := NewInMemory(5)
a := New(
Name("z"),
Provider("fake"),
WithRegistry(registry.NewMemoryRegistry()),
WithStore(store.NewMemoryStore()),
WithMemory(custom),
).(*agentImpl)
a.setup()
if a.mem != custom {
t.Error("WithMemory should make the agent use the supplied memory")
}
}
func TestRetrievalMemoryArchivesAllTurnsAndRanksRelevant(t *testing.T) {
st := store.NewMemoryStore()
m := NewRetrievalMemory(st, "agent/retrieval/history", 2)
m.Add("user", "alpha budget is 42")
m.Add("assistant", "noted")
m.Add("user", "beta owner is lee")
m.Add("assistant", "tracked")
m.Add("user", "alpha owner is sam")
if got := len(m.Messages()); got != 2 {
t.Fatalf("active messages = %d, want bounded history of 2", got)
}
recall, ok := m.(MemoryRecall)
if !ok {
t.Fatal("retrieval memory should support recall")
}
recalled := recall.Recall("alpha budget", 2)
if len(recalled) == 0 {
t.Fatal("expected relevant recalled turns")
}
if got := recalled[0].Content.(string); !strings.Contains(got, "alpha budget is 42") {
t.Fatalf("top recall = %q, want archived alpha budget turn", got)
}
}
func TestRetrievalMemoryPersistsArchiveAcrossReload(t *testing.T) {
st := store.NewMemoryStore()
m := NewRetrievalMemory(st, "agent/retrieval/reload", 1)
m.Add("user", "alpha budget is 42")
m.Add("assistant", "noted")
m.Add("user", "beta budget is 7")
reloaded := NewRetrievalMemory(st, "agent/retrieval/reload", 1)
recalled := reloaded.(MemoryRecall).Recall("alpha budget", 1)
if len(recalled) != 1 {
t.Fatalf("recalled %d messages, want 1", len(recalled))
}
if got := recalled[0].Content.(string); !strings.Contains(got, "alpha budget is 42") {
t.Fatalf("reloaded recall = %q, want alpha budget", got)
}
}
func TestCompactingMemoryRecallRanksSpecificMatches(t *testing.T) {
m := NewCompactingMemory(store.NewMemoryStore(), "agent/rank/history", 3, 1).(MemoryRecall)
writer := m.(Memory)
writer.Add("user", "alpha budget is 42")
writer.Add("assistant", "noted")
writer.Add("user", "beta budget is 7")
writer.Add("assistant", "noted")
writer.Add("user", "alpha owner is sam")
recalled := m.Recall("alpha budget", 2)
if len(recalled) == 0 {
t.Fatal("expected recalled messages")
}
if got := recalled[0].Content.(string); !strings.Contains(got, "alpha budget is 42") {
t.Fatalf("top recall = %q, want alpha budget match", got)
}
}
func TestCompactingMemoryArchivePersistsAndReloads(t *testing.T) {
st := store.NewMemoryStore()
m := NewCompactingMemory(st, "agent/reload/history", 3, 1)
m.Add("user", "alpha budget is 42")
m.Add("assistant", "noted")
m.Add("user", "beta budget is 7")
m.Add("assistant", "noted")
reloaded := NewCompactingMemory(st, "agent/reload/history", 3, 1)
recall, ok := reloaded.(MemoryRecall)
if !ok {
t.Fatal("compacting memory should support recall")
}
recalled := recall.Recall("alpha budget", 1)
if len(recalled) != 1 {
t.Fatalf("recalled %d messages, want 1", len(recalled))
}
if got := recalled[0].Content.(string); !strings.Contains(got, "alpha budget is 42") {
t.Fatalf("reloaded recall = %q, want alpha budget", got)
}
}
func TestCompactingMemoryUsesCustomSummarizerAndReloadsRecall(t *testing.T) {
st := store.NewMemoryStore()
m := NewCompactingMemoryWithOptions(st, "agent/custom/history", MemoryCompaction{
MaxMessages: 3,
KeepRecent: 1,
Summarize: func(msgs []ai.Message) ai.Message {
return ai.Message{Role: "system", Content: "custom summary count=" + strconv.Itoa(len(msgs))}
},
})
m.Add("user", "alpha budget is 42")
m.Add("assistant", "noted")
m.Add("user", "beta budget is 7")
m.Add("assistant", "noted")
msgs := m.Messages()
if len(msgs) == 0 || msgs[0].Content != "custom summary count=3" {
t.Fatalf("summary = %#v, want custom summarizer output", msgs)
}
reloaded := NewCompactingMemoryWithOptions(st, "agent/custom/history", MemoryCompaction{MaxMessages: 3, KeepRecent: 1})
recall := reloaded.(MemoryRecall)
recalled := recall.Recall("alpha budget", 1)
if len(recalled) != 1 {
t.Fatalf("recalled %d messages, want 1", len(recalled))
}
if got := recalled[0].Content.(string); !strings.Contains(got, "alpha budget is 42") {
t.Fatalf("reloaded recall = %q, want alpha budget", got)
}
}
// A custom tool is offered to the model and dispatched to its handler.
func TestWithToolExposedAndDispatched(t *testing.T) {
var got map[string]any
a := newTestAgent(Name("calc-agent"),
WithTool("calc", "adds two numbers",
map[string]any{
"a": map[string]any{"type": "number"},
"b": map[string]any{"type": "number"},
},
func(ctx context.Context, input map[string]any) (string, error) {
got = input
return `{"sum":3}`, nil
}))
tools, err := a.discoverTools()
if err != nil {
t.Fatalf("discoverTools: %v", err)
}
found := false
for _, tl := range tools {
if tl.Name == "calc" {
found = true
}
}
if !found {
t.Fatal("custom tool 'calc' was not offered to the model")
}
content := toolContent(a.toolHandler(), "calc", map[string]any{"a": 1.0, "b": 2.0})
if got == nil {
t.Fatal("custom tool handler was not called")
}
if !strings.Contains(content, "sum") {
t.Errorf("custom tool result not returned: %q", content)
}
}
// A custom tool returning an error surfaces it to the model.
func TestWithToolError(t *testing.T) {
a := newTestAgent(Name("err-agent"),
WithTool("boom", "always fails", nil,
func(ctx context.Context, input map[string]any) (string, error) {
return "", errors.New("kaboom")
}))
content := toolContent(a.toolHandler(), "boom", nil)
if !strings.Contains(content, "kaboom") {
t.Errorf("tool error not surfaced: %q", content)
}
}
+381
View File
@@ -0,0 +1,381 @@
package agent
import (
"context"
"time"
"go-micro.dev/v6/ai"
"go-micro.dev/v6/broker"
"go-micro.dev/v6/client"
"go-micro.dev/v6/flow"
"go-micro.dev/v6/registry"
"go-micro.dev/v6/store"
"go.opentelemetry.io/otel/trace"
)
// Option configures an Agent.
type Option func(*Options)
// ApproveFunc decides whether an agent may execute a tool call before it
// runs. Returning false blocks the call; the reason is shown to the
// model so it can adapt. Use it for human-in-the-loop approval or policy
// checks. It is called for actions (service tools and delegate), not for
// the internal plan tool.
type ApproveFunc func(tool string, input map[string]any) (approved bool, reason string)
// ToolFunc handles a custom tool call. Return the result as a string
// (often JSON); return an error to report failure back to the model.
type ToolFunc func(ctx context.Context, input map[string]any) (string, error)
// customTool is a developer-registered tool beyond the agent's services.
type customTool struct {
def ai.Tool
handler ToolFunc
}
// Options holds agent configuration.
type Options struct {
Name string
Services []string
Prompt string
Provider string
Model string
APIKey string
BaseURL string
Address string
Registry registry.Registry
Client client.Client
Broker broker.Broker
Store store.Store
HistoryLimit int
// ModelTimeout bounds each provider Generate call (0 disables).
ModelTimeout time.Duration
// ModelMaxAttempts bounds provider Generate attempts including the first
// call. Default 1 — retries are opt-in (enable with ModelRetry). A Generate
// runs the whole tool-execution turn, so auto-retrying it would re-run
// already-executed, possibly side-effecting tool calls; keep it explicit.
ModelMaxAttempts int
// ModelRetryBackoff is the base delay between transient provider failures
// (grows exponentially per attempt when retries are enabled).
ModelRetryBackoff time.Duration
// ToolTimeout bounds each tool execution (0 disables). The timeout is
// applied before custom tools, delegate, and service RPC calls so context
// deadlines propagate consistently through the agent loop.
ToolTimeout time.Duration
// ToolMaxAttempts bounds tool execution attempts including the first call.
// Default 1; retries are opt-in because tools can have side effects.
ToolMaxAttempts int
// ToolRetryBackoff is the base delay between transient tool failures.
ToolRetryBackoff time.Duration
// Memory is the agent's conversation memory. Nil = the default
// store-backed memory (durable across restarts).
Memory Memory
// MemoryRetrievalLimit enables retrieval-backed default memory without
// compaction. The active conversation stays bounded to this many messages
// while every turn is archived for deterministic recall.
MemoryRetrievalLimit int
// MemoryCompaction enables deterministic compaction/retrieval on the
// default store-backed memory. Custom Memory implementations can expose
// retrieval by implementing MemoryRecall.
MemoryCompaction MemoryCompaction
// MemoryRecallLimit bounds recalled archived turns injected into a model
// request (0 disables recall injection).
MemoryRecallLimit int
// Checkpoint persists agent Ask runs so callers can resume by run id
// after a restart without replaying a run that already completed.
Checkpoint flow.Checkpoint
// MaxSteps bounds the number of tool executions per Ask (0 =
// unbounded). Once exceeded, further tool calls are refused and the
// model is told to stop and summarize. A stopping condition.
MaxSteps int
// LoopLimit bounds how many times the agent may call the same tool
// with the same arguments in one Ask before the call is refused as a
// no-progress loop (0 = disabled). Catches the agent repeating an
// identical action — which MaxSteps only bounds by total count.
LoopLimit int
// Approve gates each action before it runs. Nil = allow all.
Approve ApproveFunc
// A2AAddress, if set, makes Run serve this agent over the A2A protocol
// on that address directly (no separate gateway), e.g. ":4000".
A2AAddress string
// TraceProvider enables OpenTelemetry spans for agent runs, model calls,
// and tool calls. Nil disables instrumentation.
TraceProvider trace.TracerProvider
// TraceInputs controls whether agent observability records include raw
// user messages. It is false by default so spans and persisted run
// timelines carry correlation and shape without leaking prompts.
TraceInputs bool
// tools are developer-registered custom tools (see WithTool).
tools []customTool
// wrappers are developer-registered tool-execution wrappers
// (see WrapTool), applied outside the built-in guardrails.
wrappers []ai.ToolWrapper
}
func newOptions(opts ...Option) Options {
o := Options{
Registry: registry.DefaultRegistry,
Client: client.DefaultClient,
Store: store.DefaultStore,
HistoryLimit: 50,
ModelTimeout: 30 * time.Second,
ModelMaxAttempts: 1, // retries opt-in via ModelRetry (see field doc)
ModelRetryBackoff: 100 * time.Millisecond,
ToolTimeout: 30 * time.Second,
ToolMaxAttempts: 1,
ToolRetryBackoff: 100 * time.Millisecond,
// On by default and lenient: identical repeated calls are a
// no-progress loop, never useful. Set LoopLimit(0) to disable.
LoopLimit: 3,
}
for _, opt := range opts {
opt(&o)
}
return o
}
// Name sets the agent name.
func Name(n string) Option {
return func(o *Options) { o.Name = n }
}
// Services sets which services this agent manages.
func Services(names ...string) Option {
return func(o *Options) { o.Services = names }
}
// Prompt sets the system prompt.
func Prompt(p string) Option {
return func(o *Options) { o.Prompt = p }
}
// Provider sets the LLM provider.
func Provider(p string) Option {
return func(o *Options) { o.Provider = p }
}
// Model sets the LLM model name.
func Model(m string) Option {
return func(o *Options) { o.Model = m }
}
// APIKey sets the API key for the LLM provider.
func APIKey(k string) Option {
return func(o *Options) { o.APIKey = k }
}
// BaseURL sets the base URL for the LLM provider. Use this to point
// the provider at a non-default endpoint (e.g., local Ollama, a proxy).
func BaseURL(url string) Option {
return func(o *Options) { o.BaseURL = url }
}
// Address sets the network address for the agent's service endpoint.
// Use "127.0.0.1:0" in local harnesses/tests to bind an ephemeral loopback
// port and avoid advertising the default service address.
func Address(addr string) Option {
return func(o *Options) { o.Address = addr }
}
// WithRegistry sets the service registry.
func WithRegistry(r registry.Registry) Option {
return func(o *Options) { o.Registry = r }
}
// WithClient sets the RPC client.
func WithClient(c client.Client) Option {
return func(o *Options) { o.Client = c }
}
// WithBroker sets the broker used by the agent service endpoint. Use an
// in-memory broker in local harnesses/tests to avoid sharing the package-wide
// default broker listener across concurrently running examples.
func WithBroker(b broker.Broker) Option {
return func(o *Options) { o.Broker = b }
}
// WithStore sets the store for agent memory.
func WithStore(s store.Store) Option {
return func(o *Options) { o.Store = s }
}
// HistoryLimit sets the max conversation messages to retain.
func HistoryLimit(n int) Option {
return func(o *Options) { o.HistoryLimit = n }
}
// MaxSteps bounds tool executions per Ask (0 = unbounded). A stopping
// condition: beyond the limit, tool calls are refused and the model is
// told to stop and summarize.
func MaxSteps(n int) Option {
return func(o *Options) { o.MaxSteps = n }
}
// ApproveTool sets a human-in-the-loop / policy hook called before each
// action (service tools and delegate). Returning false blocks the call.
func ApproveTool(fn ApproveFunc) Option {
return func(o *Options) { o.Approve = fn }
}
// LoopLimit sets how many times the agent may repeat the same tool call
// (same name and arguments) in one Ask before it is refused as a
// no-progress loop. 0 disables loop detection.
func LoopLimit(n int) Option {
return func(o *Options) { o.LoopLimit = n }
}
// ModelCallTimeout sets the timeout for each provider Generate call.
func ModelCallTimeout(d time.Duration) Option {
return func(o *Options) { o.ModelTimeout = d }
}
// ToolCallTimeout sets the timeout for each tool execution. It bounds custom
// tools, built-in delegate calls, and service RPC tools with the same context
// deadline so mid-run cancellation and slow tools produce safe error results
// instead of unbounded agent runs. Set 0 to disable.
func ToolCallTimeout(d time.Duration) Option {
return func(o *Options) { o.ToolTimeout = d }
}
// ModelRetry sets the provider retry budget and backoff for transient failures.
func ModelRetry(maxAttempts int, backoff time.Duration) Option {
return func(o *Options) {
o.ModelMaxAttempts = maxAttempts
o.ModelRetryBackoff = backoff
}
}
// ToolRetry sets the tool retry budget and backoff for transient failures.
// Attempts include the first call. Retries are opt-in because tools may have
// side effects; keep handlers idempotent before enabling this.
func ToolRetry(maxAttempts int, backoff time.Duration) Option {
return func(o *Options) {
o.ToolMaxAttempts = maxAttempts
o.ToolRetryBackoff = backoff
}
}
// WithA2A makes Run serve the agent over the A2A protocol on addr (e.g.
// ":4000"), so other agents can reach it directly by URL without a
// separate gateway. The agent stays a normal go-micro service as well;
// this adds a second, A2A-native HTTP endpoint that calls it in-process.
func WithA2A(addr string) Option {
return func(o *Options) { o.A2AAddress = addr }
}
// WithMemory sets the agent's conversation memory. The default is
// store-backed memory keyed by agent name; supply your own to use an
// in-process, database, or semantic store.
func WithMemory(m Memory) Option {
return func(o *Options) { o.Memory = m }
}
// RetrievalMemory enables deterministic, store-backed retrieval memory for
// the default agent memory without compaction. Active context is capped at
// activeLimit messages while every turn is archived in the store for Recall.
func RetrievalMemory(activeLimit int) Option {
return func(o *Options) {
o.MemoryRetrievalLimit = activeLimit
if o.MemoryRecallLimit == 0 {
o.MemoryRecallLimit = 5
}
}
}
// CompactMemory enables deterministic, store-backed memory compaction for the
// default agent memory. Older turns are summarized once active context exceeds
// maxMessages, keepRecent newest turns remain verbatim, and recalled archived
// turns are injected into matching future asks.
func CompactMemory(maxMessages, keepRecent int) Option {
return func(o *Options) {
o.MemoryCompaction.MaxMessages = maxMessages
o.MemoryCompaction.KeepRecent = keepRecent
if o.MemoryRecallLimit == 0 {
o.MemoryRecallLimit = 5
}
}
}
// MemorySummarizer sets the deterministic summarization hook used by the
// default compacting memory. It is optional; without it, compacted memory uses
// a provider-neutral text summary. The hook receives the older messages being
// removed from active context and returns the replacement summary message.
func MemorySummarizer(fn MemorySummaryFunc) Option {
return func(o *Options) { o.MemoryCompaction.Summarize = fn }
}
// MemoryRecallLimit sets how many archived turns a memory backend may inject
// into a model request for the current Ask. Use 0 to disable retrieval.
func MemoryRecallLimit(n int) Option {
return func(o *Options) { o.MemoryRecallLimit = n }
}
// WithCheckpoint sets the durability backend for agent Ask runs. The
// Checkpoint interface is shared with flow so services, agents, and workflows
// can use one execution history backend. When set, each Ask is saved as a
// single-step run keyed by run id; Resume returns a completed run's persisted
// response instead of calling the model again.
func WithCheckpoint(c flow.Checkpoint) Option {
return func(o *Options) { o.Checkpoint = c }
}
// WrapTool registers a tool-execution wrapper, the tool-side analog of
// a client/server middleware wrapper. Each wrapper takes the next handler
// and returns a new one; code before the next(...) call runs before the
// tool executes, code after runs after. Use it for logging, metrics,
// retries, or custom policy. Wrappers run outside the built-in guardrails
// (MaxSteps, LoopLimit, ApproveTool), so they observe every call and its
// result, including refusals. Multiple wrappers compose outermost-first.
//
// micro.NewAgent("worker", micro.AgentWrapTool(
// func(next ai.ToolHandler) ai.ToolHandler {
// return func(ctx context.Context, call ai.ToolCall) ai.ToolResult {
// res := next(ctx, call)
// log.Printf("id=%s tool=%s", call.ID, call.Name)
// return res
// }
// }))
func WrapTool(w ...ai.ToolWrapper) Option {
return func(o *Options) {
o.wrappers = append(o.wrappers, w...)
}
}
// WithTool registers a custom tool the agent can call, beyond the
// services it discovers — a local function, an external API, anything.
// properties is the JSON-schema map for the tool's parameters.
func WithTool(name, description string, properties map[string]any, handler ToolFunc) Option {
return func(o *Options) {
o.tools = append(o.tools, customTool{
def: ai.Tool{
Name: name,
OriginalName: name,
Description: description,
Properties: properties,
},
handler: handler,
})
}
}
// TraceProvider enables OpenTelemetry tracing for agent runs. The persisted
// run timeline is recorded even when TraceProvider is nil; trace/span IDs are
// added only when a provider is configured.
func TraceProvider(tp trace.TracerProvider) Option {
return func(o *Options) { o.TraceProvider = tp }
}
// TraceInputs opts in to recording raw user messages on agent run events.
// By default inputs are redacted from OpenTelemetry spans and persisted run
// timelines; use this only when the observability backend is approved to store
// prompt content.
func TraceInputs(enabled bool) Option {
return func(o *Options) { o.TraceInputs = enabled }
}
+688
View File
@@ -0,0 +1,688 @@
package agent
import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"sort"
"strings"
"time"
"go-micro.dev/v6/ai"
"go-micro.dev/v6/store"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/trace"
)
const agentInstrumentationName = "go-micro.dev/v6/agent"
const (
spanNameRun = "agent.run"
spanNameModelCall = "agent.model.call"
spanNameModelStream = "agent.model.stream"
spanNameToolCall = "agent.tool.call"
AttrRunID = "agent.run.id"
AttrParentRunID = "agent.run.parent_id"
AttrAgentName = "agent.name"
AttrProvider = "agent.model.provider"
AttrModel = "agent.model.name"
AttrLatencyMS = "agent.latency_ms"
AttrInputTokens = "agent.tokens.input"
AttrOutputTokens = "agent.tokens.output"
AttrTotalTokens = "agent.tokens.total"
AttrAttempt = "agent.model.attempt"
AttrMaxAttempts = "agent.model.max_attempts"
AttrToolAttempt = "agent.tool.attempt"
AttrToolMaxAttempts = "agent.tool.max_attempts"
AttrToolName = "agent.tool.name"
AttrDelegate = "agent.delegate"
AttrGuardrailBlock = "agent.guardrail.block"
AttrRefusal = "agent.refusal"
AttrInputChars = "agent.input.chars"
AttrErrorKind = "agent.error.kind"
AttrCheckpointStatus = "agent.checkpoint.status"
AttrCheckpointStage = "agent.checkpoint.stage"
AttrFlowName = "agent.flow.name"
AttrFlowStep = "agent.flow.step"
AttrDispatch = "agent.dispatch"
AttrTrigger = "agent.trigger"
AttrRunEventKind = "agent.event.kind"
)
type RunEvent struct {
Time time.Time `json:"time"`
RunID string `json:"run_id"`
ParentID string `json:"parent_id,omitempty"`
TraceID string `json:"trace_id,omitempty"`
SpanID string `json:"span_id,omitempty"`
Agent string `json:"agent"`
Kind string `json:"kind"`
Name string `json:"name,omitempty"`
Provider string `json:"provider,omitempty"`
Model string `json:"model,omitempty"`
Attempt int `json:"attempt,omitempty"`
MaxAttempts int `json:"max_attempts,omitempty"`
LatencyMS int64 `json:"latency_ms,omitempty"`
Tokens Usage `json:"tokens,omitempty"`
Refused string `json:"refused,omitempty"`
Status string `json:"status,omitempty"`
Error string `json:"error,omitempty"`
ErrorKind string `json:"error_kind,omitempty"`
InputChars int `json:"input_chars,omitempty"`
}
type Usage = ai.Usage
// RunListOptions controls how recorded agent run summaries are returned.
// Zero values preserve the full deterministic run list.
type RunListOptions struct {
// Status, when set, keeps only runs with the matching status
// (for example "running", "done", "canceled", "timeout",
// "rate_limited", "error", or "refused").
Status string
// TraceID, when set, keeps only runs correlated with this trace id.
// A prefix is accepted so operators can paste the shortened trace id
// printed by `micro runs`.
TraceID string
// Limit, when positive, returns the most recently updated runs up to
// the limit. Limited results are ordered newest first.
Limit int
}
// RunSummary is a compact index entry for a recorded agent run.
type RunSummary struct {
RunID string `json:"run_id"`
Agent string `json:"agent"`
ParentID string `json:"parent_id,omitempty"`
TraceID string `json:"trace_id,omitempty"`
SpanID string `json:"span_id,omitempty"`
StartedAt time.Time `json:"started_at"`
UpdatedAt time.Time `json:"updated_at"`
DurationMS int64 `json:"duration_ms,omitempty"`
Events int `json:"events"`
Status string `json:"status,omitempty"`
Checkpoint string `json:"checkpoint,omitempty"`
Stage string `json:"stage,omitempty"`
LastKind string `json:"last_kind,omitempty"`
LastError string `json:"last_error,omitempty"`
LastErrorKind string `json:"last_error_kind,omitempty"`
}
func (a *agentImpl) tracer() trace.Tracer {
return a.opts.TraceProvider.Tracer(agentInstrumentationName)
}
func (a *agentImpl) startRun(ctx context.Context, message string) (context.Context, func(error)) {
info, _ := ai.RunInfoFrom(ctx)
start := time.Now()
runEvent := RunEvent{Time: start, RunID: info.RunID, ParentID: info.ParentID, Agent: info.Agent, Kind: "run", InputChars: len(message)}
if a.opts.TraceInputs {
runEvent.Name = message
}
if a.opts.TraceProvider == nil {
a.recordRunEvent(runEvent)
return ctx, func(err error) {
latency := time.Since(start).Milliseconds()
if err != nil {
a.recordRunEvent(RunEvent{Time: time.Now(), RunID: info.RunID, ParentID: info.ParentID, Agent: info.Agent, Kind: "error", LatencyMS: latency, Error: err.Error(), ErrorKind: string(ai.ClassifyError(err))})
return
}
a.recordRunEvent(RunEvent{Time: time.Now(), RunID: info.RunID, ParentID: info.ParentID, Agent: info.Agent, Kind: "done", LatencyMS: latency})
}
}
attrs := appendRunInfoAttributes([]attribute.KeyValue{
attribute.String(AttrRunID, info.RunID),
attribute.String(AttrParentRunID, info.ParentID),
attribute.String(AttrAgentName, info.Agent),
}, info)
ctx, span := a.tracer().Start(ctx, spanNameRun, trace.WithSpanKind(trace.SpanKindInternal), trace.WithAttributes(attrs...))
a.recordSpanEvent(span, runEvent)
return ctx, func(err error) {
latency := time.Since(start).Milliseconds()
span.SetAttributes(attribute.Int64(AttrLatencyMS, latency))
if err != nil {
span.SetAttributes(attribute.String(AttrErrorKind, string(ai.ClassifyError(err))))
span.RecordError(err)
span.SetStatus(codes.Error, err.Error())
a.recordSpanEvent(span, RunEvent{Time: time.Now(), RunID: info.RunID, ParentID: info.ParentID, Agent: info.Agent, Kind: "error", LatencyMS: latency, Error: err.Error(), ErrorKind: string(ai.ClassifyError(err))})
} else {
span.SetStatus(codes.Ok, "")
a.recordSpanEvent(span, RunEvent{Time: time.Now(), RunID: info.RunID, ParentID: info.ParentID, Agent: info.Agent, Kind: "done", LatencyMS: latency})
}
span.End()
}
}
type tracedModel struct {
ai.Model
a *agentImpl
}
func (a *agentImpl) tracedModel(m ai.Model) ai.Model { return &tracedModel{Model: m, a: a} }
func (m *tracedModel) Generate(ctx context.Context, req *ai.Request, opts ...ai.GenerateOption) (*ai.Response, error) {
info, _ := ai.RunInfoFrom(ctx)
provider := m.String()
model := m.Options().Model
start := time.Now()
if m.a.opts.TraceProvider == nil {
resp, err := m.Model.Generate(ctx, req, opts...)
dur := time.Since(start).Milliseconds()
usage := ai.Usage{}
if resp != nil {
usage = resp.Usage
}
e := RunEvent{Time: time.Now(), RunID: info.RunID, ParentID: info.ParentID, Agent: info.Agent, Kind: "model", Provider: provider, Model: model, Attempt: info.Attempt, MaxAttempts: info.MaxAttempts, LatencyMS: dur, Tokens: usage}
if err != nil {
e.Error = err.Error()
e.ErrorKind = string(ai.ClassifyError(err))
}
m.a.recordRunEvent(e)
return resp, err
}
attrs := appendRunInfoAttributes([]attribute.KeyValue{
attribute.String(AttrRunID, info.RunID),
attribute.String(AttrParentRunID, info.ParentID),
attribute.String(AttrAgentName, info.Agent),
attribute.String(AttrProvider, provider),
attribute.String(AttrModel, model),
}, info)
ctx, span := m.a.tracer().Start(ctx, spanNameModelCall, trace.WithAttributes(attrs...))
resp, err := m.Model.Generate(ctx, req, opts...)
dur := time.Since(start).Milliseconds()
attrs = []attribute.KeyValue{attribute.Int64(AttrLatencyMS, dur)}
if info.Attempt > 0 {
attrs = append(attrs, attribute.Int(AttrAttempt, info.Attempt))
}
if info.MaxAttempts > 0 {
attrs = append(attrs, attribute.Int(AttrMaxAttempts, info.MaxAttempts))
}
usage := ai.Usage{}
if resp != nil {
usage = resp.Usage
attrs = appendUsage(attrs, usage)
}
span.SetAttributes(attrs...)
if err != nil {
span.SetAttributes(attribute.String(AttrErrorKind, string(ai.ClassifyError(err))))
span.RecordError(err)
span.SetStatus(codes.Error, err.Error())
} else {
span.SetStatus(codes.Ok, "")
}
e := RunEvent{Time: time.Now(), RunID: info.RunID, ParentID: info.ParentID, Agent: info.Agent, Kind: "model", Provider: provider, Model: model, Attempt: info.Attempt, MaxAttempts: info.MaxAttempts, LatencyMS: dur, Tokens: usage}
if err != nil {
e.Error = err.Error()
e.ErrorKind = string(ai.ClassifyError(err))
}
m.a.recordSpanEvent(span, e)
span.End()
return resp, err
}
func (m *tracedModel) Stream(ctx context.Context, req *ai.Request, opts ...ai.GenerateOption) (ai.Stream, error) {
info, _ := ai.RunInfoFrom(ctx)
provider := m.String()
model := m.Options().Model
start := time.Now()
if m.a.opts.TraceProvider == nil {
stream, err := m.Model.Stream(ctx, req, opts...)
if err != nil {
m.a.recordRunEvent(RunEvent{Time: time.Now(), RunID: info.RunID, ParentID: info.ParentID, Agent: info.Agent, Kind: "stream", Provider: provider, Model: model, Attempt: info.Attempt, MaxAttempts: info.MaxAttempts, LatencyMS: time.Since(start).Milliseconds(), Error: err.Error(), ErrorKind: string(ai.ClassifyError(err))})
return nil, err
}
return &tracedStream{Stream: stream, a: m.a, info: info, provider: provider, model: model, start: start}, nil
}
attrs := appendRunInfoAttributes([]attribute.KeyValue{
attribute.String(AttrRunID, info.RunID),
attribute.String(AttrParentRunID, info.ParentID),
attribute.String(AttrAgentName, info.Agent),
attribute.String(AttrProvider, provider),
attribute.String(AttrModel, model),
}, info)
ctx, span := m.a.tracer().Start(ctx, spanNameModelStream, trace.WithAttributes(attrs...))
stream, err := m.Model.Stream(ctx, req, opts...)
if err != nil {
dur := time.Since(start).Milliseconds()
span.SetAttributes(attribute.Int64(AttrLatencyMS, dur), attribute.String(AttrErrorKind, string(ai.ClassifyError(err))))
span.RecordError(err)
span.SetStatus(codes.Error, err.Error())
e := RunEvent{Time: time.Now(), RunID: info.RunID, ParentID: info.ParentID, Agent: info.Agent, Kind: "stream", Provider: provider, Model: model, Attempt: info.Attempt, MaxAttempts: info.MaxAttempts, LatencyMS: dur, Error: err.Error(), ErrorKind: string(ai.ClassifyError(err))}
m.a.recordSpanEvent(span, e)
span.End()
return nil, err
}
return &tracedStream{Stream: stream, a: m.a, info: info, provider: provider, model: model, start: start, span: span}, nil
}
type tracedStream struct {
ai.Stream
a *agentImpl
info ai.RunInfo
provider string
model string
start time.Time
span trace.Span
usage ai.Usage
closed bool
}
func (s *tracedStream) Recv() (*ai.Response, error) {
resp, err := s.Stream.Recv()
if resp != nil {
s.usage = mergeUsage(s.usage, resp.Usage)
}
if err != nil {
if errors.Is(err, io.EOF) {
s.finish(nil)
} else {
s.finish(err)
}
}
return resp, err
}
func (s *tracedStream) Close() error {
err := s.Stream.Close()
s.finish(err)
return err
}
func (s *tracedStream) finish(err error) {
if s.closed {
return
}
s.closed = true
dur := time.Since(s.start).Milliseconds()
e := RunEvent{Time: time.Now(), RunID: s.info.RunID, ParentID: s.info.ParentID, Agent: s.info.Agent, Kind: "stream", Provider: s.provider, Model: s.model, Attempt: s.info.Attempt, MaxAttempts: s.info.MaxAttempts, LatencyMS: dur, Tokens: s.usage}
if err != nil {
e.Error = err.Error()
e.ErrorKind = string(ai.ClassifyError(err))
}
if s.span == nil {
s.a.recordRunEvent(e)
return
}
attrs := appendUsage([]attribute.KeyValue{attribute.Int64(AttrLatencyMS, dur)}, s.usage)
if s.info.Attempt > 0 {
attrs = append(attrs, attribute.Int(AttrAttempt, s.info.Attempt))
}
if s.info.MaxAttempts > 0 {
attrs = append(attrs, attribute.Int(AttrMaxAttempts, s.info.MaxAttempts))
}
if err != nil {
attrs = append(attrs, attribute.String(AttrErrorKind, e.ErrorKind))
s.span.RecordError(err)
s.span.SetStatus(codes.Error, err.Error())
} else {
s.span.SetStatus(codes.Ok, "")
}
s.span.SetAttributes(attrs...)
s.a.recordSpanEvent(s.span, e)
s.span.End()
}
func mergeUsage(current, next ai.Usage) ai.Usage {
if next.InputTokens > current.InputTokens {
current.InputTokens = next.InputTokens
}
if next.OutputTokens > current.OutputTokens {
current.OutputTokens = next.OutputTokens
}
if next.TotalTokens > current.TotalTokens {
current.TotalTokens = next.TotalTokens
}
return current
}
func appendUsage(attrs []attribute.KeyValue, u ai.Usage) []attribute.KeyValue {
if u.InputTokens > 0 {
attrs = append(attrs, attribute.Int(AttrInputTokens, u.InputTokens))
}
if u.OutputTokens > 0 {
attrs = append(attrs, attribute.Int(AttrOutputTokens, u.OutputTokens))
}
if u.TotalTokens > 0 {
attrs = append(attrs, attribute.Int(AttrTotalTokens, u.TotalTokens))
}
return attrs
}
func (a *agentImpl) traceTool(next ai.ToolHandler) ai.ToolHandler {
return func(ctx context.Context, call ai.ToolCall) ai.ToolResult {
info, _ := ai.RunInfoFrom(ctx)
start := time.Now()
if a.opts.TraceProvider == nil {
res := next(ctx, call)
dur := time.Since(start).Milliseconds()
resErr := resultError(res)
toolAttempts := res.Attempts
if toolAttempts <= 0 {
toolAttempts = 1
}
a.recordRunEvent(RunEvent{Time: time.Now(), RunID: info.RunID, ParentID: info.ParentID, Agent: info.Agent, Kind: "tool", Name: call.Name, Attempt: toolAttempts, MaxAttempts: a.opts.ToolMaxAttempts, LatencyMS: dur, Refused: res.Refused, Error: resErr, ErrorKind: classifyToolError(resErr)})
return res
}
ctx, span := a.tracer().Start(ctx, spanNameToolCall, trace.WithAttributes(
attribute.String(AttrRunID, info.RunID),
attribute.String(AttrParentRunID, info.ParentID),
attribute.String(AttrAgentName, info.Agent),
attribute.String(AttrToolName, call.Name),
attribute.Bool(AttrDelegate, call.Name == toolDelegate),
))
res := next(ctx, call)
dur := time.Since(start).Milliseconds()
attrs := []attribute.KeyValue{attribute.Int64(AttrLatencyMS, dur)}
toolAttempts := res.Attempts
if toolAttempts <= 0 {
toolAttempts = 1
}
attrs = append(attrs, attribute.Int(AttrToolAttempt, toolAttempts))
if a.opts.ToolMaxAttempts > 0 {
attrs = append(attrs, attribute.Int(AttrToolMaxAttempts, a.opts.ToolMaxAttempts))
}
if res.Refused != "" {
attrs = append(attrs, attribute.Bool(AttrGuardrailBlock, true), attribute.String(AttrRefusal, res.Refused))
}
resErr := resultError(res)
if kind := classifyToolError(resErr); kind != "" {
attrs = append(attrs, attribute.String(AttrErrorKind, kind))
}
span.SetAttributes(attrs...)
if res.Refused != "" {
span.SetStatus(codes.Error, res.Refused)
} else if resErr != "" {
span.SetStatus(codes.Error, resErr)
} else {
span.SetStatus(codes.Ok, "")
}
a.recordSpanEvent(span, RunEvent{Time: time.Now(), RunID: info.RunID, ParentID: info.ParentID, Agent: info.Agent, Kind: "tool", Name: call.Name, Attempt: toolAttempts, MaxAttempts: a.opts.ToolMaxAttempts, LatencyMS: dur, Refused: res.Refused, Error: resErr, ErrorKind: classifyToolError(resErr)})
span.End()
return res
}
}
func resultError(res ai.ToolResult) string {
if m, ok := res.Value.(map[string]string); ok {
return m["error"]
}
if m, ok := res.Value.(map[string]any); ok {
if err, _ := m["error"].(string); err != "" {
return err
}
}
return ""
}
func classifyToolError(err string) string {
switch {
case err == "":
return ""
case strings.Contains(strings.ToLower(err), "context canceled"):
return string(ai.ErrorKindCanceled)
case strings.Contains(strings.ToLower(err), "deadline exceeded"):
return string(ai.ErrorKindTimeout)
default:
return string(ai.ErrorKindProvider)
}
}
func (a *agentImpl) recordTimelineEvent(ctx context.Context, e RunEvent) {
span := trace.SpanFromContext(ctx)
if span.SpanContext().IsValid() {
a.recordSpanEvent(span, e)
return
}
a.recordRunEvent(e)
}
func (a *agentImpl) recordSpanEvent(span trace.Span, e RunEvent) {
if sc := span.SpanContext(); sc.IsValid() {
e.TraceID = sc.TraceID().String()
e.SpanID = sc.SpanID().String()
}
span.AddEvent("agent."+e.Kind, trace.WithTimestamp(e.Time), trace.WithAttributes(runEventAttributes(e)...))
a.recordRunEvent(e)
}
func runEventAttributes(e RunEvent) []attribute.KeyValue {
attrs := []attribute.KeyValue{
attribute.String(AttrRunID, e.RunID),
attribute.String(AttrAgentName, e.Agent),
attribute.String(AttrRunEventKind, e.Kind),
}
if e.ParentID != "" {
attrs = append(attrs, attribute.String(AttrParentRunID, e.ParentID))
}
if e.Name != "" {
attrs = append(attrs, attribute.String("agent.event.name", e.Name))
}
if e.Provider != "" {
attrs = append(attrs, attribute.String(AttrProvider, e.Provider))
}
if e.Model != "" {
attrs = append(attrs, attribute.String(AttrModel, e.Model))
}
if e.Attempt > 0 {
if e.Kind == "tool" {
attrs = append(attrs, attribute.Int(AttrToolAttempt, e.Attempt))
} else {
attrs = append(attrs, attribute.Int(AttrAttempt, e.Attempt))
}
}
if e.MaxAttempts > 0 {
if e.Kind == "tool" {
attrs = append(attrs, attribute.Int(AttrToolMaxAttempts, e.MaxAttempts))
} else {
attrs = append(attrs, attribute.Int(AttrMaxAttempts, e.MaxAttempts))
}
}
if e.LatencyMS > 0 {
attrs = append(attrs, attribute.Int64(AttrLatencyMS, e.LatencyMS))
}
if e.InputChars > 0 {
attrs = append(attrs, attribute.Int(AttrInputChars, e.InputChars))
}
attrs = appendUsage(attrs, e.Tokens)
if e.Refused != "" {
attrs = append(attrs, attribute.Bool(AttrGuardrailBlock, true), attribute.String(AttrRefusal, e.Refused))
}
if e.Error != "" {
attrs = append(attrs, attribute.String("agent.error", e.Error))
}
if e.ErrorKind != "" {
attrs = append(attrs, attribute.String(AttrErrorKind, e.ErrorKind))
}
if e.Kind == "checkpoint" {
if e.Status != "" {
attrs = append(attrs, attribute.String(AttrCheckpointStatus, e.Status))
}
if e.Name != "" {
attrs = append(attrs, attribute.String(AttrCheckpointStage, e.Name))
}
}
return attrs
}
func appendRunInfoAttributes(attrs []attribute.KeyValue, info ai.RunInfo) []attribute.KeyValue {
if info.Flow != "" {
attrs = append(attrs, attribute.String(AttrFlowName, info.Flow))
}
if info.Step != "" {
attrs = append(attrs, attribute.String(AttrFlowStep, info.Step))
}
if info.Dispatch != "" {
attrs = append(attrs, attribute.String(AttrDispatch, info.Dispatch))
}
if info.Trigger != "" {
attrs = append(attrs, attribute.String(AttrTrigger, info.Trigger))
}
return attrs
}
func (a *agentImpl) recordRunEvent(e RunEvent) {
if e.RunID == "" {
return
}
b, _ := json.Marshal(e)
key := fmt.Sprintf("runs/%s/%020d-%s", e.RunID, e.Time.UnixNano(), e.Kind)
_ = a.stateStore().Write(&store.Record{Key: key, Value: b})
}
// ListRunSummaries returns a deterministic summary of recorded runs for agentName.
func ListRunSummaries(s store.Store, agentName string) ([]RunSummary, error) {
return ListRunSummariesWithOptions(s, agentName, RunListOptions{})
}
// ListRunSummariesWithOptions returns summaries of recorded runs for agentName,
// optionally filtered by status and limited to the most recently updated runs.
func ListRunSummariesWithOptions(s store.Store, agentName string, opts RunListOptions) ([]RunSummary, error) {
st := store.Scope(s, "agent", agentName)
keys, err := st.List(store.ListPrefix("runs/"))
if err != nil {
return nil, err
}
runs := map[string]bool{}
for _, k := range keys {
parts := strings.Split(k, "/")
if len(parts) >= 2 && parts[1] != "" {
runs[parts[1]] = true
}
}
ids := make([]string, 0, len(runs))
for id := range runs {
ids = append(ids, id)
}
sort.Strings(ids)
summaries := make([]RunSummary, 0, len(ids))
for _, id := range ids {
events, err := LoadRunEvents(s, agentName, id)
if err != nil {
return nil, err
}
if len(events) == 0 {
continue
}
first := events[0]
last := events[len(events)-1]
summary := RunSummary{
RunID: id,
Agent: first.Agent,
ParentID: first.ParentID,
TraceID: first.TraceID,
SpanID: first.SpanID,
StartedAt: first.Time,
UpdatedAt: last.Time,
DurationMS: last.Time.Sub(first.Time).Milliseconds(),
Events: len(events),
Status: runStatus(events),
LastKind: last.Kind,
LastError: last.Error,
}
for _, e := range events {
if e.Agent != "" {
summary.Agent = e.Agent
}
if e.ParentID != "" {
summary.ParentID = e.ParentID
}
if e.TraceID != "" {
summary.TraceID = e.TraceID
}
if e.SpanID != "" {
summary.SpanID = e.SpanID
}
if e.Kind == "checkpoint" {
summary.Checkpoint = e.Status
summary.Stage = e.Name
}
if e.Error != "" {
summary.LastError = e.Error
}
if e.ErrorKind != "" {
summary.LastErrorKind = e.ErrorKind
}
}
if opts.Status != "" && summary.Status != opts.Status {
continue
}
if opts.TraceID != "" && !strings.HasPrefix(summary.TraceID, opts.TraceID) {
continue
}
summaries = append(summaries, summary)
}
if opts.Limit > 0 {
sort.SliceStable(summaries, func(i, j int) bool {
return summaries[i].UpdatedAt.After(summaries[j].UpdatedAt)
})
if len(summaries) > opts.Limit {
summaries = summaries[:opts.Limit]
}
}
return summaries, nil
}
func runStatus(events []RunEvent) string {
if len(events) == 0 {
return ""
}
status := "running"
for _, e := range events {
if e.Refused != "" && status == "running" {
status = "refused"
}
if e.Error != "" || e.Kind == "error" {
status = runErrorStatus(e.ErrorKind)
}
if e.Kind == "done" {
status = "done"
}
}
return status
}
func runErrorStatus(kind string) string {
switch ai.ErrorKind(kind) {
case ai.ErrorKindCanceled:
return "canceled"
case ai.ErrorKindTimeout:
return "timeout"
case ai.ErrorKindRateLimited:
return "rate_limited"
default:
return "error"
}
}
func LoadRunEvents(s store.Store, agentName, runID string) ([]RunEvent, error) {
st := store.Scope(s, "agent", agentName)
keys, err := st.List(store.ListPrefix("runs/" + runID + "/"))
if err != nil {
return nil, err
}
sort.Strings(keys)
events := make([]RunEvent, 0, len(keys))
for _, k := range keys {
recs, err := st.Read(k)
if err != nil || len(recs) == 0 {
continue
}
var e RunEvent
if json.Unmarshal(recs[0].Value, &e) == nil {
events = append(events, e)
}
}
return events, nil
}
+758
View File
@@ -0,0 +1,758 @@
package agent
import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"strings"
"testing"
"time"
"go-micro.dev/v6/ai"
"go-micro.dev/v6/flow"
"go-micro.dev/v6/store"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/sdk/trace/tracetest"
)
const codesError = codes.Error
type otelTestModel struct{ opts ai.Options }
func (m *otelTestModel) Init(opts ...ai.Option) error {
for _, o := range opts {
o(&m.opts)
}
return nil
}
func (m *otelTestModel) Options() ai.Options { return m.opts }
func (m *otelTestModel) String() string { return "oteltest" }
func (m *otelTestModel) Stream(context.Context, *ai.Request, ...ai.GenerateOption) (ai.Stream, error) {
return nil, nil
}
func (m *otelTestModel) Generate(ctx context.Context, req *ai.Request, opts ...ai.GenerateOption) (*ai.Response, error) {
if m.opts.ToolHandler != nil {
if strings.Contains(req.Prompt, "delegate") {
_ = m.opts.ToolHandler(ctx, ai.ToolCall{ID: "call-delegate", Name: toolDelegate, Input: map[string]any{"task": "subtask"}})
} else if !strings.Contains(req.Prompt, "subtask") {
_ = m.opts.ToolHandler(ctx, ai.ToolCall{ID: "call-1", Name: "probe", Input: map[string]any{"ok": true}})
}
}
return &ai.Response{Reply: "done", Usage: ai.Usage{InputTokens: 2, OutputTokens: 3, TotalTokens: 5}}, nil
}
func init() {
ai.Register("oteltest", func(opts ...ai.Option) ai.Model { return &otelTestModel{opts: ai.NewOptions(opts...)} })
}
func TestAgentOpenTelemetrySpans(t *testing.T) {
exp := tracetest.NewInMemoryExporter()
tp := trace.NewTracerProvider(trace.WithSyncer(exp))
st := store.NewMemoryStore()
a := New(Name("runner"), Provider("oteltest"), Model("unit-model"), WithStore(st), TraceProvider(tp), WithTool("probe", "probe", nil, func(context.Context, map[string]any) (string, error) { return "ok", nil }))
if _, err := a.Ask(context.Background(), "hello"); err != nil {
t.Fatal(err)
}
spans := exp.GetSpans().Snapshots()
want := map[string]bool{spanNameRun: false, spanNameModelCall: false, spanNameToolCall: false}
var runID string
for _, s := range spans {
if _, ok := want[s.Name()]; ok {
want[s.Name()] = true
}
attrs := spanAttributes(s.Attributes())
if s.Name() == spanNameRun {
runID = attrs[AttrRunID]
}
}
for name, seen := range want {
if !seen {
t.Fatalf("span %s not emitted; got %d spans", name, len(spans))
}
}
if runID == "" {
t.Fatal("run span missing run id attribute")
}
var runEvents []trace.Event
for _, s := range spans {
if s.Name() == spanNameRun {
runEvents = s.Events()
break
}
}
if !spanEventHasRunInfo(runEvents, "agent.run", runID, "runner") || !spanEventHasRunInfo(runEvents, "agent.done", runID, "runner") {
t.Fatalf("run span missing run-info events: %#v", runEvents)
}
for _, s := range spans {
if s.Name() != spanNameModelCall && s.Name() != spanNameToolCall {
continue
}
attrs := spanAttributes(s.Attributes())
if attrs[AttrRunID] != runID || attrs[AttrAgentName] != "runner" {
t.Fatalf("%s missing run correlation attributes: %#v", s.Name(), attrs)
}
if s.Name() == spanNameModelCall {
if attrs[AttrAttempt] != "1" || attrs[AttrMaxAttempts] != "1" {
t.Fatalf("model span missing attempt attributes: %#v", attrs)
}
if !spanEventHasRunInfo(s.Events(), "agent.model", runID, "runner") {
t.Fatalf("model span missing model event: %#v", s.Events())
}
}
if s.Name() == spanNameToolCall && !spanEventHasRunInfo(s.Events(), "agent.tool", runID, "runner") {
t.Fatalf("tool span missing tool event: %#v", s.Events())
}
}
keys, err := store.Scope(st, "agent", "runner").List(store.ListPrefix("runs/"))
if err != nil {
t.Fatal(err)
}
if len(keys) == 0 {
t.Fatal("expected run events to be recorded")
}
summaries, err := ListRunSummaries(st, "runner")
if err != nil {
t.Fatal(err)
}
if len(summaries) != 1 {
t.Fatalf("got %d summaries, want 1", len(summaries))
}
if summaries[0].LastKind != "done" {
t.Fatalf("LastKind = %q, want done", summaries[0].LastKind)
}
if summaries[0].Status != "done" {
t.Fatalf("Status = %q, want done", summaries[0].Status)
}
if summaries[0].DurationMS < 0 {
t.Fatalf("DurationMS = %d, want non-negative", summaries[0].DurationMS)
}
if summaries[0].TraceID == "" || summaries[0].SpanID == "" {
t.Fatalf("summary missing trace correlation: %#v", summaries[0])
}
events, err := LoadRunEvents(st, "runner", summaries[0].RunID)
if err != nil {
t.Fatal(err)
}
if len(events) == 0 || events[0].TraceID == "" || events[0].SpanID == "" {
t.Fatalf("events missing trace correlation: %#v", events)
}
}
func TestAgentOpenTelemetryToolRetryAttempts(t *testing.T) {
exp := tracetest.NewInMemoryExporter()
tp := trace.NewTracerProvider(trace.WithSyncer(exp))
st := store.NewMemoryStore()
calls := 0
a := New(
Name("tool-retry-otel"),
Provider("oteltest"),
WithStore(st),
TraceProvider(tp),
ToolRetry(3, time.Millisecond),
WithTool("probe", "probe", nil, func(context.Context, map[string]any) (string, error) {
calls++
if calls == 1 {
return "", errors.New("rate limit exceeded")
}
return "ok", nil
}),
)
if _, err := a.Ask(context.Background(), "hello"); err != nil {
t.Fatal(err)
}
if calls != 2 {
t.Fatalf("tool calls = %d, want retry success after 2 attempts", calls)
}
var sawToolSpan bool
for _, span := range exp.GetSpans().Snapshots() {
if span.Name() != spanNameToolCall {
continue
}
attrs := spanAttributes(span.Attributes())
if attrs[AttrToolName] != "probe" {
continue
}
if attrs[AttrToolAttempt] != "2" || attrs[AttrToolMaxAttempts] != "3" {
t.Fatalf("tool retry span attempts = %#v", attrs)
}
if !spanEventHasAttr(span.Events(), "agent.tool", AttrToolAttempt, "2") || !spanEventHasAttr(span.Events(), "agent.tool", AttrToolMaxAttempts, "3") {
t.Fatalf("tool retry event missing attempt attributes: %#v", span.Events())
}
sawToolSpan = true
}
if !sawToolSpan {
t.Fatal("tool retry span not emitted")
}
summaries, err := ListRunSummaries(st, "tool-retry-otel")
if err != nil {
t.Fatal(err)
}
events, err := LoadRunEvents(st, "tool-retry-otel", summaries[0].RunID)
if err != nil {
t.Fatal(err)
}
for _, event := range events {
if event.Kind == "tool" && event.Name == "probe" && event.Attempt == 2 && event.MaxAttempts == 3 {
return
}
}
t.Fatalf("persisted tool event missing retry attempts: %#v", events)
}
func spanEventHasAttr(events []trace.Event, name, key, value string) bool {
for _, event := range events {
if event.Name != name {
continue
}
attrs := spanAttributes(event.Attributes)
if attrs[key] == value {
return true
}
}
return false
}
func TestAgentRunObservabilityRedactsInputByDefault(t *testing.T) {
secret := "deploy production with token sk-secret"
exp := tracetest.NewInMemoryExporter()
tp := trace.NewTracerProvider(trace.WithSyncer(exp))
st := store.NewMemoryStore()
a := New(Name("redactor"), Provider("oteltest"), WithStore(st), TraceProvider(tp))
if _, err := a.Ask(context.Background(), secret); err != nil {
t.Fatal(err)
}
spans := exp.GetSpans().Snapshots()
var sawInputChars bool
for _, s := range spans {
for _, event := range s.Events() {
attrs := spanAttributes(event.Attributes)
if attrs["agent.event.name"] == secret {
t.Fatalf("span event leaked raw input: %#v", event)
}
if attrs[AttrInputChars] == fmt.Sprint(len(secret)) {
sawInputChars = true
}
}
}
if !sawInputChars {
t.Fatal("run event missing redacted input length attribute")
}
summaries, err := ListRunSummaries(st, "redactor")
if err != nil {
t.Fatal(err)
}
events, err := LoadRunEvents(st, "redactor", summaries[0].RunID)
if err != nil {
t.Fatal(err)
}
for _, event := range events {
if event.Name == secret {
t.Fatalf("persisted run event leaked raw input: %#v", event)
}
if event.Kind == "run" && event.InputChars != len(secret) {
t.Fatalf("run event InputChars = %d, want %d", event.InputChars, len(secret))
}
}
}
func TestAgentTraceInputsOptInRecordsInput(t *testing.T) {
message := "operator-approved diagnostic prompt"
st := store.NewMemoryStore()
a := New(Name("input-opt-in"), Provider("oteltest"), WithStore(st), TraceInputs(true))
if _, err := a.Ask(context.Background(), message); err != nil {
t.Fatal(err)
}
summaries, err := ListRunSummaries(st, "input-opt-in")
if err != nil {
t.Fatal(err)
}
events, err := LoadRunEvents(st, "input-opt-in", summaries[0].RunID)
if err != nil {
t.Fatal(err)
}
for _, event := range events {
if event.Kind == "run" && event.Name == message {
return
}
}
t.Fatalf("opt-in run event did not record message: %#v", events)
}
type failingOtelModel struct{ opts ai.Options }
func (m *failingOtelModel) Init(opts ...ai.Option) error {
for _, o := range opts {
o(&m.opts)
}
return nil
}
func (m *failingOtelModel) Options() ai.Options { return m.opts }
func (m *failingOtelModel) String() string { return "otelfail" }
func (m *failingOtelModel) Stream(context.Context, *ai.Request, ...ai.GenerateOption) (ai.Stream, error) {
return nil, nil
}
func (m *failingOtelModel) Generate(context.Context, *ai.Request, ...ai.GenerateOption) (*ai.Response, error) {
return nil, errors.New("provider exploded")
}
func init() {
ai.Register("otelfail", func(opts ...ai.Option) ai.Model { return &failingOtelModel{opts: ai.NewOptions(opts...)} })
}
func TestAgentOpenTelemetrySpansModelFailure(t *testing.T) {
exp := tracetest.NewInMemoryExporter()
tp := trace.NewTracerProvider(trace.WithSyncer(exp))
st := store.NewMemoryStore()
a := New(Name("failing-runner"), Provider("otelfail"), WithStore(st), TraceProvider(tp))
if _, err := a.Ask(context.Background(), "hello"); err == nil {
t.Fatal("Ask succeeded, want provider error")
}
spans := exp.GetSpans().Snapshots()
var sawRunError, sawModelError bool
for _, s := range spans {
attrs := spanAttributes(s.Attributes())
switch s.Name() {
case spanNameRun:
if attrs[AttrAgentName] == "failing-runner" && s.Status().Code == codesError {
sawRunError = true
}
case spanNameModelCall:
if attrs[AttrAgentName] == "failing-runner" && attrs[AttrAttempt] == "1" && attrs[AttrErrorKind] == string(ai.ErrorKindUnknown) && s.Status().Code == codesError {
sawModelError = true
}
}
}
if !sawRunError || !sawModelError {
t.Fatalf("missing error spans: run=%v model=%v spans=%d", sawRunError, sawModelError, len(spans))
}
summaries, err := ListRunSummaries(st, "failing-runner")
if err != nil {
t.Fatal(err)
}
if len(summaries) != 1 || summaries[0].Status != "error" || summaries[0].LastError == "" {
t.Fatalf("unexpected failure summary: %#v", summaries)
}
events, err := LoadRunEvents(st, "failing-runner", summaries[0].RunID)
if err != nil {
t.Fatal(err)
}
var sawModelEvent bool
for _, event := range events {
if event.Kind == "model" && event.Attempt == 1 && event.MaxAttempts == 1 && event.Error != "" && event.ErrorKind == string(ai.ErrorKindUnknown) {
sawModelEvent = true
}
}
if !sawModelEvent {
t.Fatalf("missing failed model event with attempt metadata: %#v", events)
}
}
func spanEventHasRunInfo(events []trace.Event, name, runID, agentName string) bool {
for _, event := range events {
if event.Name != name {
continue
}
attrs := spanAttributes(event.Attributes)
wantKind := strings.TrimPrefix(name, "agent.")
if attrs[AttrRunID] == runID && attrs[AttrAgentName] == agentName && attrs[AttrRunEventKind] == wantKind {
return true
}
}
return false
}
func spanAttributes(attrs []attribute.KeyValue) map[string]string {
out := make(map[string]string, len(attrs))
for _, attr := range attrs {
out[string(attr.Key)] = fmt.Sprint(attr.Value.AsInterface())
}
return out
}
func TestAgentOpenTelemetrySpansDelegateLineage(t *testing.T) {
exp := tracetest.NewInMemoryExporter()
tp := trace.NewTracerProvider(trace.WithSyncer(exp))
st := store.NewMemoryStore()
a := New(Name("conductor"), Provider("oteltest"), WithStore(st), TraceProvider(tp))
if _, err := a.Ask(context.Background(), "delegate please"); err != nil {
t.Fatal(err)
}
spans := exp.GetSpans().Snapshots()
var parentRunID string
var delegateSpanID string
var subRunSeen bool
for _, s := range spans {
attrs := spanAttributes(s.Attributes())
if s.Name() == spanNameRun && attrs[AttrAgentName] == "conductor" {
parentRunID = attrs[AttrRunID]
}
}
if parentRunID == "" {
t.Fatal("parent run span missing run id")
}
for _, s := range spans {
attrs := spanAttributes(s.Attributes())
if s.Name() == spanNameToolCall && attrs[AttrToolName] == toolDelegate {
if attrs[AttrDelegate] != "true" || attrs[AttrRunID] != parentRunID {
t.Fatalf("delegate span missing correlation attributes: %#v", attrs)
}
delegateSpanID = s.SpanContext().SpanID().String()
}
}
if delegateSpanID == "" {
t.Fatal("delegate tool span not emitted")
}
for _, s := range spans {
attrs := spanAttributes(s.Attributes())
if s.Name() == spanNameRun && attrs[AttrAgentName] == "conductor.sub" {
if attrs[AttrParentRunID] != parentRunID {
t.Fatalf("sub-agent run parent attr = %q, want %q", attrs[AttrParentRunID], parentRunID)
}
if s.Parent().SpanID().String() != delegateSpanID {
t.Fatalf("sub-agent run parent span = %s, want delegate span %s", s.Parent().SpanID(), delegateSpanID)
}
subRunSeen = true
}
}
if !subRunSeen {
t.Fatalf("sub-agent run span not emitted; got %d spans", len(spans))
}
}
func TestAgentRunTimelineRecordsModelAndToolWithoutTraceProvider(t *testing.T) {
st := store.NewMemoryStore()
a := New(Name("runner-noop"), Provider("oteltest"), WithStore(st), WithTool("probe", "probe", nil, func(context.Context, map[string]any) (string, error) { return "ok", nil }))
if _, err := a.Ask(context.Background(), "hello"); err != nil {
t.Fatal(err)
}
keys, err := store.Scope(st, "agent", "runner-noop").List(store.ListPrefix("runs/"))
if err != nil {
t.Fatal(err)
}
if len(keys) == 0 {
t.Fatal("expected run timeline without TraceProvider")
}
summaries, err := ListRunSummaries(st, "runner-noop")
if err != nil {
t.Fatal(err)
}
if len(summaries) != 1 {
t.Fatalf("got %d summaries, want 1", len(summaries))
}
if summaries[0].Status != "done" || summaries[0].LastKind != "done" {
t.Fatalf("unexpected summary without TraceProvider: %#v", summaries[0])
}
if summaries[0].TraceID != "" || summaries[0].SpanID != "" {
t.Fatalf("unexpected trace correlation without TraceProvider: %#v", summaries[0])
}
events, err := LoadRunEvents(st, "runner-noop", summaries[0].RunID)
if err != nil {
t.Fatal(err)
}
seen := map[string]bool{"run": false, "model": false, "tool": false, "done": false}
for _, e := range events {
seen[e.Kind] = true
if e.TraceID != "" || e.SpanID != "" {
t.Fatalf("event has trace correlation without TraceProvider: %#v", e)
}
}
for kind, ok := range seen {
if !ok {
t.Fatalf("missing %s event in timeline: %#v", kind, events)
}
}
}
func TestAgentCheckpointAndResumeTimelineEvents(t *testing.T) {
exp := tracetest.NewInMemoryExporter()
tp := trace.NewTracerProvider(trace.WithSyncer(exp))
st := store.NewMemoryStore()
cp := flow.StoreCheckpoint(st, "resume-otel-agent")
first := true
fakeGen = func(ctx context.Context, opts ai.Options, req *ai.Request) (*ai.Response, error) {
if first {
first = false
return nil, errors.New("temporary provider failure")
}
return &ai.Response{Reply: "resumed"}, nil
}
defer func() { fakeGen = nil }()
a := newTestAgent(Name("resume-otel-agent"), WithStore(st), WithCheckpoint(cp), TraceProvider(tp))
_, err := a.Ask(context.Background(), "resume me")
if err == nil {
t.Fatal("Ask succeeded, want simulated failure")
}
runs, err := cp.List(context.Background())
if err != nil {
t.Fatal(err)
}
if len(runs) != 1 {
t.Fatalf("checkpointed runs = %d, want 1", len(runs))
}
resp, err := Resume(context.Background(), a, runs[0].ID)
if err != nil {
t.Fatalf("Resume: %v", err)
}
if resp.Reply != "resumed" {
t.Fatalf("reply = %q, want resumed", resp.Reply)
}
events, err := LoadRunEvents(st, "resume-otel-agent", runs[0].ID)
if err != nil {
t.Fatal(err)
}
seen := map[string]bool{"checkpoint": false, "resume": false}
for _, e := range events {
if _, ok := seen[e.Kind]; ok {
seen[e.Kind] = true
}
}
for kind, ok := range seen {
if !ok {
t.Fatalf("missing %s event in timeline: %#v", kind, events)
}
}
var resumeSpanEvent bool
for _, s := range exp.GetSpans().Snapshots() {
if s.Name() != spanNameRun {
continue
}
for _, e := range s.Events() {
if e.Name == "agent.resume" {
resumeSpanEvent = true
}
}
}
if !resumeSpanEvent {
t.Fatal("run span missing agent.resume event")
}
}
func TestLoadRunEventsSortsTimelineKeys(t *testing.T) {
st := store.NewMemoryStore()
scoped := store.Scope(st, "agent", "runner")
runID := "run-1"
events := []RunEvent{
{Time: time.Unix(0, 3), RunID: runID, Agent: "runner", Kind: "tool", Name: "third"},
{Time: time.Unix(0, 1), RunID: runID, Agent: "runner", Kind: "run", Name: "first"},
{Time: time.Unix(0, 2), RunID: runID, Agent: "runner", Kind: "model", Name: "second"},
}
for _, e := range events {
b, err := json.Marshal(e)
if err != nil {
t.Fatal(err)
}
key := "runs/" + runID + "/" + e.Time.Format("20060102150405.000000000") + "-" + e.Kind
if err := scoped.Write(&store.Record{Key: key, Value: b}); err != nil {
t.Fatal(err)
}
}
got, err := LoadRunEvents(st, "runner", runID)
if err != nil {
t.Fatal(err)
}
if len(got) != 3 {
t.Fatalf("got %d events, want 3", len(got))
}
for i, want := range []string{"first", "second", "third"} {
if got[i].Name != want {
t.Fatalf("event %d = %q, want %q (timeline: %#v)", i, got[i].Name, want, got)
}
}
}
func TestListRunSummaries(t *testing.T) {
st := store.NewMemoryStore()
scoped := store.Scope(st, "agent", "runner")
events := []RunEvent{
{Time: time.Unix(0, 1), RunID: "run-a", Agent: "runner", TraceID: "trace-a", SpanID: "span-a", Kind: "run", Name: "first"},
{Time: time.Unix(0, 2), RunID: "run-a", Agent: "runner", Kind: "tool", Name: "probe"},
{Time: time.Unix(0, 3), RunID: "run-b", Agent: "runner", ParentID: "parent", Kind: "run", Name: "second"},
{Time: time.Unix(0, 4), RunID: "run-b", Agent: "runner", ParentID: "parent", Kind: "checkpoint", Name: "ask", Status: "failed"},
{Time: time.Unix(0, 5), RunID: "run-b", Agent: "runner", ParentID: "parent", Kind: "error", Error: "context deadline exceeded", ErrorKind: string(ai.ErrorKindTimeout)},
}
for _, e := range events {
b, err := json.Marshal(e)
if err != nil {
t.Fatal(err)
}
key := "runs/" + e.RunID + "/" + e.Time.Format("20060102150405.000000000") + "-" + e.Kind
if err := scoped.Write(&store.Record{Key: key, Value: b}); err != nil {
t.Fatal(err)
}
}
got, err := ListRunSummaries(st, "runner")
if err != nil {
t.Fatal(err)
}
if len(got) != 2 {
t.Fatalf("got %d summaries, want 2: %#v", len(got), got)
}
if got[0].RunID != "run-a" || got[0].TraceID != "trace-a" || got[0].SpanID != "span-a" || got[0].Events != 2 || got[0].Status != "running" || got[0].DurationMS != 0 || got[0].LastKind != "tool" || !got[0].UpdatedAt.Equal(time.Unix(0, 2)) {
t.Fatalf("unexpected run-a summary: %#v", got[0])
}
if got[1].RunID != "run-b" || got[1].ParentID != "parent" || got[1].Events != 3 || got[1].Status != "timeout" || got[1].DurationMS != 0 || got[1].LastKind != "error" || got[1].Checkpoint != "failed" || got[1].Stage != "ask" || got[1].LastError != "context deadline exceeded" || got[1].LastErrorKind != string(ai.ErrorKindTimeout) {
t.Fatalf("unexpected run-b summary: %#v", got[1])
}
}
func TestRunStatusClassifiesOperationalErrorKinds(t *testing.T) {
tests := []struct {
name string
kind ai.ErrorKind
want string
}{
{name: "canceled", kind: ai.ErrorKindCanceled, want: "canceled"},
{name: "timeout", kind: ai.ErrorKindTimeout, want: "timeout"},
{name: "rate limited", kind: ai.ErrorKindRateLimited, want: "rate_limited"},
{name: "provider", kind: ai.ErrorKindProvider, want: "error"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := runStatus([]RunEvent{
{Kind: "run"},
{Kind: "error", Error: "failed", ErrorKind: string(tt.kind)},
})
if got != tt.want {
t.Fatalf("runStatus() = %q, want %q", got, tt.want)
}
})
}
}
func TestListRunSummariesWithOptionsFiltersAndLimits(t *testing.T) {
st := store.NewMemoryStore()
scoped := store.Scope(st, "agent", "runner")
events := []RunEvent{
{Time: time.Unix(0, 1), RunID: "run-old", Agent: "runner", Kind: "run"},
{Time: time.Unix(0, 2), RunID: "run-old", Agent: "runner", Kind: "done"},
{Time: time.Unix(0, 3), RunID: "run-new", Agent: "runner", TraceID: "abcdef1234567890", Kind: "run"},
{Time: time.Unix(0, 4), RunID: "run-new", Agent: "runner", Kind: "error", Error: "rate limit exceeded", ErrorKind: string(ai.ErrorKindRateLimited)},
}
for _, e := range events {
b, err := json.Marshal(e)
if err != nil {
t.Fatal(err)
}
if err := scoped.Write(&store.Record{Key: "runs/" + e.RunID + "/" + e.Time.Format("20060102150405.000000000") + "-" + e.Kind, Value: b}); err != nil {
t.Fatal(err)
}
}
got, err := ListRunSummariesWithOptions(st, "runner", RunListOptions{Status: "rate_limited", TraceID: "abcdef", Limit: 1})
if err != nil {
t.Fatal(err)
}
if len(got) != 1 || got[0].RunID != "run-new" || got[0].Status != "rate_limited" {
t.Fatalf("filtered summaries = %#v", got)
}
}
type otelStreamModel struct{ opts ai.Options }
func (m *otelStreamModel) Init(opts ...ai.Option) error {
for _, o := range opts {
o(&m.opts)
}
return nil
}
func (m *otelStreamModel) Options() ai.Options { return m.opts }
func (m *otelStreamModel) String() string { return "otelstream" }
func (m *otelStreamModel) Generate(context.Context, *ai.Request, ...ai.GenerateOption) (*ai.Response, error) {
return &ai.Response{Reply: "unused"}, nil
}
func (m *otelStreamModel) Stream(context.Context, *ai.Request, ...ai.GenerateOption) (ai.Stream, error) {
return &otelTestStream{chunks: []*ai.Response{{Reply: "one", Usage: ai.Usage{InputTokens: 1, OutputTokens: 2, TotalTokens: 3}}, {Reply: "two", Usage: ai.Usage{InputTokens: 1, OutputTokens: 4, TotalTokens: 5}}}}, nil
}
type otelTestStream struct {
chunks []*ai.Response
idx int
}
func (s *otelTestStream) Recv() (*ai.Response, error) {
if s.idx >= len(s.chunks) {
return nil, io.EOF
}
resp := s.chunks[s.idx]
s.idx++
return resp, nil
}
func (s *otelTestStream) Close() error { return nil }
func TestAgentOpenTelemetrySpansModelStream(t *testing.T) {
exp := tracetest.NewInMemoryExporter()
tp := trace.NewTracerProvider(trace.WithSyncer(exp))
st := store.NewMemoryStore()
a := New(Name("stream-runner"), Provider("oteltest"), Model("stream-model"), WithStore(st), TraceProvider(tp))
m := a.(*agentImpl).tracedModel(&otelStreamModel{opts: ai.Options{Model: "stream-model"}})
ctx := ai.WithRunInfo(context.Background(), ai.RunInfo{RunID: "stream-run-1", ParentID: "parent-run", Agent: "stream-runner", Attempt: 2, MaxAttempts: 3, Flow: "deploy", Step: "plan"})
stream, err := m.Stream(ctx, &ai.Request{Prompt: "stream"})
if err != nil {
t.Fatal(err)
}
for {
_, err := stream.Recv()
if errors.Is(err, io.EOF) {
break
}
if err != nil {
t.Fatal(err)
}
}
if err := stream.Close(); err != nil {
t.Fatal(err)
}
spans := exp.GetSpans().Snapshots()
var sawStream bool
for _, s := range spans {
if s.Name() != spanNameModelStream {
continue
}
attrs := spanAttributes(s.Attributes())
if attrs[AttrRunID] != "stream-run-1" || attrs[AttrParentRunID] != "parent-run" || attrs[AttrAgentName] != "stream-runner" {
t.Fatalf("stream span missing run lineage: %#v", attrs)
}
if attrs[AttrFlowName] != "deploy" || attrs[AttrFlowStep] != "plan" {
t.Fatalf("stream span missing workflow attributes: %#v", attrs)
}
if attrs[AttrAttempt] != "2" || attrs[AttrMaxAttempts] != "3" || attrs[AttrTotalTokens] != "5" {
t.Fatalf("stream span missing attempt/usage attributes: %#v", attrs)
}
if !spanEventHasRunInfo(s.Events(), "agent.stream", "stream-run-1", "stream-runner") {
t.Fatalf("stream span missing stream event: %#v", s.Events())
}
sawStream = true
}
if !sawStream {
t.Fatalf("stream span not emitted; got %d spans", len(spans))
}
events, err := LoadRunEvents(st, "stream-runner", "stream-run-1")
if err != nil {
t.Fatal(err)
}
if len(events) != 1 || events[0].Kind != "stream" || events[0].TraceID == "" || events[0].SpanID == "" || events[0].Tokens.TotalTokens != 5 {
t.Fatalf("unexpected stream run event: %#v", events)
}
}
+297
View File
@@ -0,0 +1,297 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.36.11
// protoc v3.21.12
// source: agent/proto/agent.proto
package agent
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
unsafe "unsafe"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
type ChatRequest struct {
state protoimpl.MessageState `protogen:"open.v1"`
Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"`
// parent_id correlates this chat with the workflow or agent run that dispatched it.
ParentId string `protobuf:"bytes,2,opt,name=parent_id,json=parentId,proto3" json:"parent_id,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *ChatRequest) Reset() {
*x = ChatRequest{}
mi := &file_agent_proto_agent_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *ChatRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*ChatRequest) ProtoMessage() {}
func (x *ChatRequest) ProtoReflect() protoreflect.Message {
mi := &file_agent_proto_agent_proto_msgTypes[0]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use ChatRequest.ProtoReflect.Descriptor instead.
func (*ChatRequest) Descriptor() ([]byte, []int) {
return file_agent_proto_agent_proto_rawDescGZIP(), []int{0}
}
func (x *ChatRequest) GetMessage() string {
if x != nil {
return x.Message
}
return ""
}
func (x *ChatRequest) GetParentId() string {
if x != nil {
return x.ParentId
}
return ""
}
type ChatResponse struct {
state protoimpl.MessageState `protogen:"open.v1"`
Reply string `protobuf:"bytes,1,opt,name=reply,proto3" json:"reply,omitempty"`
Agent string `protobuf:"bytes,2,opt,name=agent,proto3" json:"agent,omitempty"`
ToolCalls []*ToolCall `protobuf:"bytes,3,rep,name=tool_calls,json=toolCalls,proto3" json:"tool_calls,omitempty"`
// run_id correlates this chat response with tool calls, traces, and run history.
RunId string `protobuf:"bytes,4,opt,name=run_id,json=runId,proto3" json:"run_id,omitempty"`
// parent_id is set when this response belongs to a delegated sub-agent run.
ParentId string `protobuf:"bytes,5,opt,name=parent_id,json=parentId,proto3" json:"parent_id,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *ChatResponse) Reset() {
*x = ChatResponse{}
mi := &file_agent_proto_agent_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *ChatResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*ChatResponse) ProtoMessage() {}
func (x *ChatResponse) ProtoReflect() protoreflect.Message {
mi := &file_agent_proto_agent_proto_msgTypes[1]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use ChatResponse.ProtoReflect.Descriptor instead.
func (*ChatResponse) Descriptor() ([]byte, []int) {
return file_agent_proto_agent_proto_rawDescGZIP(), []int{1}
}
func (x *ChatResponse) GetReply() string {
if x != nil {
return x.Reply
}
return ""
}
func (x *ChatResponse) GetAgent() string {
if x != nil {
return x.Agent
}
return ""
}
func (x *ChatResponse) GetToolCalls() []*ToolCall {
if x != nil {
return x.ToolCalls
}
return nil
}
func (x *ChatResponse) GetRunId() string {
if x != nil {
return x.RunId
}
return ""
}
func (x *ChatResponse) GetParentId() string {
if x != nil {
return x.ParentId
}
return ""
}
type ToolCall struct {
state protoimpl.MessageState `protogen:"open.v1"`
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
Input string `protobuf:"bytes,3,opt,name=input,proto3" json:"input,omitempty"`
Result string `protobuf:"bytes,4,opt,name=result,proto3" json:"result,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *ToolCall) Reset() {
*x = ToolCall{}
mi := &file_agent_proto_agent_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *ToolCall) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*ToolCall) ProtoMessage() {}
func (x *ToolCall) ProtoReflect() protoreflect.Message {
mi := &file_agent_proto_agent_proto_msgTypes[2]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use ToolCall.ProtoReflect.Descriptor instead.
func (*ToolCall) Descriptor() ([]byte, []int) {
return file_agent_proto_agent_proto_rawDescGZIP(), []int{2}
}
func (x *ToolCall) GetId() string {
if x != nil {
return x.Id
}
return ""
}
func (x *ToolCall) GetName() string {
if x != nil {
return x.Name
}
return ""
}
func (x *ToolCall) GetInput() string {
if x != nil {
return x.Input
}
return ""
}
func (x *ToolCall) GetResult() string {
if x != nil {
return x.Result
}
return ""
}
var File_agent_proto_agent_proto protoreflect.FileDescriptor
const file_agent_proto_agent_proto_rawDesc = "" +
"\n" +
"\x17agent/proto/agent.proto\x12\x05agent\"D\n" +
"\vChatRequest\x12\x18\n" +
"\amessage\x18\x01 \x01(\tR\amessage\x12\x1b\n" +
"\tparent_id\x18\x02 \x01(\tR\bparentId\"\x9e\x01\n" +
"\fChatResponse\x12\x14\n" +
"\x05reply\x18\x01 \x01(\tR\x05reply\x12\x14\n" +
"\x05agent\x18\x02 \x01(\tR\x05agent\x12.\n" +
"\n" +
"tool_calls\x18\x03 \x03(\v2\x0f.agent.ToolCallR\ttoolCalls\x12\x15\n" +
"\x06run_id\x18\x04 \x01(\tR\x05runId\x12\x1b\n" +
"\tparent_id\x18\x05 \x01(\tR\bparentId\"\\\n" +
"\bToolCall\x12\x0e\n" +
"\x02id\x18\x01 \x01(\tR\x02id\x12\x12\n" +
"\x04name\x18\x02 \x01(\tR\x04name\x12\x14\n" +
"\x05input\x18\x03 \x01(\tR\x05input\x12\x16\n" +
"\x06result\x18\x04 \x01(\tR\x06result2:\n" +
"\x05Agent\x121\n" +
"\x04Chat\x12\x12.agent.ChatRequest\x1a\x13.agent.ChatResponse\"\x00B\x0fZ\r./proto;agentb\x06proto3"
var (
file_agent_proto_agent_proto_rawDescOnce sync.Once
file_agent_proto_agent_proto_rawDescData []byte
)
func file_agent_proto_agent_proto_rawDescGZIP() []byte {
file_agent_proto_agent_proto_rawDescOnce.Do(func() {
file_agent_proto_agent_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_agent_proto_agent_proto_rawDesc), len(file_agent_proto_agent_proto_rawDesc)))
})
return file_agent_proto_agent_proto_rawDescData
}
var file_agent_proto_agent_proto_msgTypes = make([]protoimpl.MessageInfo, 3)
var file_agent_proto_agent_proto_goTypes = []any{
(*ChatRequest)(nil), // 0: agent.ChatRequest
(*ChatResponse)(nil), // 1: agent.ChatResponse
(*ToolCall)(nil), // 2: agent.ToolCall
}
var file_agent_proto_agent_proto_depIdxs = []int32{
2, // 0: agent.ChatResponse.tool_calls:type_name -> agent.ToolCall
0, // 1: agent.Agent.Chat:input_type -> agent.ChatRequest
1, // 2: agent.Agent.Chat:output_type -> agent.ChatResponse
2, // [2:3] is the sub-list for method output_type
1, // [1:2] is the sub-list for method input_type
1, // [1:1] is the sub-list for extension type_name
1, // [1:1] is the sub-list for extension extendee
0, // [0:1] is the sub-list for field type_name
}
func init() { file_agent_proto_agent_proto_init() }
func file_agent_proto_agent_proto_init() {
if File_agent_proto_agent_proto != nil {
return
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: unsafe.Slice(unsafe.StringData(file_agent_proto_agent_proto_rawDesc), len(file_agent_proto_agent_proto_rawDesc)),
NumEnums: 0,
NumMessages: 3,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_agent_proto_agent_proto_goTypes,
DependencyIndexes: file_agent_proto_agent_proto_depIdxs,
MessageInfos: file_agent_proto_agent_proto_msgTypes,
}.Build()
File_agent_proto_agent_proto = out.File
file_agent_proto_agent_proto_goTypes = nil
file_agent_proto_agent_proto_depIdxs = nil
}
+79
View File
@@ -0,0 +1,79 @@
// Code generated by protoc-gen-micro. DO NOT EDIT.
// source: agent/proto/agent.proto
package agent
import (
fmt "fmt"
proto "google.golang.org/protobuf/proto"
math "math"
)
import (
context "context"
client "go-micro.dev/v6/client"
server "go-micro.dev/v6/server"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// Reference imports to suppress errors if they are not otherwise used.
var _ context.Context
var _ client.Option
var _ server.Option
// Client API for Agent service
type AgentService interface {
Chat(ctx context.Context, in *ChatRequest, opts ...client.CallOption) (*ChatResponse, error)
}
type agentService struct {
c client.Client
name string
}
func NewAgentService(name string, c client.Client) AgentService {
return &agentService{
c: c,
name: name,
}
}
func (c *agentService) Chat(ctx context.Context, in *ChatRequest, opts ...client.CallOption) (*ChatResponse, error) {
req := c.c.NewRequest(c.name, "Agent.Chat", in)
out := new(ChatResponse)
err := c.c.Call(ctx, req, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// Server API for Agent service
type AgentHandler interface {
Chat(context.Context, *ChatRequest, *ChatResponse) error
}
func RegisterAgentHandler(s server.Server, hdlr AgentHandler, opts ...server.HandlerOption) error {
type agent interface {
Chat(ctx context.Context, in *ChatRequest, out *ChatResponse) error
}
type Agent struct {
agent
}
h := &agentHandler{hdlr}
return s.Handle(s.NewHandler(&Agent{h}, opts...))
}
type agentHandler struct {
AgentHandler
}
func (h *agentHandler) Chat(ctx context.Context, in *ChatRequest, out *ChatResponse) error {
return h.AgentHandler.Chat(ctx, in, out)
}
+35
View File
@@ -0,0 +1,35 @@
syntax = "proto3";
package agent;
option go_package = "./proto;agent";
// Agent is the RPC interface for an AI agent.
service Agent {
rpc Chat(ChatRequest) returns (ChatResponse) {}
}
message ChatRequest {
string message = 1;
// parent_id correlates this chat with the workflow or agent run that dispatched it.
string parent_id = 2;
}
message ChatResponse {
string reply = 1;
string agent = 2;
repeated ToolCall tool_calls = 3;
// run_id correlates this chat response with tool calls, traces, and run history.
string run_id = 4;
// parent_id is set when this response belongs to a delegated sub-agent run.
string parent_id = 5;
}
message ToolCall {
string id = 1;
string name = 2;
string input = 3;
string result = 4;
}
-118
View File
@@ -1,118 +0,0 @@
// Code generated by protoc-gen-micro. DO NOT EDIT.
// source: github.com/micro/go-bot/proto/bot.proto
/*
Package go_micro_bot is a generated protocol buffer package.
It is generated from these files:
github.com/micro/go-bot/proto/bot.proto
It has these top-level messages:
HelpRequest
HelpResponse
ExecRequest
ExecResponse
*/
package go_micro_bot
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import (
context "context"
client "github.com/micro/go-micro/client"
server "github.com/micro/go-micro/server"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
// Reference imports to suppress errors if they are not otherwise used.
var _ context.Context
var _ client.Option
var _ server.Option
// Client API for Command service
type CommandService interface {
Help(ctx context.Context, in *HelpRequest, opts ...client.CallOption) (*HelpResponse, error)
Exec(ctx context.Context, in *ExecRequest, opts ...client.CallOption) (*ExecResponse, error)
}
type commandService struct {
c client.Client
name string
}
func NewCommandService(name string, c client.Client) CommandService {
if c == nil {
c = client.NewClient()
}
if len(name) == 0 {
name = "go.micro.bot"
}
return &commandService{
c: c,
name: name,
}
}
func (c *commandService) Help(ctx context.Context, in *HelpRequest, opts ...client.CallOption) (*HelpResponse, error) {
req := c.c.NewRequest(c.name, "Command.Help", in)
out := new(HelpResponse)
err := c.c.Call(ctx, req, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *commandService) Exec(ctx context.Context, in *ExecRequest, opts ...client.CallOption) (*ExecResponse, error) {
req := c.c.NewRequest(c.name, "Command.Exec", in)
out := new(ExecResponse)
err := c.c.Call(ctx, req, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// Server API for Command service
type CommandHandler interface {
Help(context.Context, *HelpRequest, *HelpResponse) error
Exec(context.Context, *ExecRequest, *ExecResponse) error
}
func RegisterCommandHandler(s server.Server, hdlr CommandHandler, opts ...server.HandlerOption) error {
type _command interface {
Help(ctx context.Context, in *HelpRequest, out *HelpResponse) error
Exec(ctx context.Context, in *ExecRequest, out *ExecResponse) error
}
type Command struct {
_command
}
h := &commandHandler{hdlr}
return s.Handle(s.NewHandler(&Command{h}, opts...))
}
type commandHandler struct {
CommandHandler
}
func (h *commandHandler) Help(ctx context.Context, in *HelpRequest, out *HelpResponse) error {
return h.CommandHandler.Help(ctx, in, out)
}
func (h *commandHandler) Exec(ctx context.Context, in *ExecRequest, out *ExecResponse) error {
return h.CommandHandler.Exec(ctx, in, out)
}
-210
View File
@@ -1,210 +0,0 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: github.com/micro/go-bot/proto/bot.proto
package go_micro_bot
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
type HelpRequest struct {
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *HelpRequest) Reset() { *m = HelpRequest{} }
func (m *HelpRequest) String() string { return proto.CompactTextString(m) }
func (*HelpRequest) ProtoMessage() {}
func (*HelpRequest) Descriptor() ([]byte, []int) {
return fileDescriptor_bot_654832eab83ed4b5, []int{0}
}
func (m *HelpRequest) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_HelpRequest.Unmarshal(m, b)
}
func (m *HelpRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_HelpRequest.Marshal(b, m, deterministic)
}
func (dst *HelpRequest) XXX_Merge(src proto.Message) {
xxx_messageInfo_HelpRequest.Merge(dst, src)
}
func (m *HelpRequest) XXX_Size() int {
return xxx_messageInfo_HelpRequest.Size(m)
}
func (m *HelpRequest) XXX_DiscardUnknown() {
xxx_messageInfo_HelpRequest.DiscardUnknown(m)
}
var xxx_messageInfo_HelpRequest proto.InternalMessageInfo
type HelpResponse struct {
Usage string `protobuf:"bytes,1,opt,name=usage,proto3" json:"usage,omitempty"`
Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *HelpResponse) Reset() { *m = HelpResponse{} }
func (m *HelpResponse) String() string { return proto.CompactTextString(m) }
func (*HelpResponse) ProtoMessage() {}
func (*HelpResponse) Descriptor() ([]byte, []int) {
return fileDescriptor_bot_654832eab83ed4b5, []int{1}
}
func (m *HelpResponse) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_HelpResponse.Unmarshal(m, b)
}
func (m *HelpResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_HelpResponse.Marshal(b, m, deterministic)
}
func (dst *HelpResponse) XXX_Merge(src proto.Message) {
xxx_messageInfo_HelpResponse.Merge(dst, src)
}
func (m *HelpResponse) XXX_Size() int {
return xxx_messageInfo_HelpResponse.Size(m)
}
func (m *HelpResponse) XXX_DiscardUnknown() {
xxx_messageInfo_HelpResponse.DiscardUnknown(m)
}
var xxx_messageInfo_HelpResponse proto.InternalMessageInfo
func (m *HelpResponse) GetUsage() string {
if m != nil {
return m.Usage
}
return ""
}
func (m *HelpResponse) GetDescription() string {
if m != nil {
return m.Description
}
return ""
}
type ExecRequest struct {
Args []string `protobuf:"bytes,1,rep,name=args,proto3" json:"args,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *ExecRequest) Reset() { *m = ExecRequest{} }
func (m *ExecRequest) String() string { return proto.CompactTextString(m) }
func (*ExecRequest) ProtoMessage() {}
func (*ExecRequest) Descriptor() ([]byte, []int) {
return fileDescriptor_bot_654832eab83ed4b5, []int{2}
}
func (m *ExecRequest) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_ExecRequest.Unmarshal(m, b)
}
func (m *ExecRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_ExecRequest.Marshal(b, m, deterministic)
}
func (dst *ExecRequest) XXX_Merge(src proto.Message) {
xxx_messageInfo_ExecRequest.Merge(dst, src)
}
func (m *ExecRequest) XXX_Size() int {
return xxx_messageInfo_ExecRequest.Size(m)
}
func (m *ExecRequest) XXX_DiscardUnknown() {
xxx_messageInfo_ExecRequest.DiscardUnknown(m)
}
var xxx_messageInfo_ExecRequest proto.InternalMessageInfo
func (m *ExecRequest) GetArgs() []string {
if m != nil {
return m.Args
}
return nil
}
type ExecResponse struct {
Result []byte `protobuf:"bytes,1,opt,name=result,proto3" json:"result,omitempty"`
Error string `protobuf:"bytes,2,opt,name=error,proto3" json:"error,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *ExecResponse) Reset() { *m = ExecResponse{} }
func (m *ExecResponse) String() string { return proto.CompactTextString(m) }
func (*ExecResponse) ProtoMessage() {}
func (*ExecResponse) Descriptor() ([]byte, []int) {
return fileDescriptor_bot_654832eab83ed4b5, []int{3}
}
func (m *ExecResponse) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_ExecResponse.Unmarshal(m, b)
}
func (m *ExecResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_ExecResponse.Marshal(b, m, deterministic)
}
func (dst *ExecResponse) XXX_Merge(src proto.Message) {
xxx_messageInfo_ExecResponse.Merge(dst, src)
}
func (m *ExecResponse) XXX_Size() int {
return xxx_messageInfo_ExecResponse.Size(m)
}
func (m *ExecResponse) XXX_DiscardUnknown() {
xxx_messageInfo_ExecResponse.DiscardUnknown(m)
}
var xxx_messageInfo_ExecResponse proto.InternalMessageInfo
func (m *ExecResponse) GetResult() []byte {
if m != nil {
return m.Result
}
return nil
}
func (m *ExecResponse) GetError() string {
if m != nil {
return m.Error
}
return ""
}
func init() {
proto.RegisterType((*HelpRequest)(nil), "go.micro.bot.HelpRequest")
proto.RegisterType((*HelpResponse)(nil), "go.micro.bot.HelpResponse")
proto.RegisterType((*ExecRequest)(nil), "go.micro.bot.ExecRequest")
proto.RegisterType((*ExecResponse)(nil), "go.micro.bot.ExecResponse")
}
func init() {
proto.RegisterFile("github.com/micro/go-bot/proto/bot.proto", fileDescriptor_bot_654832eab83ed4b5)
}
var fileDescriptor_bot_654832eab83ed4b5 = []byte{
// 246 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x90, 0x41, 0x4b, 0xc4, 0x30,
0x10, 0x85, 0xb7, 0xba, 0xae, 0xec, 0xb4, 0x5e, 0x82, 0x48, 0xdd, 0x53, 0xcd, 0xc5, 0xbd, 0x98,
0x82, 0x5e, 0x05, 0x0f, 0xa2, 0x78, 0xee, 0x3f, 0x68, 0xba, 0x43, 0x2c, 0x6c, 0x3b, 0x35, 0x99,
0x82, 0xff, 0xc1, 0x3f, 0x2d, 0x4d, 0x72, 0x08, 0xcb, 0xde, 0xe6, 0x65, 0x86, 0xf7, 0xbe, 0x17,
0x78, 0x34, 0x3d, 0x7f, 0xcf, 0x5a, 0x75, 0x34, 0xd4, 0x43, 0xdf, 0x59, 0xaa, 0x0d, 0x3d, 0x69,
0xe2, 0x7a, 0xb2, 0xc4, 0x54, 0x6b, 0x62, 0xe5, 0x27, 0x51, 0x18, 0x52, 0xfe, 0x40, 0x69, 0x62,
0x79, 0x03, 0xf9, 0x17, 0x1e, 0xa7, 0x06, 0x7f, 0x66, 0x74, 0x2c, 0x3f, 0xa1, 0x08, 0xd2, 0x4d,
0x34, 0x3a, 0x14, 0xb7, 0x70, 0x35, 0xbb, 0xd6, 0x60, 0x99, 0x55, 0xd9, 0x7e, 0xdb, 0x04, 0x21,
0x2a, 0xc8, 0x0f, 0xe8, 0x3a, 0xdb, 0x4f, 0xdc, 0xd3, 0x58, 0x5e, 0xf8, 0x5d, 0xfa, 0x24, 0x1f,
0x20, 0xff, 0xf8, 0xc5, 0x2e, 0xda, 0x0a, 0x01, 0xeb, 0xd6, 0x1a, 0x57, 0x66, 0xd5, 0xe5, 0x7e,
0xdb, 0xf8, 0x59, 0xbe, 0x42, 0x11, 0x4e, 0x62, 0xd4, 0x1d, 0x6c, 0x2c, 0xba, 0xf9, 0xc8, 0x3e,
0xab, 0x68, 0xa2, 0x5a, 0x10, 0xd0, 0x5a, 0xb2, 0x31, 0x26, 0x88, 0xe7, 0xbf, 0x0c, 0xae, 0xdf,
0x69, 0x18, 0xda, 0xf1, 0x20, 0xde, 0x60, 0xbd, 0x40, 0x8b, 0x7b, 0x95, 0x56, 0x53, 0x49, 0xaf,
0xdd, 0xee, 0xdc, 0x2a, 0x04, 0xcb, 0xd5, 0x62, 0xb0, 0xa0, 0x9c, 0x1a, 0x24, 0x0d, 0x4e, 0x0d,
0x52, 0x72, 0xb9, 0xd2, 0x1b, 0xff, 0xb5, 0x2f, 0xff, 0x01, 0x00, 0x00, 0xff, 0xff, 0xcb, 0x77,
0xdf, 0x28, 0x85, 0x01, 0x00, 0x00,
}
-25
View File
@@ -1,25 +0,0 @@
syntax = "proto3";
package go.micro.bot;
service Command {
rpc Help(HelpRequest) returns (HelpResponse) {};
rpc Exec(ExecRequest) returns (ExecResponse) {};
}
message HelpRequest {
}
message HelpResponse {
string usage = 1;
string description = 2;
}
message ExecRequest {
repeated string args = 1;
}
message ExecResponse {
bytes result = 1;
string error = 2;
}
+339
View File
@@ -0,0 +1,339 @@
package agent
import (
"context"
"errors"
"strings"
"testing"
"time"
"go-micro.dev/v6/ai"
"go-micro.dev/v6/flow"
"go-micro.dev/v6/store"
)
func TestAskCancellationAbortsPromptly(t *testing.T) {
fakeGen = func(ctx context.Context, opts ai.Options, req *ai.Request) (*ai.Response, error) {
<-ctx.Done()
return nil, ctx.Err()
}
defer func() { fakeGen = nil }()
a := newTestAgent(Name("cancel"), ModelCallTimeout(time.Second), ModelRetry(3, time.Millisecond))
ctx, cancel := context.WithCancel(context.Background())
cancel()
start := time.Now()
_, err := a.Ask(ctx, "stop")
if !errors.Is(err, context.Canceled) {
t.Fatalf("Ask error = %v, want context canceled", err)
}
if elapsed := time.Since(start); elapsed > 100*time.Millisecond {
t.Fatalf("Ask took %s after cancellation, want prompt abort", elapsed)
}
}
func TestAskRetriesTransientErrorsThenSucceeds(t *testing.T) {
attempts := 0
fakeGen = func(ctx context.Context, opts ai.Options, req *ai.Request) (*ai.Response, error) {
attempts++
if attempts < 3 {
return nil, context.DeadlineExceeded
}
return &ai.Response{Reply: "ok"}, nil
}
defer func() { fakeGen = nil }()
a := newTestAgent(Name("retry-success"), ModelRetry(3, time.Millisecond))
resp, err := a.Ask(context.Background(), "hello")
if err != nil {
t.Fatalf("Ask returned error: %v", err)
}
if resp.Reply != "ok" {
t.Fatalf("reply = %q, want ok", resp.Reply)
}
if attempts != 3 {
t.Fatalf("attempts = %d, want 3", attempts)
}
}
func TestAskRetriesTransientErrorsThenSurfacesStructuredError(t *testing.T) {
attempts := 0
fakeGen = func(ctx context.Context, opts ai.Options, req *ai.Request) (*ai.Response, error) {
attempts++
return nil, context.DeadlineExceeded
}
defer func() { fakeGen = nil }()
a := newTestAgent(Name("retry-fail"), ModelRetry(2, time.Millisecond))
_, err := a.Ask(context.Background(), "hello")
var retryErr *ai.RetryError
if !errors.As(err, &retryErr) {
t.Fatalf("Ask error = %T %v, want *ai.RetryError", err, err)
}
if retryErr.Attempts != 2 {
t.Fatalf("retry attempts = %d, want 2", retryErr.Attempts)
}
if attempts != 2 {
t.Fatalf("model attempts = %d, want 2", attempts)
}
if !strings.Contains(err.Error(), "micro inspect agent <name> --status timeout") ||
!strings.Contains(err.Error(), "docs/guides/debugging-agents.md") {
t.Fatalf("Ask error = %q, want actionable timeout/debugging guidance", err.Error())
}
}
func TestModelRetryDoesNotDuplicateCheckpointedToolSideEffects(t *testing.T) {
ctx := context.Background()
cp := flow.StoreCheckpoint(store.NewMemoryStore(), "retry-tool-dedupe-agent")
attempts := 0
toolRuns := 0
fakeGen = func(ctx context.Context, opts ai.Options, req *ai.Request) (*ai.Response, error) {
attempts++
if opts.ToolHandler == nil {
t.Fatal("missing tool handler")
}
res := opts.ToolHandler(ctx, ai.ToolCall{ID: "create-1", Name: "external.create", Input: map[string]any{"title": "Retry safe"}})
if res.Content != "created Retry safe" {
t.Fatalf("tool result = %q, want cached create result", res.Content)
}
if attempts == 1 {
return nil, testStatusError{code: 503}
}
return &ai.Response{Reply: "done", ToolCalls: []ai.ToolCall{{ID: "create-1", Name: "external.create", Input: map[string]any{"title": "Retry safe"}, Result: res.Content}}}, nil
}
defer func() { fakeGen = nil }()
a := newTestAgent(
Name("retry-tool-dedupe-agent"),
WithCheckpoint(cp),
ModelRetry(2, time.Millisecond),
WithTool("external.create", "create once", nil, func(context.Context, map[string]any) (string, error) {
toolRuns++
return "created Retry safe", nil
}),
)
resp, err := a.Ask(ctx, "create once despite a transient provider retry")
if err != nil {
t.Fatalf("Ask: %v", err)
}
if resp.Reply != "done" {
t.Fatalf("reply = %q, want done", resp.Reply)
}
if attempts != 2 {
t.Fatalf("model attempts = %d, want retry after transient provider failure", attempts)
}
if toolRuns != 1 {
t.Fatalf("tool executions = %d, want checkpointed side effect reused across retry", toolRuns)
}
runs, err := cp.List(ctx)
if err != nil {
t.Fatalf("List: %v", err)
}
if len(runs) != 1 {
t.Fatalf("checkpointed runs = %d, want 1", len(runs))
}
if _, ok := findStep(runs[0].Steps, `tool:external.create:{"title":"Retry safe"}`); !ok {
t.Fatalf("checkpoint steps = %#v, want completed external.create step", runs[0].Steps)
}
}
func TestAskRateLimitFailureSuggestsPreflightAndInspect(t *testing.T) {
fakeGen = func(ctx context.Context, opts ai.Options, req *ai.Request) (*ai.Response, error) {
return nil, testStatusError{code: 429}
}
defer func() { fakeGen = nil }()
a := newTestAgent(Name("rate-limit-guidance"), ModelRetry(1, time.Millisecond))
_, err := a.Ask(context.Background(), "hello")
if err == nil {
t.Fatal("Ask succeeded, want rate-limit failure")
}
if !strings.Contains(err.Error(), "micro inspect agent <name> --status rate_limited") ||
!strings.Contains(err.Error(), "micro agent preflight") {
t.Fatalf("Ask error = %q, want inspect and preflight guidance", err.Error())
}
if ai.ClassifyError(err) != ai.ErrorKindRateLimited {
t.Fatalf("ClassifyError(wrapped error) = %q, want rate_limited", ai.ClassifyError(err))
}
}
func TestCanceledAskContextSkipsToolExecution(t *testing.T) {
fakeGen = func(ctx context.Context, opts ai.Options, req *ai.Request) (*ai.Response, error) {
if opts.ToolHandler == nil {
t.Fatal("missing tool handler")
}
canceled, cancel := context.WithCancel(ctx)
cancel()
res := opts.ToolHandler(canceled, ai.ToolCall{ID: "call-1", Name: toolPlan, Input: map[string]any{
"steps": []any{map[string]any{"task": "should not persist", "status": "pending"}},
}})
if !strings.Contains(res.Content, context.Canceled.Error()) {
t.Fatalf("tool result = %q, want cancellation error", res.Content)
}
return &ai.Response{Reply: "ok"}, nil
}
defer func() { fakeGen = nil }()
a := newTestAgent(Name("cancel-tools"))
if _, err := a.Ask(context.Background(), "try a canceled tool"); err != nil {
t.Fatalf("Ask: %v", err)
}
if plan := a.loadPlan(); plan != "" {
t.Fatalf("plan persisted after canceled tool context: %q", plan)
}
}
func TestToolCallTimeoutPropagatesDeadlineToCustomTool(t *testing.T) {
var sawDeadline bool
a := newTestAgent(
Name("tool-timeout"),
ToolCallTimeout(10*time.Millisecond),
WithTool("slow", "slow tool", nil, func(ctx context.Context, input map[string]any) (string, error) {
if _, ok := ctx.Deadline(); ok {
sawDeadline = true
}
<-ctx.Done()
return "", ctx.Err()
}),
)
start := time.Now()
content := toolContent(a.toolHandler(), "slow", nil)
if !sawDeadline {
t.Fatal("custom tool did not receive a deadline")
}
if !strings.Contains(content, context.DeadlineExceeded.Error()) {
t.Fatalf("tool result = %q, want deadline exceeded", content)
}
if elapsed := time.Since(start); elapsed > 200*time.Millisecond {
t.Fatalf("tool call took %s, want bounded timeout", elapsed)
}
}
func TestAskCancellationDuringToolCallFailsRun(t *testing.T) {
fakeGen = func(ctx context.Context, opts ai.Options, req *ai.Request) (*ai.Response, error) {
if opts.ToolHandler == nil {
t.Fatal("missing tool handler")
}
res := opts.ToolHandler(ctx, ai.ToolCall{ID: "call-1", Name: "cancel-self"})
if !strings.Contains(res.Content, context.Canceled.Error()) {
t.Fatalf("tool result = %q, want cancellation error", res.Content)
}
return &ai.Response{Reply: "should not succeed"}, nil
}
defer func() { fakeGen = nil }()
ctx, cancel := context.WithCancel(context.Background())
a := newTestAgent(
Name("cancel-during-tool"),
WithTool("cancel-self", "cancel the run context", nil, func(context.Context, map[string]any) (string, error) {
cancel()
return "", context.Canceled
}),
)
_, err := a.Ask(ctx, "cancel during tool")
if !errors.Is(err, context.Canceled) {
t.Fatalf("Ask error = %v, want context canceled", err)
}
}
func TestAskCheckpointRecordsTerminalOperationalFailureStatus(t *testing.T) {
tests := []struct {
name string
err error
want string
}{
{name: "canceled", err: context.Canceled, want: "canceled"},
{name: "timeout", err: context.DeadlineExceeded, want: "timeout"},
{name: "rate limited", err: testStatusError{code: 429}, want: "rate_limited"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cp := flow.StoreCheckpoint(store.NewMemoryStore(), "terminal-"+strings.ReplaceAll(tt.name, " ", "-"))
fakeGen = func(ctx context.Context, opts ai.Options, req *ai.Request) (*ai.Response, error) {
return nil, tt.err
}
defer func() { fakeGen = nil }()
a := newTestAgent(Name("terminal-"+strings.ReplaceAll(tt.name, " ", "-")), WithCheckpoint(cp))
_, err := a.Ask(context.Background(), "fail safely")
if err == nil {
t.Fatal("Ask succeeded, want failure")
}
runs, err := cp.List(context.Background())
if err != nil {
t.Fatalf("List: %v", err)
}
if len(runs) != 1 {
t.Fatalf("checkpointed runs = %d, want 1", len(runs))
}
if runs[0].Status != tt.want {
t.Fatalf("run status = %q, want %q", runs[0].Status, tt.want)
}
if len(runs[0].Steps) == 0 || runs[0].Steps[0].Status != tt.want {
t.Fatalf("step status = %#v, want %q", runs[0].Steps, tt.want)
}
if pending, err := Pending(context.Background(), a); err != nil || len(pending) != 0 {
t.Fatalf("Pending = %#v, %v; want no terminal run", pending, err)
}
})
}
}
type testStatusError struct {
code int
}
func (e testStatusError) Error() string { return "provider status error" }
func (e testStatusError) StatusCode() int { return e.code }
func TestToolRetryRetriesTransientToolErrorsThenSucceeds(t *testing.T) {
attempts := 0
a := newTestAgent(
Name("tool-retry-success"),
ToolRetry(3, time.Millisecond),
WithTool("flaky", "flaky tool", nil, func(context.Context, map[string]any) (string, error) {
attempts++
if attempts < 3 {
return "", context.DeadlineExceeded
}
return "ok", nil
}),
)
content := toolContent(a.toolHandler(), "flaky", nil)
if content != "ok" {
t.Fatalf("tool result = %q, want ok", content)
}
if attempts != 3 {
t.Fatalf("attempts = %d, want 3", attempts)
}
}
func TestToolRetryDoesNotRetryGuardrailRefusals(t *testing.T) {
attempts := 0
a := newTestAgent(
Name("tool-retry-refusal"),
MaxSteps(1),
ToolRetry(3, time.Millisecond),
WithTool("counted", "counted tool", nil, func(context.Context, map[string]any) (string, error) {
attempts++
return "ok", nil
}),
)
h := a.toolHandler()
_ = toolContent(h, "counted", nil)
content := toolContent(h, "counted", nil)
if !strings.Contains(content, "step limit reached") {
t.Fatalf("tool result = %q, want step-limit refusal", content)
}
if attempts != 1 {
t.Fatalf("attempts = %d, want only the allowed tool call to execute", attempts)
}
}
+322
View File
@@ -0,0 +1,322 @@
package agent
import (
"context"
"encoding/json"
"errors"
"io"
"strings"
"sync"
"github.com/google/uuid"
"go-micro.dev/v6/ai"
)
// StreamEventType identifies an event emitted by a tool-aware agent stream.
type StreamEventType string
const (
// StreamEventToolStart is emitted immediately before a tool call runs.
StreamEventToolStart StreamEventType = "tool_start"
// StreamEventToolEnd is emitted after a tool call returns or is refused.
StreamEventToolEnd StreamEventType = "tool_end"
// StreamEventToken carries a chunk of the final answer.
StreamEventToken StreamEventType = "token"
// StreamEventDone carries the completed agent response.
StreamEventDone StreamEventType = "done"
)
// StreamEvent is one event from StreamAsk.
type StreamEvent struct {
Type StreamEventType
Token string
ToolCall ai.ToolCall
Result ai.ToolResult
Response *Response
}
// AgentStream is a stream of tool execution events followed by final-answer chunks.
type AgentStream interface {
Recv() (*StreamEvent, error)
Close() error
}
// StreamAsk runs an agent Ask turn with tool start/end events and streams the final answer.
// It is additive for callers that hold the public Agent interface; concrete agents also
// expose the same method directly.
func StreamAsk(ctx context.Context, ag Agent, message string) (AgentStream, error) {
streamer, ok := ag.(interface {
StreamAsk(context.Context, string) (AgentStream, error)
})
if !ok {
return nil, errors.New("agent: StreamAsk unsupported by implementation")
}
return streamer.StreamAsk(ctx, message)
}
// ResumeStreamAsk resumes a checkpointed agent run and emits the same event
// shape as StreamAsk. Completed runs are streamed from the persisted response;
// unfinished runs continue from their checkpoint and emit tool events for any
// work that still needs to run. Tool calls already recorded as done in the
// checkpoint are reused by the agent checkpoint wrapper and are not re-executed.
func ResumeStreamAsk(ctx context.Context, ag Agent, runID string) (AgentStream, error) {
a, ok := ag.(*agentImpl)
if !ok {
return nil, errors.New("agent: ResumeStreamAsk unsupported by implementation")
}
return a.resumeStreamAsk(ctx, runID)
}
// StreamAsk runs tools like Ask, emits ToolStart/ToolEnd events as they execute,
// then emits chunks of the final answer followed by a Done event.
func (a *agentImpl) StreamAsk(ctx context.Context, message string) (AgentStream, error) {
streamCtx, cancel := context.WithCancel(ctx)
events := make(chan *StreamEvent, 16)
done := make(chan struct{})
s := &agentStream{events: events, done: done, cancel: cancel}
go func() {
defer close(events)
defer close(done)
resp, err := a.askWithStreamEvents(streamCtx, message, events)
if err != nil {
s.setErr(err)
return
}
for _, tok := range splitStreamTokens(resp.Reply) {
if !sendStreamEvent(ctx, events, &StreamEvent{Type: StreamEventToken, Token: tok}) {
return
}
}
_ = sendStreamEvent(ctx, events, &StreamEvent{Type: StreamEventDone, Response: resp})
}()
return s, nil
}
func (a *agentImpl) resumeStreamAsk(ctx context.Context, runID string) (AgentStream, error) {
streamCtx, cancel := context.WithCancel(ctx)
events := make(chan *StreamEvent, 16)
done := make(chan struct{})
s := &agentStream{events: events, done: done, cancel: cancel}
go func() {
defer close(events)
defer close(done)
resp, err := a.resumeWithStreamEvents(streamCtx, runID, events)
if err != nil {
s.setErr(err)
return
}
for _, tok := range splitStreamTokens(resp.Reply) {
if !sendStreamEvent(ctx, events, &StreamEvent{Type: StreamEventToken, Token: tok}) {
return
}
}
_ = sendStreamEvent(ctx, events, &StreamEvent{Type: StreamEventDone, Response: resp})
}()
return s, nil
}
func (a *agentImpl) askWithStreamEvents(ctx context.Context, message string, events chan<- *StreamEvent) (*Response, error) {
a.mu.Lock()
defer a.mu.Unlock()
if a.tools == nil {
a.tools = ai.NewTools(a.opts.Registry, ai.ToolClient(a.opts.Client))
}
base := a.toolHandler()
handler := func(ctx context.Context, call ai.ToolCall) ai.ToolResult {
_ = sendStreamEvent(ctx, events, &StreamEvent{Type: StreamEventToolStart, ToolCall: call})
result := base(ctx, call)
_ = sendStreamEvent(ctx, events, &StreamEvent{Type: StreamEventToolEnd, ToolCall: call, Result: result})
return result
}
a.setupWithToolHandler(handler)
defer a.setupWithToolHandler(nil)
return a.askLocked(ctx, uuid.New().String(), message, a.parentRunID, nil, true)
}
func (a *agentImpl) resumeWithStreamEvents(ctx context.Context, runID string, events chan<- *StreamEvent) (*Response, error) {
if a.opts.Checkpoint == nil {
return nil, errors.New("agent: ResumeStreamAsk requires a checkpoint")
}
run, ok, err := a.opts.Checkpoint.Load(ctx, runID)
if err != nil {
return nil, err
}
if !ok {
return nil, errors.New("agent: checkpointed run not found")
}
if run.Status == "done" {
var resp Response
if err := json.Unmarshal(run.State.Data, &resp); err != nil {
return nil, err
}
return &resp, nil
}
if terminalAgentRunStatus(run.Status) {
return nil, errors.New("agent: checkpointed run is terminal with status " + run.Status)
}
a.mu.Lock()
defer a.mu.Unlock()
if a.tools == nil {
a.tools = ai.NewTools(a.opts.Registry, ai.ToolClient(a.opts.Client))
}
base := a.toolHandler()
handler := func(ctx context.Context, call ai.ToolCall) ai.ToolResult {
_ = sendStreamEvent(ctx, events, &StreamEvent{Type: StreamEventToolStart, ToolCall: call})
result := base(ctx, call)
_ = sendStreamEvent(ctx, events, &StreamEvent{Type: StreamEventToolEnd, ToolCall: call, Result: result})
return result
}
a.setupWithToolHandler(handler)
defer a.setupWithToolHandler(nil)
if run.Status == "paused" {
if run.State.Stage == agentInputStep {
return nil, errors.New("agent: checkpointed run is input-required; resume with ResumeInput")
}
run.Status = "running"
run.State.Stage = agentAskStep
}
return a.askLocked(ctx, run.ID, string(run.State.Data), run.ParentID, &run, false)
}
type agentStreamAdapter struct {
stream AgentStream
}
type memoryRecordingStream struct {
stream ai.Stream
memory Memory
mu sync.Mutex
chunks []string
closed bool
}
func (s *memoryRecordingStream) Recv() (*ai.Response, error) {
resp, err := s.stream.Recv()
if resp != nil && resp.Reply != "" {
s.mu.Lock()
s.chunks = append(s.chunks, resp.Reply)
s.mu.Unlock()
}
if errors.Is(err, io.EOF) {
s.recordAssistant()
}
return resp, err
}
func (s *memoryRecordingStream) Close() error {
s.recordAssistant()
return s.stream.Close()
}
func (s *memoryRecordingStream) recordAssistant() {
s.mu.Lock()
defer s.mu.Unlock()
if s.closed {
return
}
s.closed = true
if reply := strings.Join(s.chunks, ""); reply != "" {
s.memory.Add("assistant", reply)
}
}
func (s *agentStreamAdapter) Recv() (*ai.Response, error) {
for {
event, err := s.stream.Recv()
if err != nil {
return nil, err
}
if event == nil {
continue
}
switch event.Type {
case StreamEventToken:
if event.Token == "" {
continue
}
return &ai.Response{Reply: event.Token}, nil
case StreamEventDone:
return nil, io.EOF
}
}
}
func (s *agentStreamAdapter) Close() error {
return s.stream.Close()
}
func (a *agentImpl) streamAskAI(ctx context.Context, message string) (ai.Stream, error) {
stream, err := a.StreamAsk(ctx, message)
if err != nil {
return nil, err
}
return &agentStreamAdapter{stream: stream}, nil
}
type agentStream struct {
events <-chan *StreamEvent
done <-chan struct{}
cancel context.CancelFunc
mu sync.Mutex
err error
}
func (s *agentStream) Recv() (*StreamEvent, error) {
ev, ok := <-s.events
if ok {
return ev, nil
}
s.mu.Lock()
defer s.mu.Unlock()
if s.err != nil {
return nil, s.err
}
return nil, io.EOF
}
func (s *agentStream) Close() error {
if s.cancel != nil {
s.cancel()
}
<-s.done
return nil
}
func (s *agentStream) setErr(err error) {
s.mu.Lock()
defer s.mu.Unlock()
s.err = err
}
func sendStreamEvent(ctx context.Context, events chan<- *StreamEvent, ev *StreamEvent) bool {
select {
case events <- ev:
return true
case <-ctx.Done():
return false
}
}
func splitStreamTokens(reply string) []string {
if reply == "" {
return nil
}
parts := strings.Fields(reply)
if len(parts) == 0 {
return []string{reply}
}
out := make([]string, 0, len(parts))
for i, part := range parts {
if i > 0 {
part = " " + part
}
out = append(out, part)
}
return out
}
+278
View File
@@ -0,0 +1,278 @@
package agent
import (
"context"
"errors"
"io"
"testing"
"time"
"go-micro.dev/v6/ai"
"go-micro.dev/v6/flow"
"go-micro.dev/v6/store"
)
func TestStreamAskEmitsToolEventsAndFinalTokens(t *testing.T) {
calls := 0
fakeGen = func(ctx context.Context, opts ai.Options, req *ai.Request) (*ai.Response, error) {
if opts.ToolHandler == nil {
t.Fatal("StreamAsk must configure a tool handler")
}
calls++
result := opts.ToolHandler(ctx, ai.ToolCall{ID: "call-1", Name: "echo", Input: map[string]any{"text": "hello"}})
return &ai.Response{
Reply: "planning",
Answer: "final answer",
ToolCalls: []ai.ToolCall{{ID: "call-1", Name: "echo", Input: map[string]any{"text": "hello"}, Result: result.Content}},
}, nil
}
defer func() { fakeGen = nil }()
a := newTestAgent(Name("streamer"), WithTool("echo", "echo text", nil, func(ctx context.Context, input map[string]any) (string, error) {
return input["text"].(string), nil
}))
stream, err := a.StreamAsk(context.Background(), "say hello")
if err != nil {
t.Fatalf("StreamAsk: %v", err)
}
var types []StreamEventType
var tokens string
var done *Response
for {
event, err := stream.Recv()
if errors.Is(err, io.EOF) {
break
}
if err != nil {
t.Fatalf("Recv: %v", err)
}
types = append(types, event.Type)
if event.Type == StreamEventToken {
tokens += event.Token
}
if event.Type == StreamEventDone {
done = event.Response
}
}
want := []StreamEventType{StreamEventToolStart, StreamEventToolEnd, StreamEventToken, StreamEventToken, StreamEventToken, StreamEventDone}
if len(types) != len(want) {
t.Fatalf("event types = %v, want %v", types, want)
}
for i := range want {
if types[i] != want[i] {
t.Fatalf("event types = %v, want %v", types, want)
}
}
if tokens != "planning final answer" {
t.Fatalf("tokens = %q", tokens)
}
if done == nil || done.Reply != "planning\n\nfinal answer" {
t.Fatalf("done response = %#v", done)
}
if calls != 1 {
t.Fatalf("Generate calls = %d, want 1", calls)
}
}
func TestStreamAskCloseCancelsInFlightModelCall(t *testing.T) {
started := make(chan struct{})
fakeGen = func(ctx context.Context, opts ai.Options, req *ai.Request) (*ai.Response, error) {
close(started)
<-ctx.Done()
return nil, ctx.Err()
}
defer func() { fakeGen = nil }()
a := newTestAgent(Name("stream-cancel"))
stream, err := a.StreamAsk(context.Background(), "cancel me")
if err != nil {
t.Fatalf("StreamAsk: %v", err)
}
select {
case <-started:
case <-time.After(time.Second):
t.Fatal("model call did not start")
}
closed := make(chan error, 1)
go func() { closed <- stream.Close() }()
select {
case err := <-closed:
if err != nil {
t.Fatalf("Close: %v", err)
}
case <-time.After(time.Second):
t.Fatal("Close did not cancel the in-flight stream")
}
}
func TestStreamAskHelperRejectsUnsupportedAgent(t *testing.T) {
_, err := StreamAsk(context.Background(), unsupportedAgent{}, "hello")
if err == nil {
t.Fatal("StreamAsk helper should reject unsupported implementations")
}
}
func TestAgentStreamUsesProviderStreamingAndRecordsAssistantMemory(t *testing.T) {
var sawRequest bool
fakeStream = func(ctx context.Context, opts ai.Options, req *ai.Request) (ai.Stream, error) {
sawRequest = true
if req.Prompt != "stream the answer" {
t.Fatalf("Prompt = %q, want stream the answer", req.Prompt)
}
if len(req.Messages) != 1 || req.Messages[0].Role != "user" || req.Messages[0].Content != "stream the answer" {
t.Fatalf("Messages = %#v, want current user turn in memory", req.Messages)
}
return &sliceStream{chunks: []string{"hel", "lo"}}, nil
}
defer func() { fakeStream = nil }()
a := newTestAgent(Name("provider-stream"))
stream, err := a.Stream(context.Background(), "stream the answer")
if err != nil {
t.Fatalf("Stream: %v", err)
}
var reply string
for {
chunk, err := stream.Recv()
if errors.Is(err, io.EOF) {
break
}
if err != nil {
t.Fatalf("Recv: %v", err)
}
reply += chunk.Reply
}
if err := stream.Close(); err != nil {
t.Fatalf("Close: %v", err)
}
if !sawRequest {
t.Fatal("provider Stream was not called")
}
if reply != "hello" {
t.Fatalf("reply = %q, want hello", reply)
}
got := a.mem.Messages()
if len(got) != 2 || got[0].Role != "user" || got[0].Content != "stream the answer" || got[1].Role != "assistant" || got[1].Content != "hello" {
t.Fatalf("memory = %#v, want user turn and streamed assistant reply", got)
}
}
func TestResumeStreamAskDoesNotReplayCompletedTool(t *testing.T) {
ctx := context.Background()
cp := flow.StoreCheckpoint(store.NewStore(), "stream-resume-agent")
toolRuns := 0
first := true
fakeGen = func(ctx context.Context, opts ai.Options, req *ai.Request) (*ai.Response, error) {
if opts.ToolHandler != nil {
res := opts.ToolHandler(ctx, ai.ToolCall{ID: "call-1", Name: "charge", Input: map[string]any{"order": "42"}})
if res.Content != "charged" {
t.Fatalf("tool result = %q, want charged", res.Content)
}
}
if first {
first = false
return nil, errors.New("stream disconnected after tool")
}
return &ai.Response{Reply: "finished from streamed checkpoint"}, nil
}
defer func() { fakeGen = nil }()
a := newTestAgent(Name("stream-resume-agent"), WithCheckpoint(cp),
WithTool("charge", "charge once", nil, func(context.Context, map[string]any) (string, error) {
toolRuns++
return "charged", nil
}))
stream, err := a.StreamAsk(ctx, "charge order 42")
if err != nil {
t.Fatalf("StreamAsk: %v", err)
}
for {
_, err := stream.Recv()
if errors.Is(err, io.EOF) {
break
}
if err != nil {
break
}
}
if toolRuns != 1 {
t.Fatalf("tool executions after failed StreamAsk = %d, want 1", toolRuns)
}
runs, err := Pending(ctx, a)
if err != nil {
t.Fatalf("Pending: %v", err)
}
if len(runs) != 1 {
t.Fatalf("Pending returned %d runs, want 1", len(runs))
}
resumed, err := ResumeStreamAsk(ctx, a, runs[0].ID)
if err != nil {
t.Fatalf("ResumeStreamAsk: %v", err)
}
var toolEvents int
var done *Response
for {
event, err := resumed.Recv()
if errors.Is(err, io.EOF) {
break
}
if err != nil {
t.Fatalf("resumed Recv: %v", err)
}
if event.Type == StreamEventToolStart || event.Type == StreamEventToolEnd {
toolEvents++
}
if event.Type == StreamEventDone {
done = event.Response
}
}
if toolRuns != 1 {
t.Fatalf("tool executions after ResumeStreamAsk = %d, want completed tool was not replayed", toolRuns)
}
if toolEvents != 2 {
t.Fatalf("resumed tool events = %d, want start/end for replayed checkpoint result", toolEvents)
}
if done == nil || done.Reply != "finished from streamed checkpoint" || done.RunID != runs[0].ID {
t.Fatalf("done response = %#v", done)
}
}
func TestAgentStreamDoesNotRecordUserWhenProviderStreamingUnsupported(t *testing.T) {
fakeStream = func(ctx context.Context, opts ai.Options, req *ai.Request) (ai.Stream, error) {
if len(req.Messages) == 0 || req.Messages[len(req.Messages)-1].Role != "user" || req.Messages[len(req.Messages)-1].Content != "stream fallback" {
t.Fatalf("stream request messages = %+v, want pending user message", req.Messages)
}
return nil, ai.ErrStreamingUnsupported
}
defer func() { fakeStream = nil }()
mem := NewInMemory(8)
a := newTestAgent(Name("stream-fallback"), WithMemory(mem), WithTool("echo", "echo text", nil, func(context.Context, map[string]any) (string, error) {
return "ok", nil
}))
_, err := a.Stream(context.Background(), "stream fallback")
if !errors.Is(err, ai.ErrStreamingUnsupported) {
t.Fatalf("Stream error = %v, want ErrStreamingUnsupported", err)
}
if got := mem.Messages(); len(got) != 0 {
t.Fatalf("memory after unsupported stream = %+v, want no recorded messages", got)
}
}
type unsupportedAgent struct{}
func (unsupportedAgent) Name() string { return "unsupported" }
func (unsupportedAgent) Init(...Option) {}
func (unsupportedAgent) Options() Options { return Options{} }
func (unsupportedAgent) Ask(context.Context, string) (*Response, error) { return nil, nil }
func (unsupportedAgent) Stream(context.Context, string) (ai.Stream, error) { return nil, nil }
func (unsupportedAgent) Run() error { return nil }
func (unsupportedAgent) Stop() error { return nil }
func (unsupportedAgent) String() string { return "unsupported" }
+407
View File
@@ -0,0 +1,407 @@
package agent
import (
"context"
"encoding/json"
"fmt"
"html"
"regexp"
"strings"
"go-micro.dev/v6/ai"
)
var fencedJSONBlock = regexp.MustCompile("(?s)```(?:json)?\\s*(.*?)\\s*```")
var taggedToolCallBlock = regexp.MustCompile(`(?s)<[^<>]*(?:tool_call|tool_calls|function=)[^<>]*>(.*?)</[^<>]*>`)
var singleTaggedToolCall = regexp.MustCompile(`(?s)<(tool_call\b[^<>]*|[^<>]*function\s*=[^<>]*)>(.*?)</[^<>]*>`)
var taggedToolNameAttr = regexp.MustCompile(`(?i)(?:function|name|tool)\s*=\s*["\']?([^"\'\s>]+)`)
type textToolCall struct {
ID string `json:"id"`
Name string `json:"name"`
Tool string `json:"tool"`
Input map[string]any `json:"input"`
Arguments any `json:"arguments"`
Function *textToolCall `json:"function"`
}
// executeTextToolCalls is a compatibility fallback for providers that return a
// tool call as text JSON instead of a structured tool_calls field. It only runs
// calls whose names match the tools offered to the model, so ordinary JSON
// answers are left untouched.
func (a *agentImpl) executeTextToolCalls(ctx context.Context, reply string, tools []ai.Tool) ([]ai.ToolCall, string, bool) {
calls := parseTextToolCalls(reply, tools)
if len(calls) == 0 {
return nil, "", false
}
handler := a.toolHandler()
results := make([]string, 0, len(calls))
for i := range calls {
result := handler(ctx, calls[i])
calls[i].Result = result.Content
if result.Refused != "" {
calls[i].Error = result.Refused
}
if result.Content != "" {
results = append(results, result.Content)
}
}
return calls, strings.Join(results, "\n"), true
}
// executeAdditionalTextToolCalls runs text-encoded tool calls that accompany a
// structured tool_calls response. Some OpenAI-compatible providers can mix the
// two forms in a single assistant turn: for example, emitting a native
// conformance_echo call while rendering a follow-up guarded delegate call as
// <tool_call name="delegate">...</tool_call> text. Keep this fallback additive
// and de-duplicate calls already represented in the structured tool_calls list.
func (a *agentImpl) executeAdditionalTextToolCalls(ctx context.Context, reply string, tools []ai.Tool, existing []ai.ToolCall) ([]ai.ToolCall, string, bool) {
calls := parseTextToolCalls(reply, tools)
if len(calls) == 0 {
return nil, "", false
}
seen := map[string]bool{}
for _, call := range existing {
seen[textToolCallKey(call)] = true
}
handler := a.toolHandler()
out := make([]ai.ToolCall, 0, len(calls))
results := make([]string, 0, len(calls))
for i := range calls {
if seen[textToolCallKey(calls[i])] {
continue
}
result := handler(ctx, calls[i])
calls[i].Result = result.Content
if result.Refused != "" {
calls[i].Error = result.Refused
}
if result.Content != "" {
results = append(results, result.Content)
}
out = append(out, calls[i])
}
return out, strings.Join(results, "\n"), len(out) > 0
}
func textToolCallKey(call ai.ToolCall) string {
b, _ := json.Marshal(call.Input)
return call.Name + "\x00" + string(b)
}
func parseTextToolCalls(text string, tools []ai.Tool) []ai.ToolCall {
text = html.UnescapeString(text)
allowed := textToolNames(tools)
if len(allowed) == 0 {
return nil
}
if calls := decodeTaggedTextToolCalls(text, allowed); len(calls) > 0 {
return calls
}
if calls := decodeFunctionTextToolCalls(text, allowed); len(calls) > 0 {
return calls
}
for _, candidate := range jsonCandidates(text) {
if calls := decodeTextToolCalls(candidate, allowed); len(calls) > 0 {
return calls
}
}
return nil
}
func textToolNames(tools []ai.Tool) map[string]string {
allowed := map[string]string{}
for _, tool := range tools {
addTextToolName(allowed, tool.Name, tool.Name)
if tool.OriginalName != "" {
addTextToolName(allowed, tool.OriginalName, tool.Name)
}
}
return allowed
}
func addTextToolName(allowed map[string]string, name, canonical string) {
if name == "" || canonical == "" {
return
}
allowed[name] = canonical
// Some OpenAI-compatible models describe an idempotent Add endpoint as a
// creation action and emit the otherwise-correct service tool with a Create
// suffix in text-only tool-call markup. Keep the fallback bounded by the
// offered service tool prefix so ordinary unknown tools remain ignored.
for _, suffix := range []string{"_Add", ".Add"} {
if strings.HasSuffix(name, suffix) {
allowed[strings.TrimSuffix(name, suffix)+strings.Replace(suffix, "Add", "Create", 1)] = canonical
}
}
}
func jsonCandidates(text string) []string {
trimmed := strings.TrimSpace(text)
var out []string
if trimmed != "" {
out = append(out, trimmed)
}
for _, match := range fencedJSONBlock.FindAllStringSubmatch(text, -1) {
if len(match) > 1 {
out = append(out, strings.TrimSpace(match[1]))
}
}
for _, match := range taggedToolCallBlock.FindAllStringSubmatch(text, -1) {
if len(match) > 1 {
out = append(out, strings.TrimSpace(match[1]))
}
}
if start, end := strings.IndexAny(text, "[{"), strings.LastIndexAny(text, "]}"); start >= 0 && end > start {
out = append(out, strings.TrimSpace(text[start:end+1]))
}
return out
}
func decodeTextToolCalls(candidate string, allowed map[string]string) []ai.ToolCall {
var root any
if err := json.Unmarshal([]byte(candidate), &root); err != nil {
return nil
}
return collectTextToolCalls(root, allowed)
}
func collectTextToolCalls(v any, allowed map[string]string) []ai.ToolCall {
switch x := v.(type) {
case []any:
var out []ai.ToolCall
for _, item := range x {
out = append(out, collectTextToolCalls(item, allowed)...)
}
return out
case map[string]any:
if nested, ok := firstNestedToolCalls(x); ok {
return collectTextToolCalls(nested, allowed)
}
call := mapToTextToolCall(x)
name, input := textToolCallNameAndInput(call)
if name == "" || allowed[name] == "" || input == nil {
return nil
}
id := call.ID
if id == "" {
id = fmt.Sprintf("text-call-%s", strings.ReplaceAll(name, ".", "_"))
}
return []ai.ToolCall{{ID: id, Name: allowed[name], Input: input}}
default:
return nil
}
}
func textToolCallNameAndInput(call textToolCall) (string, map[string]any) {
name := call.Name
if name == "" {
name = call.Tool
}
input := call.Input
if input == nil {
input = textToolArguments(call.Arguments)
}
if call.Function != nil {
fnName, fnInput := textToolCallNameAndInput(*call.Function)
if name == "" {
name = fnName
}
if input == nil {
input = fnInput
}
}
return name, input
}
func textToolArguments(raw any) map[string]any {
switch args := raw.(type) {
case map[string]any:
return args
case string:
var input map[string]any
if err := json.Unmarshal([]byte(args), &input); err == nil {
return input
}
}
return nil
}
func decodeTaggedTextToolCalls(text string, allowed map[string]string) []ai.ToolCall {
var out []ai.ToolCall
for _, match := range singleTaggedToolCall.FindAllStringSubmatch(text, -1) {
if len(match) < 3 {
continue
}
tag, body := match[1], strings.TrimSpace(match[2])
if calls := decodeTextToolCalls(body, allowed); len(calls) > 0 {
out = append(out, calls...)
continue
}
if calls := decodeTaggedTextToolCalls(body, allowed); len(calls) > 0 {
out = append(out, calls...)
continue
}
name := taggedToolName(tag)
if name == "" || allowed[name] == "" {
continue
}
var input map[string]any
if err := json.Unmarshal([]byte(body), &input); err != nil || input == nil {
continue
}
out = append(out, ai.ToolCall{
ID: fmt.Sprintf("text-call-%s", strings.ReplaceAll(name, ".", "_")),
Name: allowed[name],
Input: input,
})
}
return out
}
func taggedToolName(tag string) string {
match := taggedToolNameAttr.FindStringSubmatch(tag)
if len(match) < 2 {
return ""
}
return strings.Trim(match[1], `"'`)
}
func decodeFunctionTextToolCalls(text string, allowed map[string]string) []ai.ToolCall {
var out []ai.ToolCall
for alias, canonical := range allowed {
for _, body := range functionCallBodies(text, alias) {
var input map[string]any
if err := json.Unmarshal([]byte(body), &input); err != nil || input == nil {
continue
}
out = append(out, ai.ToolCall{
ID: fmt.Sprintf("text-call-%s", strings.ReplaceAll(alias, ".", "_")),
Name: canonical,
Input: input,
})
}
}
return out
}
func functionCallBodies(text, name string) []string {
if name == "" {
return nil
}
var bodies []string
for searchFrom := 0; searchFrom < len(text); {
idx := strings.Index(text[searchFrom:], name)
if idx < 0 {
break
}
start := searchFrom + idx
open := start + len(name)
if !isFunctionCallBoundary(text, start, open) {
searchFrom = start + len(name)
continue
}
bodyStart := open + 1
bodyEnd, ok := balancedJSONObjectEnd(text, bodyStart)
if !ok {
searchFrom = bodyStart
continue
}
bodies = append(bodies, strings.TrimSpace(text[bodyStart:bodyEnd]))
searchFrom = bodyEnd + 1
}
return bodies
}
func isFunctionCallBoundary(text string, start, open int) bool {
if open >= len(text) || text[open] != '(' {
return false
}
if start > 0 {
prev := text[start-1]
if prev == '_' || prev == '.' || prev == '-' || prev == '$' || ('0' <= prev && prev <= '9') || ('A' <= prev && prev <= 'Z') || ('a' <= prev && prev <= 'z') {
return false
}
}
for i := open + 1; i < len(text); i++ {
switch text[i] {
case ' ', '\n', '\r', '\t':
continue
case '{':
return true
default:
return false
}
}
return false
}
func balancedJSONObjectEnd(text string, start int) (int, bool) {
for start < len(text) {
switch text[start] {
case ' ', '\n', '\r', '\t':
start++
case '{':
depth := 0
inString := false
escaped := false
for i := start; i < len(text); i++ {
c := text[i]
if inString {
if escaped {
escaped = false
} else if c == '\\' {
escaped = true
} else if c == '"' {
inString = false
}
continue
}
switch c {
case '"':
inString = true
case '{':
depth++
case '}':
depth--
if depth == 0 {
for j := i + 1; j < len(text); j++ {
switch text[j] {
case ' ', '\n', '\r', '\t':
continue
case ')':
return i + 1, true
default:
return 0, false
}
}
}
}
}
return 0, false
default:
return 0, false
}
}
return 0, false
}
func firstNestedToolCalls(m map[string]any) (any, bool) {
for _, key := range []string{"tool_calls", "toolCalls", "calls"} {
if v, ok := m[key]; ok {
return v, true
}
}
return nil, false
}
func mapToTextToolCall(m map[string]any) textToolCall {
b, _ := json.Marshal(m)
var call textToolCall
_ = json.Unmarshal(b, &call)
return call
}
+148
View File
@@ -0,0 +1,148 @@
package agent
import (
"testing"
"go-micro.dev/v6/ai"
)
func TestParseTextToolCallsMiniMaxTaggedMarkup(t *testing.T) {
tools := []ai.Tool{{Name: "task_TaskService_Add"}}
reply := `<tool_calls>
<tool_call>{"name":"task_TaskService_Add","arguments":{"title":"Design"}}</tool_call>
<tool_call>{"name":"task_TaskService_Add","arguments":{"title":"Build"}}</tool_call>
<tool_call>{"name":"task_TaskService_Add","arguments":{"title":"Ship"}}</tool_call>
</tool_calls>`
calls := parseTextToolCalls(reply, tools)
if len(calls) != 3 {
t.Fatalf("parseTextToolCalls returned %d calls, want 3: %+v", len(calls), calls)
}
for i, want := range []string{"Design", "Build", "Ship"} {
if calls[i].Name != "task_TaskService_Add" {
t.Fatalf("call %d name = %q, want task_TaskService_Add", i, calls[i].Name)
}
if got := calls[i].Input["title"]; got != want {
t.Fatalf("call %d title = %v, want %q", i, got, want)
}
}
}
func TestParseTextToolCallsFunctionTaggedMarkup(t *testing.T) {
tools := []ai.Tool{{Name: "task_TaskService_Add"}}
reply := `<function=task_TaskService_Add>{"title":"Design"}</function>`
calls := parseTextToolCalls(reply, tools)
if len(calls) != 1 {
t.Fatalf("parseTextToolCalls returned %d calls, want 1: %+v", len(calls), calls)
}
if got := calls[0].Input["title"]; got != "Design" {
t.Fatalf("title = %v, want Design", got)
}
}
func TestParseTextToolCallsCreateAliasForAddTool(t *testing.T) {
tools := []ai.Tool{{Name: "task_TaskService_Add", OriginalName: "task.TaskService.Add"}}
reply := `<tool_call>{"name":"task_TaskService_Create","arguments":{"title":"Design"}}</tool_call>`
calls := parseTextToolCalls(reply, tools)
if len(calls) != 1 {
t.Fatalf("parseTextToolCalls returned %d calls, want 1: %+v", len(calls), calls)
}
if calls[0].Name != "task_TaskService_Add" {
t.Fatalf("call name = %q, want canonical task_TaskService_Add", calls[0].Name)
}
if got := calls[0].Input["title"]; got != "Design" {
t.Fatalf("title = %v, want Design", got)
}
}
func TestParseTextToolCallsOpenAICompatibleFunctionArgumentsString(t *testing.T) {
tools := []ai.Tool{{Name: "delegate"}}
reply := `<tool_call>{"id":"call-2","type":"function","function":{"name":"delegate","arguments":"{\"task\":\"summarize the conformance marker\",\"to\":\"blocked-reviewer\"}"}}</tool_call>`
calls := parseTextToolCalls(reply, tools)
if len(calls) != 1 {
t.Fatalf("parseTextToolCalls returned %d calls, want 1: %+v", len(calls), calls)
}
if calls[0].Name != "delegate" {
t.Fatalf("call name = %q, want delegate", calls[0].Name)
}
if got := calls[0].Input["task"]; got != "summarize the conformance marker" {
t.Fatalf("task = %v, want summarize the conformance marker", got)
}
if got := calls[0].Input["to"]; got != "blocked-reviewer" {
t.Fatalf("to = %v, want blocked-reviewer", got)
}
}
func TestParseTextToolCallsTaggedMarkupWithSpacedNameAttribute(t *testing.T) {
tools := []ai.Tool{{Name: "delegate"}}
reply := `<tool_call name = "delegate">{"task":"summarize the conformance marker","to":"blocked-reviewer"}</tool_call>`
calls := parseTextToolCalls(reply, tools)
if len(calls) != 1 {
t.Fatalf("parseTextToolCalls returned %d calls, want 1: %+v", len(calls), calls)
}
if calls[0].Name != "delegate" {
t.Fatalf("call name = %q, want delegate", calls[0].Name)
}
if got := calls[0].Input["to"]; got != "blocked-reviewer" {
t.Fatalf("to = %v, want blocked-reviewer", got)
}
}
func TestParseTextToolCallsHTMLEscapedTaggedMarkup(t *testing.T) {
tools := []ai.Tool{{Name: "delegate"}}
reply := `&lt;tool_call name=&quot;delegate&quot;&gt;{"task":"summarize the conformance marker","to":"blocked-reviewer"}&lt;/tool_call&gt;`
calls := parseTextToolCalls(reply, tools)
if len(calls) != 1 {
t.Fatalf("parseTextToolCalls returned %d calls, want 1: %+v", len(calls), calls)
}
if calls[0].Name != "delegate" {
t.Fatalf("call name = %q, want delegate", calls[0].Name)
}
if got := calls[0].Input["task"]; got != "summarize the conformance marker" {
t.Fatalf("task = %v, want summarize the conformance marker", got)
}
}
func TestParseTextToolCallsFunctionCallSyntax(t *testing.T) {
tools := []ai.Tool{{Name: "delegate"}}
reply := `I will now call delegate({"task":"summarize the conformance marker","to":"blocked-reviewer"}) before answering.`
calls := parseTextToolCalls(reply, tools)
if len(calls) != 1 {
t.Fatalf("parseTextToolCalls returned %d calls, want 1: %+v", len(calls), calls)
}
if calls[0].Name != "delegate" {
t.Fatalf("call name = %q, want delegate", calls[0].Name)
}
if got := calls[0].Input["task"]; got != "summarize the conformance marker" {
t.Fatalf("task = %v, want summarize the conformance marker", got)
}
if got := calls[0].Input["to"]; got != "blocked-reviewer" {
t.Fatalf("to = %v, want blocked-reviewer", got)
}
}
func TestParseTextToolCallsFunctionCallSyntaxHandlesNestedJSON(t *testing.T) {
tools := []ai.Tool{{Name: "delegate"}}
reply := `delegate({
"task":"summarize the {escaped} marker",
"meta":{"note":"paren ) and brace } in string"},
"to":"blocked-reviewer"
})`
calls := parseTextToolCalls(reply, tools)
if len(calls) != 1 {
t.Fatalf("parseTextToolCalls returned %d calls, want 1: %+v", len(calls), calls)
}
if got := calls[0].Input["task"]; got != "summarize the {escaped} marker" {
t.Fatalf("task = %v, want nested JSON-safe task", got)
}
if got := calls[0].Input["to"]; got != "blocked-reviewer" {
t.Fatalf("to = %v, want blocked-reviewer", got)
}
}
+183
View File
@@ -0,0 +1,183 @@
package agent
import (
"context"
"fmt"
"strings"
"testing"
"go-micro.dev/v6/ai"
"go-micro.dev/v6/registry"
"go-micro.dev/v6/store"
)
// A registered wrapper runs around every tool call and can observe and
// modify the result.
func TestWrapToolWraps(t *testing.T) {
var saw string
wrap := func(next ai.ToolHandler) ai.ToolHandler {
return func(ctx context.Context, call ai.ToolCall) ai.ToolResult {
saw = call.Name
res := next(ctx, call)
res.Content = "wrapped:" + res.Content
return res
}
}
a := newTestAgent(Name("wrapped"), WrapTool(wrap))
content := toolContent(a.toolHandler(), "demo_Svc_Do", map[string]any{})
if saw != "demo_Svc_Do" {
t.Errorf("wrapper saw %q, want demo_Svc_Do", saw)
}
if !strings.HasPrefix(content, "wrapped:") {
t.Errorf("wrapper did not modify the result; got %q", content)
}
}
// Multiple wrappers compose outermost-first: the first registered wrapper
// is the outer layer, so it runs first on the way in and last on the way
// out.
func TestWrapToolOrder(t *testing.T) {
var order []string
mk := func(tag string) ai.ToolWrapper {
return func(next ai.ToolHandler) ai.ToolHandler {
return func(ctx context.Context, call ai.ToolCall) ai.ToolResult {
order = append(order, "in:"+tag)
res := next(ctx, call)
order = append(order, "out:"+tag)
return res
}
}
}
a := newTestAgent(Name("ordered"), WrapTool(mk("a"), mk("b")))
toolContent(a.toolHandler(), "demo_Svc_Do", map[string]any{})
want := "in:a in:b out:b out:a"
if got := strings.Join(order, " "); got != want {
t.Errorf("wrapper order = %q, want %q", got, want)
}
}
// Wrappers run outside the built-in guardrails, so they observe a refused
// call and its refusal result rather than being short-circuited.
func TestWrapToolSeesGuardrailRefusal(t *testing.T) {
var sawResult string
wrap := func(next ai.ToolHandler) ai.ToolHandler {
return func(ctx context.Context, call ai.ToolCall) ai.ToolResult {
res := next(ctx, call)
sawResult = res.Content
return res
}
}
a := newTestAgent(Name("gated-wrap"),
ApproveTool(func(tool string, input map[string]any) (bool, string) {
return false, "denied"
}),
WrapTool(wrap),
)
toolContent(a.toolHandler(), "demo_Svc_Do", map[string]any{})
if !strings.Contains(sawResult, "not approved") {
t.Errorf("wrapper should observe the guardrail refusal; got %q", sawResult)
}
}
// A guardrail refusal carries a structured reason a wrapper can switch on,
// so reliability tooling (e.g. loop handling) needn't parse the message.
func TestWrapToolSeesRefusedReason(t *testing.T) {
a := newTestAgent(Name("looper"), LoopLimit(2))
h := a.toolHandler()
var last ai.ToolResult
for i := 0; i < 3; i++ {
last = h(context.Background(), ai.ToolCall{ID: "x", Name: "demo_Svc_Do", Input: map[string]any{"q": "same"}})
}
if last.Refused != ai.RefusedLoop {
t.Errorf("Refused = %q, want %q", last.Refused, ai.RefusedLoop)
}
}
// ctxMock is a model that forwards the Generate context to the tool
// handler (as real providers do), so a wrapper can read ai.RunInfo.
type ctxMock struct{ opts ai.Options }
func (m *ctxMock) Init(opts ...ai.Option) error {
for _, o := range opts {
o(&m.opts)
}
return nil
}
func (m *ctxMock) Options() ai.Options { return m.opts }
func (m *ctxMock) String() string { return "ctxmock" }
func (m *ctxMock) Stream(context.Context, *ai.Request, ...ai.GenerateOption) (ai.Stream, error) {
return nil, fmt.Errorf("no stream")
}
func (m *ctxMock) Generate(ctx context.Context, _ *ai.Request, _ ...ai.GenerateOption) (*ai.Response, error) {
if m.opts.ToolHandler != nil {
m.opts.ToolHandler(ctx, ai.ToolCall{ID: "c1", Name: "demo_Svc_Do", Input: map[string]any{}})
}
return &ai.Response{Answer: "done"}, nil
}
// During an Ask, a wrapper sees RunInfo on the context: a correlation id
// for the run and the agent's name.
func TestWrapToolSeesRunInfo(t *testing.T) {
ai.Register("ctxmock", func(opts ...ai.Option) ai.Model {
m := &ctxMock{}
_ = m.Init(opts...)
return m
})
var got ai.RunInfo
var ok bool
a := New(
Name("runner"),
Provider("ctxmock"),
WithRegistry(registry.NewMemoryRegistry()),
WithStore(store.NewMemoryStore()),
WrapTool(func(next ai.ToolHandler) ai.ToolHandler {
return func(ctx context.Context, call ai.ToolCall) ai.ToolResult {
got, ok = ai.RunInfoFrom(ctx)
return next(ctx, call)
}
}),
)
resp, err := a.Ask(context.Background(), "go")
if err != nil {
t.Fatalf("Ask: %v", err)
}
if !ok {
t.Fatal("wrapper did not see RunInfo on the context")
}
if got.Agent != "runner" {
t.Errorf("RunInfo.Agent = %q, want runner", got.Agent)
}
if got.RunID == "" {
t.Error("RunInfo.RunID is empty")
}
if resp.RunID != got.RunID {
t.Errorf("Response.RunID = %q, want wrapper RunID %q", resp.RunID, got.RunID)
}
if resp.ParentID != "" {
t.Errorf("Response.ParentID = %q, want empty", resp.ParentID)
}
}
// call.Scan decodes a tool call's input into a typed struct.
func TestToolCallScan(t *testing.T) {
call := ai.ToolCall{Input: map[string]any{"query": "hello", "limit": 5}}
var args struct {
Query string `json:"query"`
Limit int `json:"limit"`
}
if err := call.Scan(&args); err != nil {
t.Fatalf("Scan: %v", err)
}
if args.Query != "hello" || args.Limit != 5 {
t.Errorf("Scan decoded %+v, want {hello 5}", args)
}
}
+381
View File
@@ -0,0 +1,381 @@
# AI Package
The `ai` package provides simple, high-level interfaces for AI model providers. It supports text generation (`Model`), image generation (`ImageModel`), and video generation (`VideoModel`).
## Interfaces
### Text Generation (Model)
The Model interface follows the same patterns as other go-micro packages (Registry, Client, Broker):
```go
type Model interface {
Init(...Option) error
Options() Options
Generate(ctx context.Context, req *Request, opts ...GenerateOption) (*Response, error)
Stream(ctx context.Context, req *Request, opts ...GenerateOption) (Stream, error)
String() string
}
```
## Quick Start
```go
import (
"context"
"go-micro.dev/v5/ai"
_ "go-micro.dev/v5/ai/anthropic"
_ "go-micro.dev/v5/ai/openai"
)
// Create a model
m := ai.New("openai",
ai.WithAPIKey("your-api-key"),
ai.WithModel("gpt-4o"),
)
// Generate a response
req := &ai.Request{
Prompt: "What is Go?",
SystemPrompt: "You are a helpful programming assistant",
}
resp, err := m.Generate(context.Background(), req)
if err != nil {
log.Fatal(err)
}
fmt.Println(resp.Reply)
```
### Image Generation (ImageModel)
```go
type ImageModel interface {
GenerateImage(ctx context.Context, req *ImageRequest, opts ...GenerateOption) (*ImageResponse, error)
String() string
}
```
```go
import (
"go-micro.dev/v5/ai"
_ "go-micro.dev/v5/ai/atlascloud"
)
ig := ai.NewImage("atlascloud",
ai.WithAPIKey("your-api-key"),
)
resp, err := ig.GenerateImage(context.Background(), &ai.ImageRequest{
Prompt: "A Go gopher in space",
Size: "1024x1024",
})
fmt.Println(resp.Images[0].URL)
```
Providers that support image generation: **Atlas Cloud**, **OpenAI**.
### Video Generation (VideoModel)
```go
type VideoModel interface {
GenerateVideo(ctx context.Context, req *VideoRequest, opts ...GenerateOption) (*VideoResponse, error)
String() string
}
```
```go
import (
"go-micro.dev/v5/ai"
_ "go-micro.dev/v5/ai/atlascloud"
)
vg := ai.NewVideo("atlascloud",
ai.WithAPIKey("your-api-key"),
)
resp, err := vg.GenerateVideo(context.Background(), &ai.VideoRequest{
Prompt: "Microservices nodes animating with data flowing between them",
Images: []string{"https://example.com/diagram.png"}, // optional: image-to-video
Duration: 6,
})
fmt.Println(resp.URL)
```
Providers that support video generation: **Atlas Cloud**.
## Options
Configure the model using functional options:
```go
m := ai.New("anthropic",
ai.WithAPIKey("your-key"), // Required
ai.WithModel("claude-sonnet-4-20250514"), // Optional, uses provider default
ai.WithBaseURL("https://api.anthropic.com"), // Optional, uses provider default
)
```
You can also update options after creation:
```go
m.Init(
ai.WithModel("gpt-4o-mini"),
ai.WithAPIKey("new-key"),
)
```
## Using Tools
The model can automatically execute tool calls when provided with a tool handler:
```go
// Define a tool handler. It mirrors a go-micro RPC handler: context
// first, the call in, a result out.
toolHandler := func(ctx context.Context, call ai.ToolCall) ai.ToolResult {
// Execute the tool and return results
switch call.Name {
case "get_weather":
return ai.ToolResult{ID: call.ID, Value: map[string]string{"temp": "72F"}, Content: `{"temp": "72F"}`}
default:
return ai.ToolResult{ID: call.ID, Content: `{"error": "unknown tool"}`}
}
}
// Create model with tool handler
m := ai.New("openai",
ai.WithAPIKey("your-key"),
ai.WithToolHandler(toolHandler),
)
// Provide tools in the request
req := &ai.Request{
Prompt: "What's the weather?",
SystemPrompt: "You are a helpful assistant",
Tools: []ai.Tool{
{
Name: "get_weather",
Description: "Get current weather",
Properties: map[string]any{
"location": map[string]any{
"type": "string",
"description": "City name",
},
},
},
},
}
// Generate will automatically call tools and return final answer
resp, err := m.Generate(context.Background(), req)
fmt.Println(resp.Answer) // Final answer after tool execution
```
## Response Structure
```go
type Response struct {
Reply string // Initial reply from model
ToolCalls []ToolCall // Tools the model wants to call
Answer string // Final answer (after tool execution if handler provided)
}
```
- `Reply`: The model's first response
- `ToolCalls`: List of tools the model requested (if any)
- `Answer`: The final answer after tools are executed (only set if ToolHandler is provided)
## Provider capability matrix
The CLI can print the provider capabilities registered in the current build:
```bash
micro ai providers
```
For automation and docs generation, emit the same matrix as stable JSON:
```bash
micro ai providers --json
```
It reports support from Go Micro's provider registry, so the matrix reflects the model, image, and video interfaces available to this binary rather than external provider marketing claims.
## Supported Providers
### Anthropic Claude
```go
m := ai.New("anthropic",
ai.WithAPIKey("sk-ant-..."),
ai.WithModel("claude-sonnet-4-20250514"), // default
)
```
Default model: `claude-sonnet-4-20250514`
Default base URL: `https://api.anthropic.com`
### OpenAI GPT
```go
m := ai.New("openai",
ai.WithAPIKey("sk-..."),
ai.WithModel("gpt-4o"), // default
)
```
Default model: `gpt-4o`
Default base URL: `https://api.openai.com`
### Google Gemini
```go
m := ai.New("gemini",
ai.WithAPIKey("your-key"),
ai.WithModel("gemini-2.5-flash"), // default
)
```
Default model: `gemini-2.5-flash`
Default base URL: `https://generativelanguage.googleapis.com`
Google Gemini uses its own API format with `system_instruction`, `contents` (not `messages`), and `functionDeclarations` for tool calling. The provider handles the translation automatically.
### Groq
```go
m := ai.New("groq",
ai.WithAPIKey("your-key"),
ai.WithModel("llama-3.3-70b-versatile"), // default
)
```
Default model: `llama-3.3-70b-versatile`
Default base URL: `https://api.groq.com/openai`
Groq provides ultra-fast inference for open-weight models via an OpenAI-compatible endpoint.
### Mistral
```go
m := ai.New("mistral",
ai.WithAPIKey("your-key"),
ai.WithModel("mistral-large-latest"), // default
)
```
Default model: `mistral-large-latest`
Default base URL: `https://api.mistral.ai`
Mistral AI is a European AI company offering high-performance models via an OpenAI-compatible endpoint.
### Together AI
```go
m := ai.New("together",
ai.WithAPIKey("your-key"),
ai.WithModel("meta-llama/Llama-3.3-70B-Instruct-Turbo"), // default
)
```
Default model: `meta-llama/Llama-3.3-70B-Instruct-Turbo`
Default base URL: `https://api.together.xyz`
Together AI provides fast inference for open-weight models via an OpenAI-compatible endpoint.
### Atlas Cloud
```go
m := ai.New("atlascloud",
ai.WithAPIKey("your-key"),
ai.WithModel("llama-3.3-70b"), // default
)
```
Default model: `llama-3.3-70b`
Default base URL: `https://api.atlascloud.ai`
Atlas Cloud is an enterprise AI infrastructure platform offering high-performance LLM APIs. It exposes an OpenAI-compatible chat completions endpoint with tool calling support.
### MiniMax
```go
m := ai.New("minimax",
ai.WithAPIKey("your-key"),
ai.WithModel("MiniMax-M3"), // default
)
```
Default model: `MiniMax-M3`
Default base URL: `https://api.minimax.io`
MiniMax offers its flagship MiniMax-M3 model via an OpenAI-compatible chat completions endpoint.
## Auto-Detection
Use `AutoDetectProvider()` to detect the provider from a base URL:
```go
provider := ai.AutoDetectProvider("https://api.anthropic.com")
// Returns "anthropic"
m := ai.New(provider, ai.WithAPIKey("..."))
```
## Adding a New Provider
See the full **[AI Provider Integration Guide](../internal/website/docs/guides/ai-provider-guide.md)** for a step-by-step walkthrough, checklist, and design notes.
Quick summary:
1. Create `ai/yourprovider/yourprovider.go` implementing `ai.Model`.
2. Call `ai.Register("yourprovider", ...)` in `init()`.
3. Add tests in `ai/yourprovider/yourprovider_test.go`.
4. Users enable the provider with a blank import:
```go
import _ "go-micro.dev/v5/ai/yourprovider"
```
We welcome contributions and sponsorships from AI infrastructure companies — see the guide for details.
## Comparison with Other Packages
The ai package follows the same patterns as other go-micro packages:
**Registry:**
```go
r := registry.NewRegistry(registry.Addrs("..."))
r.Register(service)
```
**Client:**
```go
c := client.NewClient(client.Retries(3))
c.Call(ctx, req, rsp)
```
**AI:**
```go
m := ai.New("openai", ai.WithAPIKey("..."))
m.Generate(ctx, req)
```
All use:
- `Init()` to update options
- `Options()` to get current options
- `String()` to get the implementation name
- Functional options pattern
## Testing
```bash
go test ./ai/...
```
## Examples
See the [server implementation](../cmd/micro/server/server.go) for a complete example of using the ai package with tool execution.
+396
View File
@@ -0,0 +1,396 @@
// Package anthropic implements the Anthropic Claude model provider
package anthropic
import (
"bufio"
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"net/http"
"strings"
"go-micro.dev/v6/ai"
)
func init() {
ai.Register("anthropic", func(opts ...ai.Option) ai.Model {
return NewProvider(opts...)
})
ai.RegisterStream("anthropic")
}
// Provider implements the ai.Model interface for Anthropic Claude
type Provider struct {
opts ai.Options
}
// NewProvider creates a new Anthropic provider
func NewProvider(opts ...ai.Option) *Provider {
options := ai.NewOptions(opts...)
// Set defaults if not provided
if options.Model == "" {
options.Model = "claude-sonnet-4-20250514"
}
if options.BaseURL == "" {
options.BaseURL = "https://api.anthropic.com"
}
return &Provider{
opts: options,
}
}
// Init initializes the provider with options
func (p *Provider) Init(opts ...ai.Option) error {
for _, o := range opts {
o(&p.opts)
}
return nil
}
// Options returns the provider options
func (p *Provider) Options() ai.Options {
return p.opts
}
// String returns the provider name
func (p *Provider) String() string {
return "anthropic"
}
// Generate generates a response from the model
func (p *Provider) Generate(ctx context.Context, req *ai.Request, opts ...ai.GenerateOption) (*ai.Response, error) {
// Build tools for Anthropic format
var anthropicTools []map[string]any
for _, t := range req.Tools {
anthropicTools = append(anthropicTools, map[string]any{
"name": t.Name,
"description": t.Description,
"input_schema": map[string]any{
"type": "object",
"properties": t.Properties,
},
})
}
// Build initial request
apiReq := map[string]any{
"model": p.opts.Model,
"max_tokens": anthropicMaxTokens(p.opts),
"system": req.SystemPrompt,
"messages": threadAnthropicMessages(req),
}
if len(anthropicTools) > 0 {
apiReq["tools"] = anthropicTools
}
// Make API call
resp, rawContent, err := p.callAPI(ctx, apiReq)
if err != nil {
return nil, err
}
// If no tool calls or no handler, return as-is
if len(resp.ToolCalls) == 0 || p.opts.ToolHandler == nil {
return resp, nil
}
// Tool execution loop: execute tools, send results back, repeat
// until the model responds with text only (no more tool calls)
messages := append(threadAnthropicMessages(req),
map[string]any{"role": "assistant", "content": cleanContent(rawContent)},
)
pendingCalls := resp.ToolCalls
for rounds := 0; rounds < 10; rounds++ {
var toolResultBlocks []map[string]any
for i := range pendingCalls {
content := p.opts.ToolHandler(ctx, pendingCalls[i]).Content
pendingCalls[i].Result = content
toolResultBlocks = append(toolResultBlocks, map[string]any{
"type": "tool_result",
"tool_use_id": pendingCalls[i].ID,
"content": content,
})
}
messages = append(messages, map[string]any{
"role": "user",
"content": toolResultBlocks,
})
followUpReq := map[string]any{
"model": p.opts.Model,
"max_tokens": anthropicMaxTokens(p.opts),
"system": req.SystemPrompt,
"messages": messages,
}
if len(anthropicTools) > 0 {
followUpReq["tools"] = anthropicTools
}
followUpResp, followUpRaw, err := p.callAPI(ctx, followUpReq)
if err != nil {
break
}
if len(followUpResp.ToolCalls) > 0 {
resp.ToolCalls = append(resp.ToolCalls, followUpResp.ToolCalls...)
pendingCalls = followUpResp.ToolCalls
messages = append(messages, map[string]any{
"role": "assistant",
"content": cleanContent(followUpRaw),
})
continue
}
if followUpResp.Reply != "" {
resp.Answer = followUpResp.Reply
}
break
}
return resp, nil
}
// Stream generates a streaming response from Anthropic's Messages SSE API.
func (p *Provider) Stream(ctx context.Context, req *ai.Request, opts ...ai.GenerateOption) (ai.Stream, error) {
apiReq := map[string]any{
"model": p.opts.Model,
"max_tokens": anthropicMaxTokens(p.opts),
"system": req.SystemPrompt,
"messages": threadAnthropicMessages(req),
"stream": true,
}
reqBody, err := json.Marshal(apiReq)
if err != nil {
return nil, fmt.Errorf("failed to marshal stream request: %w", err)
}
apiURL := strings.TrimRight(p.opts.BaseURL, "/") + "/v1/messages"
httpReq, err := http.NewRequestWithContext(ctx, http.MethodPost, apiURL, bytes.NewReader(reqBody))
if err != nil {
return nil, fmt.Errorf("failed to create stream request: %w", err)
}
httpReq.Header.Set("Content-Type", "application/json")
httpReq.Header.Set("Accept", "text/event-stream")
httpReq.Header.Set("x-api-key", p.opts.APIKey)
httpReq.Header.Set("anthropic-version", "2023-06-01")
httpResp, err := http.DefaultClient.Do(httpReq)
if err != nil {
return nil, fmt.Errorf("stream API request failed: %w", err)
}
if httpResp.StatusCode != http.StatusOK {
defer httpResp.Body.Close()
respBody, _ := io.ReadAll(httpResp.Body)
return nil, fmt.Errorf("stream API error (%s): %s", httpResp.Status, string(respBody))
}
return &streamReader{body: httpResp.Body, scanner: bufio.NewScanner(httpResp.Body)}, nil
}
type streamReader struct {
body io.ReadCloser
scanner *bufio.Scanner
closed bool
}
func (s *streamReader) Recv() (*ai.Response, error) {
for s.scanner.Scan() {
line := strings.TrimSpace(s.scanner.Text())
if line == "" || strings.HasPrefix(line, ":") || strings.HasPrefix(line, "event:") {
continue
}
if !strings.HasPrefix(line, "data:") {
continue
}
data := strings.TrimSpace(strings.TrimPrefix(line, "data:"))
var chunk struct {
Type string `json:"type"`
Delta struct {
Type string `json:"type"`
Text string `json:"text"`
} `json:"delta"`
Message struct {
Usage struct {
InputTokens int `json:"input_tokens"`
OutputTokens int `json:"output_tokens"`
} `json:"usage"`
} `json:"message"`
Usage *struct {
InputTokens int `json:"input_tokens"`
OutputTokens int `json:"output_tokens"`
} `json:"usage"`
}
if err := json.Unmarshal([]byte(data), &chunk); err != nil {
return nil, fmt.Errorf("failed to parse stream chunk: %w", err)
}
switch chunk.Type {
case "content_block_delta":
if chunk.Delta.Type == "text_delta" && chunk.Delta.Text != "" {
return &ai.Response{Reply: chunk.Delta.Text}, nil
}
case "message_start":
if chunk.Message.Usage.InputTokens > 0 || chunk.Message.Usage.OutputTokens > 0 {
return &ai.Response{Usage: usage(chunk.Message.Usage.InputTokens, chunk.Message.Usage.OutputTokens)}, nil
}
case "message_delta":
if chunk.Usage != nil {
return &ai.Response{Usage: usage(chunk.Usage.InputTokens, chunk.Usage.OutputTokens)}, nil
}
case "message_stop":
return nil, io.EOF
case "error":
return nil, fmt.Errorf("anthropic stream error: %s", data)
}
}
if err := s.scanner.Err(); err != nil {
return nil, err
}
return nil, io.EOF
}
func (s *streamReader) Close() error {
if s.closed {
return nil
}
s.closed = true
return s.body.Close()
}
func usage(input, output int) ai.Usage {
return ai.Usage{InputTokens: input, OutputTokens: output, TotalTokens: input + output}
}
// callAPI makes an HTTP request to the Anthropic API
func (p *Provider) callAPI(ctx context.Context, req map[string]any) (*ai.Response, any, error) {
// Marshal request
reqBody, err := json.Marshal(req)
if err != nil {
return nil, nil, fmt.Errorf("failed to marshal request: %w", err)
}
// Build HTTP request
apiURL := strings.TrimRight(p.opts.BaseURL, "/") + "/v1/messages"
httpReq, err := http.NewRequestWithContext(ctx, http.MethodPost, apiURL, bytes.NewReader(reqBody))
if err != nil {
return nil, nil, fmt.Errorf("failed to create request: %w", err)
}
// Set headers
httpReq.Header.Set("Content-Type", "application/json")
httpReq.Header.Set("x-api-key", p.opts.APIKey)
httpReq.Header.Set("anthropic-version", "2023-06-01")
// Make request
httpResp, err := http.DefaultClient.Do(httpReq)
if err != nil {
return nil, nil, fmt.Errorf("API request failed: %w", err)
}
defer httpResp.Body.Close()
// Read response
respBody, _ := io.ReadAll(httpResp.Body)
if httpResp.StatusCode != http.StatusOK {
return nil, nil, ai.NewHTTPError(httpResp, respBody)
}
// Parse response
var anthropicResp struct {
Content []struct {
Type string `json:"type"`
Text string `json:"text"`
ID string `json:"id"`
Name string `json:"name"`
Input json.RawMessage `json:"input"`
} `json:"content"`
StopReason string `json:"stop_reason"`
}
if err := json.Unmarshal(respBody, &anthropicResp); err != nil {
return nil, nil, fmt.Errorf("failed to parse response: %w", err)
}
response := &ai.Response{}
// Extract text reply
var replyParts []string
for _, block := range anthropicResp.Content {
if block.Type == "text" && block.Text != "" {
replyParts = append(replyParts, block.Text)
}
}
if len(replyParts) > 0 {
response.Reply = strings.Join(replyParts, "\n")
}
// Extract tool calls
for _, block := range anthropicResp.Content {
if block.Type == "tool_use" {
var input map[string]any
if err := json.Unmarshal(block.Input, &input); err != nil {
input = map[string]any{}
}
response.ToolCalls = append(response.ToolCalls, ai.ToolCall{
ID: block.ID,
Name: block.Name,
Input: input,
})
}
}
return response, anthropicResp.Content, nil
}
// cleanContent strips fields from response content blocks that Anthropic
// rejects when sent back as assistant message content (e.g. "id" on text blocks).
func cleanContent(raw any) any {
blocks, ok := raw.([]struct {
Type string `json:"type"`
Text string `json:"text"`
ID string `json:"id"`
Name string `json:"name"`
Input json.RawMessage `json:"input"`
})
if !ok {
return raw
}
var cleaned []map[string]any
for _, b := range blocks {
switch b.Type {
case "text":
cleaned = append(cleaned, map[string]any{"type": "text", "text": b.Text})
case "tool_use":
var input any
_ = json.Unmarshal(b.Input, &input)
cleaned = append(cleaned, map[string]any{"type": "tool_use", "id": b.ID, "name": b.Name, "input": input})
}
}
return cleaned
}
// threadAnthropicMessages builds the Anthropic messages array from the
// conversation history (req.Messages) followed by the current prompt. The
// system prompt is sent separately via the top-level "system" field.
func threadAnthropicMessages(req *ai.Request) []map[string]any {
msgs := make([]map[string]any, 0, len(req.Messages)+1)
for _, m := range req.Messages {
msgs = append(msgs, map[string]any{"role": m.Role, "content": m.Content})
}
if req.Prompt != "" {
msgs = append(msgs, map[string]any{"role": "user", "content": req.Prompt})
}
return msgs
}
func anthropicMaxTokens(o ai.Options) int {
if o.MaxTokens > 0 {
return o.MaxTokens
}
return 8192
}
+151
View File
@@ -0,0 +1,151 @@
package anthropic
import (
"context"
"errors"
"io"
"net/http"
"net/http/httptest"
"strings"
"testing"
"go-micro.dev/v6/ai"
)
func TestProvider_String(t *testing.T) {
p := NewProvider()
if p.String() != "anthropic" {
t.Errorf("Expected provider name 'anthropic', got '%s'", p.String())
}
}
func TestProvider_Init(t *testing.T) {
p := NewProvider()
err := p.Init(
ai.WithModel("test-model"),
ai.WithAPIKey("test-key"),
ai.WithBaseURL("https://test.com"),
)
if err != nil {
t.Fatalf("Init failed: %v", err)
}
opts := p.Options()
if opts.Model != "test-model" {
t.Errorf("Expected model 'test-model', got '%s'", opts.Model)
}
if opts.APIKey != "test-key" {
t.Errorf("Expected API key 'test-key', got '%s'", opts.APIKey)
}
if opts.BaseURL != "https://test.com" {
t.Errorf("Expected base URL 'https://test.com', got '%s'", opts.BaseURL)
}
}
func TestProvider_Options(t *testing.T) {
p := NewProvider(
ai.WithModel("custom-model"),
ai.WithAPIKey("my-key"),
)
opts := p.Options()
if opts.Model != "custom-model" {
t.Errorf("Expected model 'custom-model', got '%s'", opts.Model)
}
if opts.APIKey != "my-key" {
t.Errorf("Expected API key 'my-key', got '%s'", opts.APIKey)
}
}
func TestProvider_Defaults(t *testing.T) {
p := NewProvider()
opts := p.Options()
if opts.Model != "claude-sonnet-4-20250514" {
t.Errorf("Expected default model 'claude-sonnet-4-20250514', got '%s'", opts.Model)
}
if opts.BaseURL != "https://api.anthropic.com" {
t.Errorf("Expected default base URL 'https://api.anthropic.com', got '%s'", opts.BaseURL)
}
}
func TestProvider_Generate_NoAPIKey(t *testing.T) {
p := NewProvider()
req := &ai.Request{
Prompt: "Hello",
SystemPrompt: "You are helpful",
}
_, err := p.Generate(context.Background(), req)
if err == nil {
t.Error("Expected error when API key is missing, got nil")
}
}
func TestProvider_Stream(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/v1/messages" {
t.Fatalf("path = %q, want /v1/messages", r.URL.Path)
}
if got := r.Header.Get("Accept"); got != "text/event-stream" {
t.Fatalf("Accept = %q, want text/event-stream", got)
}
if got := r.Header.Get("x-api-key"); got != "test-key" {
t.Fatalf("x-api-key = %q, want test-key", got)
}
body, _ := io.ReadAll(r.Body)
if !strings.Contains(string(body), `"stream":true`) {
t.Fatalf("request body %s does not enable streaming", string(body))
}
w.Header().Set("Content-Type", "text/event-stream")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte("event: message_start\n"))
_, _ = w.Write([]byte(`data: {"type":"message_start","message":{"usage":{"input_tokens":2}}}` + "\n\n"))
_, _ = w.Write([]byte("event: content_block_delta\n"))
_, _ = w.Write([]byte(`data: {"type":"content_block_delta","delta":{"type":"text_delta","text":"hel"}}` + "\n\n"))
_, _ = w.Write([]byte("event: content_block_delta\n"))
_, _ = w.Write([]byte(`data: {"type":"content_block_delta","delta":{"type":"text_delta","text":"lo"}}` + "\n\n"))
_, _ = w.Write([]byte("event: message_delta\n"))
_, _ = w.Write([]byte(`data: {"type":"message_delta","usage":{"output_tokens":3}}` + "\n\n"))
_, _ = w.Write([]byte("event: message_stop\n"))
_, _ = w.Write([]byte(`data: {"type":"message_stop"}` + "\n\n"))
}))
defer ts.Close()
p := NewProvider(ai.WithAPIKey("test-key"), ai.WithBaseURL(ts.URL))
req := &ai.Request{
Prompt: "Hello",
}
stream, err := p.Stream(context.Background(), req)
if err != nil {
t.Fatalf("Stream failed: %v", err)
}
defer stream.Close()
var reply strings.Builder
var usage ai.Usage
for {
chunk, err := stream.Recv()
if errors.Is(err, io.EOF) {
break
}
if err != nil {
t.Fatalf("Recv failed: %v", err)
}
reply.WriteString(chunk.Reply)
if chunk.Usage.TotalTokens > 0 {
usage = chunk.Usage
}
}
if got := reply.String(); got != "hello" {
t.Fatalf("reply = %q, want hello", got)
}
if usage.TotalTokens != 3 {
t.Fatalf("usage = %+v, want total 3", usage)
}
}
+848
View File
@@ -0,0 +1,848 @@
// Package atlascloud implements the Atlas Cloud model provider.
//
// Atlas Cloud is an enterprise AI infrastructure platform offering
// high-performance LLM, image, and video APIs. It exposes
// OpenAI-compatible endpoints for chat completions and image
// generation.
//
// Usage:
//
// import _ "go-micro.dev/v6/ai/atlascloud"
//
// m := ai.New("atlascloud",
// ai.WithAPIKey("your-api-key"),
// )
//
// // Image generation
// ig := ai.NewImage("atlascloud",
// ai.WithAPIKey("your-api-key"),
// )
package atlascloud
import (
"bufio"
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
"os"
"strings"
"time"
"go-micro.dev/v6/ai"
)
func init() {
ai.Register("atlascloud", func(opts ...ai.Option) ai.Model {
return NewProvider(opts...)
})
ai.RegisterImage("atlascloud", func(opts ...ai.Option) ai.ImageModel {
return NewProvider(opts...)
})
ai.RegisterVideo("atlascloud", func(opts ...ai.Option) ai.VideoModel {
return NewProvider(opts...)
})
ai.RegisterStream("atlascloud")
}
// Provider implements the ai.Model interface for Atlas Cloud.
type Provider struct {
opts ai.Options
}
type atlasToolCall struct {
ID string `json:"id"`
Type string `json:"type"`
Function struct {
Name string `json:"name"`
Arguments string `json:"arguments"`
} `json:"function"`
}
// NewProvider creates a new Atlas Cloud provider.
func NewProvider(opts ...ai.Option) *Provider {
options := ai.NewOptions(opts...)
if options.Model == "" {
// Allow the chat model to be selected via the ATLASCLOUD_MODEL env var
// (e.g. to run CI conformance against a stronger tool-use model) without
// a code change; fall back to a sensible default otherwise.
if m := os.Getenv("ATLASCLOUD_MODEL"); m != "" {
options.Model = m
} else {
options.Model = "deepseek-ai/DeepSeek-V3-0324"
}
}
if options.BaseURL == "" {
options.BaseURL = "https://api.atlascloud.ai"
}
return &Provider{opts: options}
}
func (p *Provider) Init(opts ...ai.Option) error {
for _, o := range opts {
o(&p.opts)
}
return nil
}
func (p *Provider) Options() ai.Options { return p.opts }
func (p *Provider) String() string { return "atlascloud" }
func (p *Provider) Generate(ctx context.Context, req *ai.Request, opts ...ai.GenerateOption) (*ai.Response, error) {
tools := atlascloudTools(req.Tools)
compatTools, compatPrompt := atlascloudMinimaxCompatTools(p.opts.Model, req.Tools)
messages := []map[string]any{
{"role": "system", "content": req.SystemPrompt},
}
for _, m := range req.Messages {
messages = append(messages, map[string]any{"role": m.Role, "content": m.Content})
}
if req.Prompt != "" {
messages = append(messages, map[string]any{"role": "user", "content": req.Prompt})
}
if compatPrompt != "" {
messages = append(messages, map[string]any{"role": "system", "content": compatPrompt})
}
apiReq := map[string]any{
"model": p.opts.Model,
"messages": messages,
}
if p.opts.MaxTokens > 0 {
apiReq["max_tokens"] = p.opts.MaxTokens
}
if len(tools) > 0 {
apiReq["tools"] = tools
}
resp, rawMessage, err := p.callAPI(ctx, "chat", apiReq)
if err != nil {
if atlascloudShouldRetryMinimaxCompat(err, compatTools) {
apiReq["tools"] = compatTools
resp, rawMessage, err = p.callAPI(ctx, "chat-minimax-compat", apiReq)
}
if err != nil {
return nil, err
}
}
if len(resp.ToolCalls) == 0 {
return resp, nil
}
if p.opts.ToolHandler != nil {
var allToolCalls []ai.ToolCall
var toolResults []string
pendingToolCalls := append([]ai.ToolCall(nil), resp.ToolCalls...)
followUpMessages := append(messages, map[string]any{
"role": "assistant",
"content": rawMessage["content"],
"tool_calls": rawMessage["tool_calls"],
})
for attempt := 0; len(pendingToolCalls) > 0 && attempt < 4; attempt++ {
for _, tc := range pendingToolCalls {
result := p.opts.ToolHandler(ctx, tc)
if result.Refused != "" {
tc.Error = result.Refused
}
if result.Content != "" {
tc.Result = result.Content
toolResults = append(toolResults, result.Content)
}
allToolCalls = append(allToolCalls, tc)
resp.ToolCalls = allToolCalls
followUpMessages = append(followUpMessages, map[string]any{
"role": "tool",
"tool_call_id": tc.ID,
"content": result.Content,
})
}
followUpReq := map[string]any{
"model": p.opts.Model,
"messages": followUpMessages,
}
if len(tools) > 0 {
// Keep the tool schema available during follow-up turns. Minimax
// models behind Atlas Cloud sometimes complete a multi-tool task
// one call at a time (plan, then service tools, then delegate).
followUpReq["tools"] = tools
}
followUpResp, followUpRawMessage, err := p.callAPI(ctx, "tool-follow-up", followUpReq)
if err != nil {
if atlascloudShouldRetryWithoutTools(err, followUpReq) {
delete(followUpReq, "tools")
followUpResp, followUpRawMessage, err = p.callAPI(ctx, "tool-follow-up-no-tools", followUpReq)
}
if err != nil {
return nil, err
}
}
if len(followUpResp.ToolCalls) == 0 {
if followUpResp.Reply != "" {
if strings.Contains(followUpResp.Reply, "<tool_call") || strings.Contains(followUpResp.Reply, "function=") {
// Preserve follow-up assistant content as Reply, not Answer, when
// it may contain a text-encoded tool call. The agent harness
// inspects Reply for text fallback calls after Generate returns.
resp.Reply = followUpResp.Reply
} else {
resp.Answer = followUpResp.Reply
}
} else if len(toolResults) > 0 {
resp.Answer = strings.Join(toolResults, "\n")
}
break
}
followUpMessages = append(followUpMessages, map[string]any{
"role": "assistant",
"content": followUpRawMessage["content"],
"tool_calls": followUpRawMessage["tool_calls"],
})
pendingToolCalls = followUpResp.ToolCalls
}
}
return resp, nil
}
// Stream generates a streaming response from Atlas Cloud's OpenAI-compatible
// chat completions endpoint, emitting content deltas as they arrive.
func (p *Provider) Stream(ctx context.Context, req *ai.Request, opts ...ai.GenerateOption) (ai.Stream, error) {
if len(req.Tools) > 0 {
return nil, fmt.Errorf("%w: atlascloud streaming does not expose tools", ai.ErrStreamingUnsupported)
}
messages := []map[string]any{
{"role": "system", "content": req.SystemPrompt},
}
for _, m := range req.Messages {
messages = append(messages, map[string]any{"role": m.Role, "content": m.Content})
}
if req.Prompt != "" {
messages = append(messages, map[string]any{"role": "user", "content": req.Prompt})
}
apiReq := map[string]any{
"model": p.opts.Model,
"messages": messages,
"stream": true,
"stream_options": map[string]any{"include_usage": true},
}
if p.opts.MaxTokens > 0 {
apiReq["max_tokens"] = p.opts.MaxTokens
}
reqBody, err := json.Marshal(apiReq)
if err != nil {
return nil, fmt.Errorf("failed to marshal stream request: %w", err)
}
apiURL := strings.TrimRight(p.opts.BaseURL, "/") + "/v1/chat/completions"
httpReq, err := http.NewRequestWithContext(ctx, http.MethodPost, apiURL, bytes.NewReader(reqBody))
if err != nil {
return nil, fmt.Errorf("failed to create stream request: %w", err)
}
httpReq.Header.Set("Content-Type", "application/json")
httpReq.Header.Set("Accept", "text/event-stream")
httpReq.Header.Set("Authorization", "Bearer "+p.opts.APIKey)
httpResp, err := http.DefaultClient.Do(httpReq)
if err != nil {
return nil, fmt.Errorf("stream API request failed: %w", err)
}
if httpResp.StatusCode != http.StatusOK {
defer httpResp.Body.Close()
respBody, _ := io.ReadAll(httpResp.Body)
return nil, fmt.Errorf("stream API error (%s): %s", httpResp.Status, string(respBody))
}
return &atlasStream{body: httpResp.Body, scanner: bufio.NewScanner(httpResp.Body)}, nil
}
type atlasStream struct {
body io.ReadCloser
scanner *bufio.Scanner
closed bool
}
func (s *atlasStream) Recv() (*ai.Response, error) {
for s.scanner.Scan() {
line := strings.TrimSpace(s.scanner.Text())
if line == "" || strings.HasPrefix(line, ":") {
continue
}
if !strings.HasPrefix(line, "data:") {
continue
}
data := strings.TrimSpace(strings.TrimPrefix(line, "data:"))
if data == "[DONE]" {
return nil, io.EOF
}
var chunk struct {
Choices []struct {
Delta struct {
Content string `json:"content"`
} `json:"delta"`
} `json:"choices"`
Usage *struct {
PromptTokens int `json:"prompt_tokens"`
CompletionTokens int `json:"completion_tokens"`
TotalTokens int `json:"total_tokens"`
} `json:"usage"`
}
if err := json.Unmarshal([]byte(data), &chunk); err != nil {
return nil, fmt.Errorf("failed to parse stream chunk: %w", err)
}
if len(chunk.Choices) > 0 && chunk.Choices[0].Delta.Content != "" {
return &ai.Response{Reply: chunk.Choices[0].Delta.Content}, nil
}
// Final chunk (after include_usage) carries token usage and no content.
if chunk.Usage != nil {
return &ai.Response{Usage: ai.Usage{
InputTokens: chunk.Usage.PromptTokens,
OutputTokens: chunk.Usage.CompletionTokens,
TotalTokens: chunk.Usage.TotalTokens,
}}, nil
}
continue
}
if err := s.scanner.Err(); err != nil {
return nil, err
}
return nil, io.EOF
}
func (s *atlasStream) Close() error {
if s.closed {
return nil
}
s.closed = true
return s.body.Close()
}
type atlascloudAPIError struct {
Status string
Code int
Retry time.Duration
Phase string
Summary string
Body string
}
func (e *atlascloudAPIError) Error() string {
return fmt.Sprintf("API error (%s) during atlascloud %s request (%s): %s", e.Status, e.Phase, e.Summary, e.Body)
}
func (e *atlascloudAPIError) StatusCode() int {
if e == nil {
return 0
}
return e.Code
}
func (e *atlascloudAPIError) RetryAfter() time.Duration {
if e == nil {
return 0
}
return e.Retry
}
func (p *Provider) callAPI(ctx context.Context, phase string, req map[string]any) (*ai.Response, map[string]any, error) {
reqBody, err := json.Marshal(req)
if err != nil {
return nil, nil, fmt.Errorf("failed to marshal request: %w", err)
}
apiURL := strings.TrimRight(p.opts.BaseURL, "/") + "/v1/chat/completions"
httpReq, err := http.NewRequestWithContext(ctx, http.MethodPost, apiURL, bytes.NewReader(reqBody))
if err != nil {
return nil, nil, fmt.Errorf("failed to create request: %w", err)
}
httpReq.Header.Set("Content-Type", "application/json")
httpReq.Header.Set("Authorization", "Bearer "+p.opts.APIKey)
httpResp, err := http.DefaultClient.Do(httpReq)
if err != nil {
return nil, nil, fmt.Errorf("API request failed: %w", err)
}
defer httpResp.Body.Close()
respBody, _ := io.ReadAll(httpResp.Body)
if httpResp.StatusCode != http.StatusOK {
retryAfter := time.Duration(0)
var retryErr interface{ RetryAfter() time.Duration }
if errors.As(ai.NewHTTPError(httpResp, respBody), &retryErr) {
retryAfter = retryErr.RetryAfter()
}
return nil, nil, &atlascloudAPIError{Status: httpResp.Status, Code: httpResp.StatusCode, Retry: retryAfter, Phase: phase, Summary: atlascloudRequestSummary(req), Body: string(respBody)}
}
var chatResp struct {
Choices []struct {
Message struct {
Content string `json:"content"`
ToolCalls []atlasToolCall `json:"tool_calls"`
} `json:"message"`
} `json:"choices"`
}
if err := json.Unmarshal(respBody, &chatResp); err != nil {
return nil, nil, fmt.Errorf("failed to parse response: %w", err)
}
if len(chatResp.Choices) == 0 {
return nil, nil, fmt.Errorf("no response from API")
}
choice := chatResp.Choices[0]
response := &ai.Response{
Reply: choice.Message.Content,
}
for _, tc := range choice.Message.ToolCalls {
var input map[string]any
if err := json.Unmarshal([]byte(tc.Function.Arguments), &input); err != nil {
input = map[string]any{}
}
response.ToolCalls = append(response.ToolCalls, ai.ToolCall{
ID: tc.ID,
Name: tc.Function.Name,
Input: input,
})
}
rawMessage := map[string]any{
"content": choice.Message.Content,
"tool_calls": normalizeAtlasCloudToolCalls(choice.Message.ToolCalls),
}
return response, rawMessage, nil
}
func atlascloudMinimaxCompatTools(model string, input []ai.Tool) ([]map[string]any, string) {
if !atlascloudIsMinimaxModel(model) || len(input) == 0 {
return nil, ""
}
var native []ai.Tool
var builtins []string
for _, tool := range input {
switch tool.Name {
case "plan", "request_input", "delegate":
builtins = append(builtins, tool.Name)
default:
native = append(native, tool)
}
}
if len(builtins) == 0 || len(native) == len(input) {
return nil, ""
}
prompt := "AtlasCloud/minimax compatibility: use native tool_calls for the listed service tools. " +
"For built-in agent tools that are not listed natively (" + strings.Join(builtins, ", ") +
"), emit exactly <tool_call name=\"tool_name\">{...}</tool_call> so the agent runtime can execute them. Do not describe those built-in tool calls in prose instead of emitting the tag."
return atlascloudTools(native), prompt
}
func atlascloudIsMinimaxModel(model string) bool {
model = strings.ToLower(model)
return strings.Contains(model, "minimax")
}
func atlascloudShouldRetryMinimaxCompat(err error, compatTools []map[string]any) bool {
if len(compatTools) == 0 {
return false
}
var apiErr *atlascloudAPIError
return errors.As(err, &apiErr) && apiErr.StatusCode() == http.StatusBadRequest
}
func atlascloudShouldRetryWithoutTools(err error, req map[string]any) bool {
if _, ok := req["tools"]; !ok {
return false
}
var apiErr *atlascloudAPIError
return errors.As(err, &apiErr) && apiErr.StatusCode() == http.StatusBadRequest
}
func atlascloudTools(input []ai.Tool) []map[string]any {
tools := make([]map[string]any, 0, len(input))
for _, t := range input {
tools = append(tools, map[string]any{
"type": "function",
"function": map[string]any{
"name": t.Name,
"description": t.Description,
"parameters": map[string]any{
"type": "object",
"properties": normalizeAtlasCloudSchema(t.Properties),
},
},
})
}
return tools
}
func normalizeAtlasCloudSchema(schema map[string]any) map[string]any {
if schema == nil {
return nil
}
out := make(map[string]any, len(schema))
for k, v := range schema {
out[k] = normalizeAtlasCloudSchemaValue(v)
}
return out
}
func normalizeAtlasCloudSchemaValue(v any) any {
switch val := v.(type) {
case map[string]any:
out := make(map[string]any, len(val)+1)
for k, nested := range val {
out[k] = normalizeAtlasCloudSchemaValue(nested)
}
if typ, _ := out["type"].(string); typ == "array" {
if _, ok := out["items"]; !ok {
out["items"] = map[string]any{}
}
}
return out
case []any:
out := make([]any, len(val))
for i, nested := range val {
out[i] = normalizeAtlasCloudSchemaValue(nested)
}
return out
default:
return v
}
}
func normalizeAtlasCloudToolCalls(toolCalls []atlasToolCall) []map[string]any {
out := make([]map[string]any, 0, len(toolCalls))
for _, tc := range toolCalls {
toolType := tc.Type
if toolType == "" {
toolType = "function"
}
out = append(out, map[string]any{
"id": tc.ID,
"type": toolType,
"function": map[string]any{
"name": tc.Function.Name,
"arguments": tc.Function.Arguments,
},
})
}
return out
}
func atlascloudRequestSummary(req map[string]any) string {
parts := []string{}
if model, ok := req["model"].(string); ok && model != "" {
parts = append(parts, "model="+model)
}
if messages, ok := req["messages"].([]map[string]any); ok {
parts = append(parts, fmt.Sprintf("messages=%d", len(messages)))
if len(messages) > 0 {
last := messages[len(messages)-1]
if role, ok := last["role"].(string); ok && role != "" {
parts = append(parts, "last_role="+role)
}
if _, ok := last["tool_call_id"].(string); ok {
parts = append(parts, "last_has_tool_call_id=true")
}
}
}
if tools, ok := req["tools"].([]map[string]any); ok {
names := make([]string, 0, len(tools))
for _, tool := range tools {
fn, _ := tool["function"].(map[string]any)
name, _ := fn["name"].(string)
if name != "" {
names = append(names, name)
}
}
parts = append(parts, fmt.Sprintf("tools=%d", len(tools)))
if len(names) > 0 {
parts = append(parts, "tool_names="+strings.Join(names, ","))
}
}
if len(parts) == 0 {
return "request_context=unavailable"
}
return strings.Join(parts, " ")
}
const defaultImageModel = "openai/gpt-image-2/text-to-image"
// GenerateImage creates an image using Atlas Cloud's async image API.
// It submits the job and polls until completion or context cancellation.
func (p *Provider) GenerateImage(ctx context.Context, req *ai.ImageRequest, opts ...ai.GenerateOption) (*ai.ImageResponse, error) {
model := req.Model
if model == "" {
model = defaultImageModel
}
quality := req.Quality
if quality == "" {
quality = "medium"
}
outputFmt := req.OutputFormat
if outputFmt == "" {
outputFmt = "png"
}
size := req.Size
if size == "" {
size = "1024x1024"
}
apiReq := map[string]any{
"model": model,
"prompt": req.Prompt,
"quality": quality,
"output_format": outputFmt,
"size": size,
"enable_sync_mode": false,
"enable_base64_output": false,
"moderation": "low",
}
reqBody, err := json.Marshal(apiReq)
if err != nil {
return nil, fmt.Errorf("failed to marshal request: %w", err)
}
apiURL := strings.TrimRight(p.opts.BaseURL, "/") + "/api/v1/model/generateImage"
httpReq, err := http.NewRequestWithContext(ctx, http.MethodPost, apiURL, bytes.NewReader(reqBody))
if err != nil {
return nil, fmt.Errorf("failed to create request: %w", err)
}
httpReq.Header.Set("Content-Type", "application/json")
httpReq.Header.Set("Authorization", "Bearer "+p.opts.APIKey)
httpResp, err := http.DefaultClient.Do(httpReq)
if err != nil {
return nil, fmt.Errorf("API request failed: %w", err)
}
defer httpResp.Body.Close()
respBody, _ := io.ReadAll(httpResp.Body)
if httpResp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("API error (%s): %s", httpResp.Status, string(respBody))
}
var submitResp struct {
Code int `json:"code"`
Msg string `json:"message"`
Data struct {
ID string `json:"id"`
Status string `json:"status"`
} `json:"data"`
}
if err := json.Unmarshal(respBody, &submitResp); err != nil {
return nil, fmt.Errorf("failed to parse submit response: %w", err)
}
if submitResp.Code != 200 {
return nil, fmt.Errorf("API error: %s", submitResp.Msg)
}
predictionID := submitResp.Data.ID
pollURL := strings.TrimRight(p.opts.BaseURL, "/") + "/api/v1/model/prediction/" + predictionID
ticker := time.NewTicker(2 * time.Second)
defer ticker.Stop()
for {
select {
case <-ctx.Done():
return nil, ctx.Err()
case <-ticker.C:
result, err := p.pollPrediction(ctx, pollURL)
if err != nil {
return nil, err
}
if result != nil {
return result, nil
}
}
}
}
func (p *Provider) pollPrediction(ctx context.Context, url string) (*ai.ImageResponse, error) {
httpReq, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err != nil {
return nil, err
}
httpReq.Header.Set("Authorization", "Bearer "+p.opts.APIKey)
httpResp, err := http.DefaultClient.Do(httpReq)
if err != nil {
return nil, fmt.Errorf("poll request failed: %w", err)
}
defer httpResp.Body.Close()
body, _ := io.ReadAll(httpResp.Body)
var pollResp struct {
Data struct {
Status string `json:"status"`
Outputs []string `json:"outputs"`
Error string `json:"error"`
} `json:"data"`
}
if err := json.Unmarshal(body, &pollResp); err != nil {
return nil, fmt.Errorf("failed to parse poll response: %w", err)
}
switch pollResp.Data.Status {
case "completed":
resp := &ai.ImageResponse{}
for _, output := range pollResp.Data.Outputs {
resp.Images = append(resp.Images, ai.Image{URL: output})
}
return resp, nil
case "failed":
return nil, fmt.Errorf("image generation failed: %s", pollResp.Data.Error)
default:
return nil, nil
}
}
const defaultVideoModel = "google/gemini-omni-flash/image-to-video-developer"
// GenerateVideo creates a video using Atlas Cloud's async video API.
// Supports text-to-video and image-to-video depending on whether
// Images are provided in the request.
func (p *Provider) GenerateVideo(ctx context.Context, req *ai.VideoRequest, opts ...ai.GenerateOption) (*ai.VideoResponse, error) {
model := req.Model
if model == "" {
model = defaultVideoModel
}
duration := req.Duration
if duration <= 0 {
duration = 6
}
aspect := req.AspectRatio
if aspect == "" {
aspect = "16:9"
}
resolution := req.Resolution
if resolution == "" {
resolution = "720p"
}
apiReq := map[string]any{
"model": model,
"prompt": req.Prompt,
"duration": duration,
"aspect_ratio": aspect,
"resolution": resolution,
"seed": -1,
}
if len(req.Images) > 0 {
apiReq["images"] = req.Images
}
reqBody, err := json.Marshal(apiReq)
if err != nil {
return nil, fmt.Errorf("failed to marshal request: %w", err)
}
apiURL := strings.TrimRight(p.opts.BaseURL, "/") + "/api/v1/model/generateVideo"
httpReq, err := http.NewRequestWithContext(ctx, http.MethodPost, apiURL, bytes.NewReader(reqBody))
if err != nil {
return nil, fmt.Errorf("failed to create request: %w", err)
}
httpReq.Header.Set("Content-Type", "application/json")
httpReq.Header.Set("Authorization", "Bearer "+p.opts.APIKey)
httpResp, err := http.DefaultClient.Do(httpReq)
if err != nil {
return nil, fmt.Errorf("API request failed: %w", err)
}
defer httpResp.Body.Close()
respBody, _ := io.ReadAll(httpResp.Body)
if httpResp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("API error (%s): %s", httpResp.Status, string(respBody))
}
var submitResp struct {
Code int `json:"code"`
Msg string `json:"message"`
Data struct {
ID string `json:"id"`
Status string `json:"status"`
} `json:"data"`
}
if err := json.Unmarshal(respBody, &submitResp); err != nil {
return nil, fmt.Errorf("failed to parse submit response: %w", err)
}
if submitResp.Code != 200 {
return nil, fmt.Errorf("API error: %s", submitResp.Msg)
}
pollURL := strings.TrimRight(p.opts.BaseURL, "/") + "/api/v1/model/prediction/" + submitResp.Data.ID
ticker := time.NewTicker(5 * time.Second)
defer ticker.Stop()
for {
select {
case <-ctx.Done():
return nil, ctx.Err()
case <-ticker.C:
result, err := p.pollVideo(ctx, pollURL)
if err != nil {
return nil, err
}
if result != nil {
return result, nil
}
}
}
}
func (p *Provider) pollVideo(ctx context.Context, url string) (*ai.VideoResponse, error) {
httpReq, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err != nil {
return nil, err
}
httpReq.Header.Set("Authorization", "Bearer "+p.opts.APIKey)
httpResp, err := http.DefaultClient.Do(httpReq)
if err != nil {
return nil, fmt.Errorf("poll request failed: %w", err)
}
defer httpResp.Body.Close()
body, _ := io.ReadAll(httpResp.Body)
var pollResp struct {
Data struct {
Status string `json:"status"`
Outputs []string `json:"outputs"`
Error string `json:"error"`
} `json:"data"`
}
if err := json.Unmarshal(body, &pollResp); err != nil {
return nil, fmt.Errorf("failed to parse poll response: %w", err)
}
switch pollResp.Data.Status {
case "completed", "succeeded":
if len(pollResp.Data.Outputs) == 0 {
return nil, fmt.Errorf("video completed but no outputs returned")
}
return &ai.VideoResponse{URL: pollResp.Data.Outputs[0]}, nil
case "failed":
return nil, fmt.Errorf("video generation failed: %s", pollResp.Data.Error)
default:
return nil, nil
}
}
+722
View File
@@ -0,0 +1,722 @@
package atlascloud
import (
"context"
"encoding/json"
"errors"
"io"
"net/http"
"net/http/httptest"
"strings"
"testing"
"go-micro.dev/v6/ai"
)
func TestProvider_String(t *testing.T) {
p := NewProvider()
if p.String() != "atlascloud" {
t.Errorf("Expected provider name 'atlascloud', got '%s'", p.String())
}
}
func TestProvider_Init(t *testing.T) {
p := NewProvider()
err := p.Init(
ai.WithModel("test-model"),
ai.WithAPIKey("test-key"),
ai.WithBaseURL("https://test.com"),
)
if err != nil {
t.Fatalf("Init failed: %v", err)
}
opts := p.Options()
if opts.Model != "test-model" {
t.Errorf("Expected model 'test-model', got '%s'", opts.Model)
}
if opts.APIKey != "test-key" {
t.Errorf("Expected API key 'test-key', got '%s'", opts.APIKey)
}
if opts.BaseURL != "https://test.com" {
t.Errorf("Expected base URL 'https://test.com', got '%s'", opts.BaseURL)
}
}
func TestProvider_Options(t *testing.T) {
p := NewProvider(
ai.WithModel("custom-model"),
ai.WithAPIKey("my-key"),
)
opts := p.Options()
if opts.Model != "custom-model" {
t.Errorf("Expected model 'custom-model', got '%s'", opts.Model)
}
if opts.APIKey != "my-key" {
t.Errorf("Expected API key 'my-key', got '%s'", opts.APIKey)
}
}
func TestProvider_Defaults(t *testing.T) {
p := NewProvider()
opts := p.Options()
if opts.Model != "deepseek-ai/DeepSeek-V3-0324" {
t.Errorf("Expected default model 'deepseek-ai/DeepSeek-V3-0324', got '%s'", opts.Model)
}
if opts.BaseURL != "https://api.atlascloud.ai" {
t.Errorf("Expected default base URL 'https://api.atlascloud.ai', got '%s'", opts.BaseURL)
}
}
func TestProvider_Generate_NoAPIKey(t *testing.T) {
p := NewProvider()
req := &ai.Request{
Prompt: "Hello",
SystemPrompt: "You are helpful",
}
_, err := p.Generate(context.Background(), req)
if err == nil {
t.Error("Expected error when API key is missing, got nil")
}
}
func TestProvider_Stream(t *testing.T) {
var sawStream, sawIncludeUsage bool
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/v1/chat/completions" {
t.Errorf("path = %s, want /v1/chat/completions", r.URL.Path)
}
var body map[string]any
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
t.Fatalf("decode request: %v", err)
}
sawStream, _ = body["stream"].(bool)
if so, ok := body["stream_options"].(map[string]any); ok {
sawIncludeUsage, _ = so["include_usage"].(bool)
}
w.Header().Set("Content-Type", "text/event-stream")
_, _ = w.Write([]byte("data: {\"choices\":[{\"delta\":{\"content\":\"hel\"}}]}\n\n"))
_, _ = w.Write([]byte("data: {\"choices\":[{\"delta\":{\"content\":\"lo\"}}]}\n\n"))
_, _ = w.Write([]byte("data: {\"choices\":[],\"usage\":{\"prompt_tokens\":7,\"completion_tokens\":2,\"total_tokens\":9}}\n\n"))
_, _ = w.Write([]byte("data: [DONE]\n\n"))
}))
defer ts.Close()
p := NewProvider(ai.WithAPIKey("test-key"), ai.WithBaseURL(ts.URL))
stream, err := p.Stream(context.Background(), &ai.Request{Prompt: "Hello"})
if err != nil {
t.Fatalf("Stream returned error: %v", err)
}
defer stream.Close()
if !sawStream {
t.Fatal("stream request did not set stream=true")
}
if !sawIncludeUsage {
t.Fatal("stream request did not set stream_options.include_usage=true")
}
first, err := stream.Recv()
if err != nil || first.Reply != "hel" {
t.Fatalf("first chunk = %#v, %v; want hel", first, err)
}
second, err := stream.Recv()
if err != nil || second.Reply != "lo" {
t.Fatalf("second chunk = %#v, %v; want lo", second, err)
}
usage, err := stream.Recv()
if err != nil {
t.Fatalf("usage chunk error: %v", err)
}
if usage.Usage.TotalTokens != 9 || usage.Usage.InputTokens != 7 || usage.Usage.OutputTokens != 2 {
t.Fatalf("usage = %#v; want input=7 output=2 total=9", usage.Usage)
}
if _, err := stream.Recv(); !errors.Is(err, io.EOF) {
t.Fatalf("final error = %v, want EOF", err)
}
}
func TestProvider_StreamWithToolsFallsBack(t *testing.T) {
p := NewProvider(ai.WithAPIKey("test-key"))
_, err := p.Stream(context.Background(), &ai.Request{
Prompt: "call a tool",
Tools: []ai.Tool{{
Name: "fallback_echo",
Description: "echo fallback marker",
Properties: map[string]any{"value": map[string]any{"type": "string"}},
}},
})
if !errors.Is(err, ai.ErrStreamingUnsupported) {
t.Fatalf("Stream with tools error = %v, want ErrStreamingUnsupported", err)
}
}
func TestProvider_GenerateToolCallEmptyFollowUpUsesToolResult(t *testing.T) {
var calls int
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/v1/chat/completions" {
t.Errorf("path = %s, want /v1/chat/completions", r.URL.Path)
}
calls++
w.Header().Set("Content-Type", "application/json")
switch calls {
case 1:
_, _ = w.Write([]byte(`{"choices":[{"message":{"content":"","tool_calls":[{"id":"call-1","function":{"name":"conformance_echo","arguments":"{\"value\":\"agent-conformance\"}"}}]}}]}`))
case 2:
_, _ = w.Write([]byte(`{"choices":[{"message":{"content":""}}]}`))
default:
t.Fatalf("unexpected API call %d", calls)
}
}))
defer ts.Close()
p := NewProvider(
ai.WithAPIKey("test-key"),
ai.WithBaseURL(ts.URL),
ai.WithToolHandler(func(ctx context.Context, call ai.ToolCall) ai.ToolResult {
if call.Name != "conformance_echo" {
t.Fatalf("tool name = %q, want conformance_echo", call.Name)
}
return ai.ToolResult{ID: call.ID, Content: `{"marker":"agent-conformance-ok"}`}
}),
)
resp, err := p.Generate(context.Background(), &ai.Request{
Prompt: "call a tool",
Tools: []ai.Tool{{
Name: "conformance_echo",
Description: "echo conformance marker",
Properties: map[string]any{"value": map[string]any{"type": "string"}},
}},
})
if err != nil {
t.Fatalf("Generate returned error: %v", err)
}
if calls != 2 {
t.Fatalf("API calls = %d, want 2", calls)
}
if resp.Answer != `{"marker":"agent-conformance-ok"}` {
t.Fatalf("Answer = %q, want tool result fallback", resp.Answer)
}
}
func TestProvider_GenerateMinimaxToolRequests(t *testing.T) {
var bodies []map[string]any
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var body map[string]any
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
t.Fatalf("decode request: %v", err)
}
bodies = append(bodies, body)
w.Header().Set("Content-Type", "application/json")
switch len(bodies) {
case 1:
_, _ = w.Write([]byte(`{"choices":[{"message":{"content":"","tool_calls":[{"id":"call-1","function":{"name":"conformance_echo","arguments":"{\"value\":\"agent-conformance\"}"}}]}}]}`))
case 2:
_, _ = w.Write([]byte(`{"choices":[{"message":{"content":"done"}}]}`))
default:
t.Fatalf("unexpected API call %d", len(bodies))
}
}))
defer ts.Close()
p := NewProvider(
ai.WithAPIKey("test-key"),
ai.WithBaseURL(ts.URL),
ai.WithModel("minimaxai/minimax-m3"),
ai.WithToolHandler(func(ctx context.Context, call ai.ToolCall) ai.ToolResult {
return ai.ToolResult{ID: call.ID, Content: `{"marker":"agent-conformance-ok"}`}
}),
)
resp, err := p.Generate(context.Background(), &ai.Request{
SystemPrompt: "You are helpful.",
Prompt: "call a tool",
Tools: []ai.Tool{{
Name: "conformance_echo",
Description: "echo conformance marker",
Properties: map[string]any{"value": map[string]any{"type": "string"}},
}},
})
if err != nil {
t.Fatalf("Generate returned error: %v", err)
}
if resp.Answer != "done" {
t.Fatalf("Answer = %q, want done", resp.Answer)
}
if len(bodies) != 2 {
t.Fatalf("captured requests = %d, want 2", len(bodies))
}
if got := bodies[0]["model"]; got != "minimaxai/minimax-m3" {
t.Fatalf("initial model = %v", got)
}
tools, ok := bodies[0]["tools"].([]any)
if !ok || len(tools) != 1 {
t.Fatalf("initial tools = %#v, want one tool", bodies[0]["tools"])
}
tool := tools[0].(map[string]any)
if tool["type"] != "function" {
t.Fatalf("tool type = %v, want function", tool["type"])
}
fn := tool["function"].(map[string]any)
if fn["name"] != "conformance_echo" {
t.Fatalf("tool function name = %v", fn["name"])
}
params := fn["parameters"].(map[string]any)
if params["type"] != "object" {
t.Fatalf("parameters type = %v, want object", params["type"])
}
followUpMessages := bodies[1]["messages"].([]any)
if len(followUpMessages) != 4 {
t.Fatalf("follow-up messages = %d, want 4", len(followUpMessages))
}
assistant := followUpMessages[2].(map[string]any)
if assistant["role"] != "assistant" {
t.Fatalf("assistant role = %v", assistant["role"])
}
assistantCalls := assistant["tool_calls"].([]any)
assistantCall := assistantCalls[0].(map[string]any)
if assistantCall["type"] != "function" {
t.Fatalf("assistant tool call type = %v, want function", assistantCall["type"])
}
toolResult := followUpMessages[3].(map[string]any)
if toolResult["role"] != "tool" || toolResult["tool_call_id"] != "call-1" {
t.Fatalf("tool result message = %#v", toolResult)
}
}
func TestProvider_GenerateNormalizesBuiltInToolSchemas(t *testing.T) {
var body map[string]any
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
t.Fatalf("decode request: %v", err)
}
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{"choices":[{"message":{"content":"ok"}}]}`))
}))
defer ts.Close()
planProperties := map[string]any{
"steps": map[string]any{
"type": "array",
"description": "ordered plan steps",
},
}
p := NewProvider(
ai.WithAPIKey("test-key"),
ai.WithBaseURL(ts.URL),
ai.WithModel("minimaxai/minimax-m3"),
)
_, err := p.Generate(context.Background(), &ai.Request{
Prompt: "plan and delegate",
Tools: []ai.Tool{
{Name: "task_TaskService_Add", Description: "add task", Properties: map[string]any{"title": map[string]any{"type": "string"}}},
{Name: "plan", Description: "record a plan", Properties: planProperties},
{Name: "request_input", Description: "request input", Properties: map[string]any{"prompt": map[string]any{"type": "string"}}},
{Name: "delegate", Description: "delegate work", Properties: map[string]any{"task": map[string]any{"type": "string"}, "to": map[string]any{"type": "string"}}},
},
})
if err != nil {
t.Fatalf("Generate returned error: %v", err)
}
tools := body["tools"].([]any)
if len(tools) != 4 {
t.Fatalf("tools = %d, want custom tool plus built-ins", len(tools))
}
planTool := tools[1].(map[string]any)
fn := planTool["function"].(map[string]any)
params := fn["parameters"].(map[string]any)
props := params["properties"].(map[string]any)
steps := props["steps"].(map[string]any)
if _, ok := steps["items"].(map[string]any); !ok {
t.Fatalf("plan steps schema = %#v, want array items for AtlasCloud/minimax", steps)
}
if _, mutated := planProperties["steps"].(map[string]any)["items"]; mutated {
t.Fatalf("Generate mutated caller tool schema: %#v", planProperties)
}
}
func TestProvider_GenerateExecutesFollowUpToolCall(t *testing.T) {
var bodies []map[string]any
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var body map[string]any
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
t.Fatalf("decode request: %v", err)
}
bodies = append(bodies, body)
w.Header().Set("Content-Type", "application/json")
switch len(bodies) {
case 1:
_, _ = w.Write([]byte(`{"choices":[{"message":{"content":"","tool_calls":[{"id":"call-1","function":{"name":"conformance_echo","arguments":"{\"value\":\"agent-conformance\"}"}}]}}]}`))
case 2:
_, _ = w.Write([]byte(`{"choices":[{"message":{"content":"","tool_calls":[{"id":"call-2","function":{"name":"delegate","arguments":"{\"task\":\"summarize the conformance marker\",\"to\":\"blocked-reviewer\"}"}}]}}]}`))
case 3:
_, _ = w.Write([]byte(`{"choices":[{"message":{"content":"blocked by policy"}}]}`))
default:
t.Fatalf("unexpected API call %d", len(bodies))
}
}))
defer ts.Close()
var sawEcho, sawDelegate bool
p := NewProvider(
ai.WithAPIKey("test-key"),
ai.WithBaseURL(ts.URL),
ai.WithToolHandler(func(ctx context.Context, call ai.ToolCall) ai.ToolResult {
switch call.Name {
case "conformance_echo":
sawEcho = true
return ai.ToolResult{ID: call.ID, Content: `{"marker":"agent-conformance-ok"}`}
case "delegate":
sawDelegate = true
return ai.ToolResult{ID: call.ID, Refused: ai.RefusedApproval, Content: "blocked by policy"}
default:
t.Fatalf("unexpected tool call %+v", call)
return ai.ToolResult{}
}
}),
)
resp, err := p.Generate(context.Background(), &ai.Request{
Prompt: "run conformance",
Tools: []ai.Tool{
{Name: "conformance_echo", Description: "echo conformance marker", Properties: map[string]any{"value": map[string]any{"type": "string"}}},
{Name: "delegate", Description: "delegate work", Properties: map[string]any{"task": map[string]any{"type": "string"}, "to": map[string]any{"type": "string"}}},
},
})
if err != nil {
t.Fatalf("Generate returned error: %v", err)
}
if !sawEcho || !sawDelegate {
t.Fatalf("sawEcho=%v sawDelegate=%v, want both tools executed", sawEcho, sawDelegate)
}
if len(resp.ToolCalls) != 2 {
t.Fatalf("ToolCalls = %+v, want echo and delegate", resp.ToolCalls)
}
if resp.ToolCalls[1].Name != "delegate" || resp.ToolCalls[1].Error != ai.RefusedApproval {
t.Fatalf("follow-up delegate = %+v, want refused delegate", resp.ToolCalls[1])
}
if !strings.Contains(resp.Answer, "blocked by policy") {
t.Fatalf("Answer = %q, want follow-up tool result", resp.Answer)
}
if _, ok := bodies[1]["tools"].([]any); !ok {
t.Fatalf("follow-up request did not include tools: %#v", bodies[1])
}
}
func TestProvider_GenerateExecutesMultiStepFollowUpToolCalls(t *testing.T) {
var bodies []map[string]any
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var body map[string]any
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
t.Fatalf("decode request: %v", err)
}
bodies = append(bodies, body)
w.Header().Set("Content-Type", "application/json")
switch len(bodies) {
case 1:
_, _ = w.Write([]byte(`{"choices":[{"message":{"content":"","tool_calls":[{"id":"call-plan","function":{"name":"plan","arguments":"{\"steps\":[{\"task\":\"create tasks\"},{\"task\":\"notify owner\"}]}"}}]}}]}`))
case 2:
_, _ = w.Write([]byte(`{"choices":[{"message":{"content":"","tool_calls":[{"id":"call-add","function":{"name":"task_TaskService_Add","arguments":"{\"title\":\"Design\"}"}}]}}]}`))
case 3:
_, _ = w.Write([]byte(`{"choices":[{"message":{"content":"","tool_calls":[{"id":"call-delegate","function":{"name":"delegate","arguments":"{\"task\":\"notify owner@acme.com\",\"to\":\"comms\"}"}}]}}]}`))
case 4:
_, _ = w.Write([]byte(`{"choices":[{"message":{"content":"done"}}]}`))
default:
t.Fatalf("unexpected API call %d", len(bodies))
}
}))
defer ts.Close()
var calls []string
p := NewProvider(
ai.WithAPIKey("test-key"),
ai.WithBaseURL(ts.URL),
ai.WithToolHandler(func(ctx context.Context, call ai.ToolCall) ai.ToolResult {
calls = append(calls, call.Name)
return ai.ToolResult{ID: call.ID, Content: `{"ok":true}`}
}),
)
resp, err := p.Generate(context.Background(), &ai.Request{
Prompt: "plan, create tasks, and delegate notification",
Tools: []ai.Tool{
{Name: "plan", Description: "record a plan", Properties: map[string]any{"steps": map[string]any{"type": "array"}}},
{Name: "task_TaskService_Add", Description: "add task", Properties: map[string]any{"title": map[string]any{"type": "string"}}},
{Name: "delegate", Description: "delegate work", Properties: map[string]any{"task": map[string]any{"type": "string"}, "to": map[string]any{"type": "string"}}},
},
})
if err != nil {
t.Fatalf("Generate returned error: %v", err)
}
wantCalls := []string{"plan", "task_TaskService_Add", "delegate"}
if strings.Join(calls, ",") != strings.Join(wantCalls, ",") {
t.Fatalf("tool calls = %v, want %v", calls, wantCalls)
}
if len(resp.ToolCalls) != 3 {
t.Fatalf("ToolCalls = %+v, want all multi-step calls", resp.ToolCalls)
}
if resp.Answer != "done" {
t.Fatalf("Answer = %q, want final follow-up reply", resp.Answer)
}
if len(bodies) != 4 {
t.Fatalf("requests = %d, want initial plus three follow-ups", len(bodies))
}
for i := 1; i < 4; i++ {
if _, ok := bodies[i]["tools"].([]any); !ok {
t.Fatalf("follow-up request %d did not include tools: %#v", i+1, bodies[i])
}
}
}
func TestProvider_GeneratePreservesFollowUpTextToolCallInReply(t *testing.T) {
var bodies []map[string]any
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var body map[string]any
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
t.Fatalf("decode request: %v", err)
}
bodies = append(bodies, body)
w.Header().Set("Content-Type", "application/json")
switch len(bodies) {
case 1:
_, _ = w.Write([]byte(`{"choices":[{"message":{"content":"","tool_calls":[{"id":"call-1","function":{"name":"conformance_echo","arguments":"{\"value\":\"agent-conformance\"}"}}]}}]}`))
case 2:
_, _ = w.Write([]byte(`{"choices":[{"message":{"content":"<tool_call name=\"delegate\">{\"task\":\"summarize the conformance marker\",\"to\":\"blocked-reviewer\"}</tool_call>"}}]}`))
default:
t.Fatalf("unexpected API call %d", len(bodies))
}
}))
defer ts.Close()
p := NewProvider(
ai.WithAPIKey("test-key"),
ai.WithBaseURL(ts.URL),
ai.WithToolHandler(func(ctx context.Context, call ai.ToolCall) ai.ToolResult {
if call.Name != "conformance_echo" {
t.Fatalf("unexpected structured tool call %+v", call)
}
return ai.ToolResult{ID: call.ID, Content: `{"marker":"agent-conformance-ok"}`}
}),
)
resp, err := p.Generate(context.Background(), &ai.Request{
Prompt: "run conformance",
Tools: []ai.Tool{
{Name: "conformance_echo", Description: "echo conformance marker", Properties: map[string]any{"value": map[string]any{"type": "string"}}},
{Name: "delegate", Description: "delegate work", Properties: map[string]any{"task": map[string]any{"type": "string"}, "to": map[string]any{"type": "string"}}},
},
})
if err != nil {
t.Fatalf("Generate returned error: %v", err)
}
if !strings.Contains(resp.Reply, `<tool_call name="delegate">`) {
t.Fatalf("Reply = %q, want tagged delegate follow-up for agent text fallback", resp.Reply)
}
if resp.Answer != "" {
t.Fatalf("Answer = %q, want follow-up text preserved only as Reply", resp.Answer)
}
}
func TestProvider_GenerateRetriesMinimaxBuiltInsAsTextTools(t *testing.T) {
var bodies []map[string]any
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var body map[string]any
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
t.Fatalf("decode request: %v", err)
}
bodies = append(bodies, body)
w.Header().Set("Content-Type", "application/json")
switch len(bodies) {
case 1:
http.Error(w, `{"code":400,"msg":"bad request"}`, http.StatusBadRequest)
case 2:
_, _ = w.Write([]byte(`{"choices":[{"message":{"content":"<tool_call name=\"delegate\">{\"task\":\"summarize\",\"to\":\"blocked-reviewer\"}</tool_call>"}}]}`))
default:
t.Fatalf("unexpected API call %d", len(bodies))
}
}))
defer ts.Close()
p := NewProvider(ai.WithAPIKey("test-key"), ai.WithBaseURL(ts.URL), ai.WithModel("minimaxai/minimax-m3"))
resp, err := p.Generate(context.Background(), &ai.Request{
Prompt: "plan and delegate",
Tools: []ai.Tool{
{Name: "task_TaskService_Add", Description: "add task", Properties: map[string]any{"title": map[string]any{"type": "string"}}},
{Name: "plan", Description: "record a plan", Properties: map[string]any{"steps": map[string]any{"type": "array"}}},
{Name: "request_input", Description: "request input", Properties: map[string]any{"prompt": map[string]any{"type": "string"}}},
{Name: "delegate", Description: "delegate work", Properties: map[string]any{"task": map[string]any{"type": "string"}, "to": map[string]any{"type": "string"}}},
},
})
if err != nil {
t.Fatalf("Generate returned error: %v", err)
}
if !strings.Contains(resp.Reply, `<tool_call name="delegate">`) {
t.Fatalf("Reply = %q, want text delegate fallback", resp.Reply)
}
if len(bodies) != 2 {
t.Fatalf("requests = %d, want initial plus compat retry", len(bodies))
}
initialTools := bodies[0]["tools"].([]any)
if len(initialTools) != 4 {
t.Fatalf("initial tools = %d, want all tools", len(initialTools))
}
retryTools := bodies[1]["tools"].([]any)
if len(retryTools) != 1 {
t.Fatalf("retry tools = %d, want only service tools", len(retryTools))
}
fn := retryTools[0].(map[string]any)["function"].(map[string]any)
if fn["name"] != "task_TaskService_Add" {
t.Fatalf("retry tool name = %v, want service tool only", fn["name"])
}
msgs := bodies[1]["messages"].([]any)
compat := msgs[len(msgs)-1].(map[string]any)
if compat["role"] != "system" || !strings.Contains(compat["content"].(string), `<tool_call name="tool_name">`) {
t.Fatalf("compat instruction = %#v", compat)
}
}
func TestProvider_GenerateFollowUpRetriesWithoutToolsOnBadRequest(t *testing.T) {
var bodies []map[string]any
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var body map[string]any
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
t.Fatalf("decode request: %v", err)
}
bodies = append(bodies, body)
w.Header().Set("Content-Type", "application/json")
switch len(bodies) {
case 1:
_, _ = w.Write([]byte(`{"choices":[{"message":{"content":"","tool_calls":[{"id":"call-1","function":{"name":"conformance_echo","arguments":"{\"value\":\"agent-conformance\"}"}}]}}]}`))
case 2:
http.Error(w, `{"code":400,"msg":"bad request"}`, http.StatusBadRequest)
case 3:
if _, ok := body["tools"]; ok {
t.Fatalf("no-tools retry still included tools: %#v", body["tools"])
}
_, _ = w.Write([]byte(`{"choices":[{"message":{"content":"done"}}]}`))
default:
t.Fatalf("unexpected API call %d", len(bodies))
}
}))
defer ts.Close()
var toolCalls int
p := NewProvider(
ai.WithAPIKey("test-key"),
ai.WithBaseURL(ts.URL),
ai.WithModel("minimaxai/minimax-m3"),
ai.WithToolHandler(func(ctx context.Context, call ai.ToolCall) ai.ToolResult {
toolCalls++
return ai.ToolResult{ID: call.ID, Content: `{"marker":"agent-conformance-ok"}`}
}),
)
resp, err := p.Generate(context.Background(), &ai.Request{
Prompt: "call a tool",
Tools: []ai.Tool{{Name: "conformance_echo", Description: "echo", Properties: map[string]any{"value": map[string]any{"type": "string"}}}},
})
if err != nil {
t.Fatalf("Generate returned error: %v", err)
}
if resp.Answer != "done" {
t.Fatalf("Answer = %q, want done", resp.Answer)
}
if toolCalls != 1 {
t.Fatalf("tool handler calls = %d, want one (no duplicate side effect)", toolCalls)
}
if len(bodies) != 3 {
t.Fatalf("requests = %d, want chat, failed follow-up, no-tools follow-up", len(bodies))
}
if _, ok := bodies[1]["tools"]; !ok {
t.Fatalf("first follow-up did not include tools")
}
}
func TestProvider_GenerateToolCallHTTPErrorIncludesRequestContext(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.Error(w, `{"code":400,"msg":"bad request"}`, http.StatusBadRequest)
}))
defer ts.Close()
p := NewProvider(
ai.WithAPIKey("test-key"),
ai.WithBaseURL(ts.URL),
ai.WithModel("minimaxai/minimax-m3"),
)
_, err := p.Generate(context.Background(), &ai.Request{
Prompt: "call a tool",
Tools: []ai.Tool{{
Name: "conformance_echo",
Description: "echo conformance marker",
Properties: map[string]any{"value": map[string]any{"type": "string"}},
}},
})
if err == nil {
t.Fatal("Generate error = nil, want 400")
}
msg := err.Error()
for _, want := range []string{"400 Bad Request", "atlascloud chat request", "model=minimaxai/minimax-m3", "tools=1", "tool_names=conformance_echo"} {
if !strings.Contains(msg, want) {
t.Fatalf("error %q missing %q", msg, want)
}
}
if strings.Contains(msg, "test-key") {
t.Fatalf("error leaked API key: %s", msg)
}
}
func TestProvider_Registration(t *testing.T) {
m := ai.New("atlascloud", ai.WithAPIKey("test"))
if m == nil {
t.Fatal("ai.New('atlascloud') returned nil — provider not registered")
}
if m.String() != "atlascloud" {
t.Errorf("Expected 'atlascloud', got '%s'", m.String())
}
}
func TestProvider_ImageRegistration(t *testing.T) {
ig := ai.NewImage("atlascloud", ai.WithAPIKey("test"))
if ig == nil {
t.Fatal("ai.NewImage('atlascloud') returned nil — image provider not registered")
}
if ig.String() != "atlascloud" {
t.Errorf("Expected 'atlascloud', got '%s'", ig.String())
}
}
func TestProvider_GenerateImage_NoAPIKey(t *testing.T) {
p := NewProvider()
_, err := p.GenerateImage(context.Background(), &ai.ImageRequest{Prompt: "a cat"})
if err == nil {
t.Error("Expected error when API key is missing, got nil")
}
}
func TestProvider_ImplementsImageModel(t *testing.T) {
var _ ai.ImageModel = (*Provider)(nil)
}
func TestProvider_VideoRegistration(t *testing.T) {
vg := ai.NewVideo("atlascloud", ai.WithAPIKey("test"))
if vg == nil {
t.Fatal("ai.NewVideo('atlascloud') returned nil — video provider not registered")
}
if vg.String() != "atlascloud" {
t.Errorf("Expected 'atlascloud', got '%s'", vg.String())
}
}
func TestProvider_GenerateVideo_NoAPIKey(t *testing.T) {
p := NewProvider()
_, err := p.GenerateVideo(context.Background(), &ai.VideoRequest{Prompt: "a cat"})
if err == nil {
t.Error("Expected error when API key is missing, got nil")
}
}
func TestProvider_ImplementsVideoModel(t *testing.T) {
var _ ai.VideoModel = (*Provider)(nil)
}
+140
View File
@@ -0,0 +1,140 @@
package ai
import "sort"
// CapabilityRow is one deterministic row in a provider capability matrix.
type CapabilityRow struct {
// Provider is the registered provider name.
Provider string `json:"provider"`
Capabilities
}
// Capabilities describes the AI interfaces a provider has registered.
// It is intentionally based on package registration rather than external
// provider marketing claims, so it reflects what this build can actually use.
type Capabilities struct {
// Model reports whether ai.New can construct a chat/text model provider.
Model bool `json:"model"`
// Image reports whether ai.NewImage can construct an image model provider.
Image bool `json:"image"`
// Video reports whether ai.NewVideo can construct a video model provider.
Video bool `json:"video"`
// Stream reports whether the provider has registered end-to-end token streaming.
// Providers that only satisfy the Model interface with ErrStreamingUnsupported
// leave this false until their Stream implementation is usable.
Stream bool `json:"stream"`
}
// ProviderCapabilities reports the capabilities registered for provider.
func ProviderCapabilities(provider string) Capabilities {
_, hasModel := providers[provider]
_, hasImage := imageProviders[provider]
_, hasVideo := videoProviders[provider]
_, hasStream := streamProviders[provider]
return Capabilities{
Model: hasModel,
Image: hasImage,
Video: hasVideo,
Stream: hasStream,
}
}
// CapabilityMatrix returns a snapshot of all registered AI providers and the
// interfaces they support. The returned map is a copy and can be modified by
// callers without mutating the registry. Use CapabilityRows when rendering a
// deterministic table or report.
func CapabilityMatrix() map[string]Capabilities {
names := map[string]struct{}{}
for name := range providers {
names[name] = struct{}{}
}
for name := range imageProviders {
names[name] = struct{}{}
}
for name := range videoProviders {
names[name] = struct{}{}
}
for name := range streamProviders {
names[name] = struct{}{}
}
matrix := make(map[string]Capabilities, len(names))
for name := range names {
matrix[name] = ProviderCapabilities(name)
}
return matrix
}
// CapabilityRows returns a deterministic capability support matrix for every
// registered AI provider. It is the ordered form of CapabilityMatrix, intended
// for CLIs, docs generators, and conformance reports that need stable output.
func CapabilityRows() []CapabilityRow {
names := RegisteredProviders("")
rows := make([]CapabilityRow, 0, len(names))
for _, name := range names {
rows = append(rows, CapabilityRow{
Provider: name,
Capabilities: ProviderCapabilities(name),
})
}
return rows
}
// RegisterStream records that provider has a usable Stream implementation.
// Providers should call this from init alongside Register once Stream returns
// chunks instead of ErrStreamingUnsupported.
func RegisterStream(provider string) {
streamProviders[provider] = struct{}{}
}
var streamProviders = make(map[string]struct{})
// RegisteredProviders returns the registered provider names in sorted order.
// kind may be "model", "image", "video", "stream", or empty for the union of all
// provider registries.
func RegisteredProviders(kind string) []string {
names := map[string]struct{}{}
add := func(registry any) {
switch r := registry.(type) {
case map[string]NewFunc:
for name := range r {
names[name] = struct{}{}
}
case map[string]NewImageFunc:
for name := range r {
names[name] = struct{}{}
}
case map[string]NewVideoFunc:
for name := range r {
names[name] = struct{}{}
}
case map[string]struct{}:
for name := range r {
names[name] = struct{}{}
}
}
}
switch kind {
case "model":
add(providers)
case "stream":
add(streamProviders)
case "image":
add(imageProviders)
case "video":
add(videoProviders)
default:
add(providers)
add(imageProviders)
add(videoProviders)
}
out := make([]string, 0, len(names))
for name := range names {
out = append(out, name)
}
sort.Strings(out)
return out
}
+97
View File
@@ -0,0 +1,97 @@
package ai_test
import (
"reflect"
"testing"
"go-micro.dev/v6/ai"
_ "go-micro.dev/v6/ai/anthropic"
_ "go-micro.dev/v6/ai/atlascloud"
_ "go-micro.dev/v6/ai/gemini"
_ "go-micro.dev/v6/ai/groq"
_ "go-micro.dev/v6/ai/minimax"
_ "go-micro.dev/v6/ai/mistral"
_ "go-micro.dev/v6/ai/openai"
_ "go-micro.dev/v6/ai/together"
)
func TestRegisteredProviders(t *testing.T) {
got := ai.RegisteredProviders("")
want := []string{"anthropic", "atlascloud", "gemini", "groq", "minimax", "mistral", "openai", "together"}
if !reflect.DeepEqual(got, want) {
t.Fatalf("RegisteredProviders() = %#v, want %#v", got, want)
}
got = ai.RegisteredProviders("image")
want = []string{"atlascloud", "openai"}
if !reflect.DeepEqual(got, want) {
t.Fatalf("RegisteredProviders(image) = %#v, want %#v", got, want)
}
got = ai.RegisteredProviders("video")
want = []string{"atlascloud"}
if !reflect.DeepEqual(got, want) {
t.Fatalf("RegisteredProviders(video) = %#v, want %#v", got, want)
}
got = ai.RegisteredProviders("stream")
want = []string{"anthropic", "atlascloud", "groq", "minimax", "mistral", "openai", "together"}
if !reflect.DeepEqual(got, want) {
t.Fatalf("RegisteredProviders(stream) = %#v, want %#v", got, want)
}
}
func TestCapabilityRows(t *testing.T) {
got := ai.CapabilityRows()
want := []ai.CapabilityRow{
{Provider: "anthropic", Capabilities: ai.Capabilities{Model: true, Stream: true}},
{Provider: "atlascloud", Capabilities: ai.Capabilities{Model: true, Image: true, Video: true, Stream: true}},
{Provider: "gemini", Capabilities: ai.Capabilities{Model: true}},
{Provider: "groq", Capabilities: ai.Capabilities{Model: true, Stream: true}},
{Provider: "minimax", Capabilities: ai.Capabilities{Model: true, Stream: true}},
{Provider: "mistral", Capabilities: ai.Capabilities{Model: true, Stream: true}},
{Provider: "openai", Capabilities: ai.Capabilities{Model: true, Image: true, Stream: true}},
{Provider: "together", Capabilities: ai.Capabilities{Model: true, Stream: true}},
}
if !reflect.DeepEqual(got, want) {
t.Fatalf("CapabilityRows() = %#v, want %#v", got, want)
}
}
func TestCapabilityMatrix(t *testing.T) {
matrix := ai.CapabilityMatrix()
for _, provider := range []string{"anthropic", "atlascloud", "gemini", "groq", "minimax", "mistral", "openai", "together"} {
caps, ok := matrix[provider]
if !ok {
t.Fatalf("CapabilityMatrix missing %q", provider)
}
if !caps.Model {
t.Fatalf("CapabilityMatrix(%s).Model = false, want true", provider)
}
}
if caps := ai.ProviderCapabilities("openai"); caps != (ai.Capabilities{Model: true, Image: true, Stream: true}) {
t.Fatalf("ProviderCapabilities(openai) = %#v", caps)
}
if caps := ai.ProviderCapabilities("atlascloud"); caps != (ai.Capabilities{Model: true, Image: true, Video: true, Stream: true}) {
t.Fatalf("ProviderCapabilities(atlascloud) = %#v", caps)
}
if caps := ai.ProviderCapabilities("missing"); caps != (ai.Capabilities{}) {
t.Fatalf("ProviderCapabilities(missing) = %#v", caps)
}
}
func TestRegisterStream(t *testing.T) {
ai.RegisterStream("test-stream")
if caps := ai.ProviderCapabilities("test-stream"); caps != (ai.Capabilities{Stream: true}) {
t.Fatalf("ProviderCapabilities(test-stream) = %#v", caps)
}
got := ai.RegisteredProviders("stream")
want := []string{"anthropic", "atlascloud", "groq", "minimax", "mistral", "openai", "test-stream", "together"}
if !reflect.DeepEqual(got, want) {
t.Fatalf("RegisteredProviders(stream) = %#v, want %#v", got, want)
}
}
+22
View File
@@ -0,0 +1,22 @@
// Package flow is maintained for backward compatibility.
// The canonical import is go-micro.dev/v6/flow.
package flow
import "go-micro.dev/v6/flow"
// Re-export types for backward compatibility.
type Flow = flow.Flow
type Options = flow.Options
type Option = flow.Option
type Result = flow.Result
var New = flow.New
var Trigger = flow.Trigger
var Prompt = flow.Prompt
var SystemPrompt = flow.SystemPrompt
var Provider = flow.Provider
var APIKey = flow.APIKey
var Model = flow.Model
var BaseURL = flow.BaseURL
var HistoryLimit = flow.HistoryLimit
var OnResult = flow.OnResult
+226
View File
@@ -0,0 +1,226 @@
// Package gemini implements the Google Gemini model provider.
//
// Usage:
//
// import _ "go-micro.dev/v6/ai/gemini"
//
// m := ai.New("gemini",
// ai.WithAPIKey("your-api-key"),
// )
package gemini
import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"net/http"
"strings"
"go-micro.dev/v6/ai"
)
func init() {
ai.Register("gemini", func(opts ...ai.Option) ai.Model {
return NewProvider(opts...)
})
}
// Provider implements the ai.Model interface for Google Gemini.
type Provider struct {
opts ai.Options
}
// NewProvider creates a new Gemini provider.
func NewProvider(opts ...ai.Option) *Provider {
options := ai.NewOptions(opts...)
if options.Model == "" {
options.Model = "gemini-2.5-flash"
}
if options.BaseURL == "" {
options.BaseURL = "https://generativelanguage.googleapis.com"
}
return &Provider{opts: options}
}
func (p *Provider) Init(opts ...ai.Option) error {
for _, o := range opts {
o(&p.opts)
}
return nil
}
func (p *Provider) Options() ai.Options { return p.opts }
func (p *Provider) String() string { return "gemini" }
func (p *Provider) Generate(ctx context.Context, req *ai.Request, opts ...ai.GenerateOption) (*ai.Response, error) {
var tools []map[string]any
for _, t := range req.Tools {
tools = append(tools, map[string]any{
"name": t.Name,
"description": t.Description,
"parameters": map[string]any{
"type": "object",
"properties": t.Properties,
},
})
}
contents := []map[string]any{
{"role": "user", "parts": []map[string]any{{"text": req.Prompt}}},
}
apiReq := map[string]any{
"contents": contents,
}
if req.SystemPrompt != "" {
apiReq["system_instruction"] = map[string]any{
"parts": []map[string]any{{"text": req.SystemPrompt}},
}
}
if len(tools) > 0 {
apiReq["tools"] = []map[string]any{
{"functionDeclarations": tools},
}
}
resp, rawParts, err := p.callAPI(ctx, apiReq)
if err != nil {
return nil, err
}
if len(resp.ToolCalls) == 0 {
return resp, nil
}
if p.opts.ToolHandler != nil {
var resultParts []map[string]any
for _, tc := range resp.ToolCalls {
result := p.opts.ToolHandler(ctx, tc).Value
resultParts = append(resultParts, map[string]any{
"functionResponse": map[string]any{
"name": tc.Name,
"id": tc.ID,
"response": result,
},
})
}
followUpContents := append(contents,
map[string]any{"role": "model", "parts": rawParts},
map[string]any{"role": "user", "parts": resultParts},
)
followUpReq := map[string]any{
"contents": followUpContents,
}
if req.SystemPrompt != "" {
followUpReq["system_instruction"] = map[string]any{
"parts": []map[string]any{{"text": req.SystemPrompt}},
}
}
followUpResp, _, err := p.callAPI(ctx, followUpReq)
if err == nil && followUpResp.Reply != "" {
resp.Answer = followUpResp.Reply
}
}
return resp, nil
}
func (p *Provider) Stream(ctx context.Context, req *ai.Request, opts ...ai.GenerateOption) (ai.Stream, error) {
return nil, fmt.Errorf("%w: gemini provider", ai.ErrStreamingUnsupported)
}
func (p *Provider) callAPI(ctx context.Context, req map[string]any) (*ai.Response, []map[string]any, error) {
reqBody, err := json.Marshal(req)
if err != nil {
return nil, nil, fmt.Errorf("failed to marshal request: %w", err)
}
apiURL := strings.TrimRight(p.opts.BaseURL, "/") +
"/v1beta/models/" + p.opts.Model + ":generateContent"
httpReq, err := http.NewRequestWithContext(ctx, http.MethodPost, apiURL, bytes.NewReader(reqBody))
if err != nil {
return nil, nil, fmt.Errorf("failed to create request: %w", err)
}
httpReq.Header.Set("Content-Type", "application/json")
httpReq.Header.Set("x-goog-api-key", p.opts.APIKey)
httpResp, err := http.DefaultClient.Do(httpReq)
if err != nil {
return nil, nil, fmt.Errorf("API request failed: %w", err)
}
defer httpResp.Body.Close()
respBody, _ := io.ReadAll(httpResp.Body)
if httpResp.StatusCode != http.StatusOK {
return nil, nil, ai.NewHTTPError(httpResp, respBody)
}
var geminiResp struct {
Candidates []struct {
Content struct {
Parts []struct {
Text string `json:"text"`
FunctionCall *functionCallPB `json:"functionCall"`
} `json:"parts"`
} `json:"content"`
} `json:"candidates"`
}
if err := json.Unmarshal(respBody, &geminiResp); err != nil {
return nil, nil, fmt.Errorf("failed to parse response: %w", err)
}
if len(geminiResp.Candidates) == 0 {
return nil, nil, fmt.Errorf("no response from API")
}
parts := geminiResp.Candidates[0].Content.Parts
response := &ai.Response{}
var replyParts []string
var rawParts []map[string]any
for _, part := range parts {
if part.Text != "" {
replyParts = append(replyParts, part.Text)
rawParts = append(rawParts, map[string]any{"text": part.Text})
}
if part.FunctionCall != nil {
response.ToolCalls = append(response.ToolCalls, ai.ToolCall{
ID: part.FunctionCall.ID,
Name: part.FunctionCall.Name,
Input: part.FunctionCall.Args,
})
rawParts = append(rawParts, map[string]any{
"functionCall": map[string]any{
"id": part.FunctionCall.ID,
"name": part.FunctionCall.Name,
"args": part.FunctionCall.Args,
},
})
}
}
if len(replyParts) > 0 {
response.Reply = strings.Join(replyParts, "\n")
}
return response, rawParts, nil
}
type functionCallPB struct {
ID string `json:"id"`
Name string `json:"name"`
Args map[string]any `json:"args"`
}
+105
View File
@@ -0,0 +1,105 @@
package gemini
import (
"context"
"errors"
"testing"
"go-micro.dev/v6/ai"
)
func TestProvider_String(t *testing.T) {
p := NewProvider()
if p.String() != "gemini" {
t.Errorf("Expected provider name 'gemini', got '%s'", p.String())
}
}
func TestProvider_Init(t *testing.T) {
p := NewProvider()
err := p.Init(
ai.WithModel("gemini-2.0-flash"),
ai.WithAPIKey("test-key"),
ai.WithBaseURL("https://test.com"),
)
if err != nil {
t.Fatalf("Init failed: %v", err)
}
opts := p.Options()
if opts.Model != "gemini-2.0-flash" {
t.Errorf("Expected model 'gemini-2.0-flash', got '%s'", opts.Model)
}
if opts.APIKey != "test-key" {
t.Errorf("Expected API key 'test-key', got '%s'", opts.APIKey)
}
if opts.BaseURL != "https://test.com" {
t.Errorf("Expected base URL 'https://test.com', got '%s'", opts.BaseURL)
}
}
func TestProvider_Options(t *testing.T) {
p := NewProvider(
ai.WithModel("custom-model"),
ai.WithAPIKey("my-key"),
)
opts := p.Options()
if opts.Model != "custom-model" {
t.Errorf("Expected model 'custom-model', got '%s'", opts.Model)
}
if opts.APIKey != "my-key" {
t.Errorf("Expected API key 'my-key', got '%s'", opts.APIKey)
}
}
func TestProvider_Defaults(t *testing.T) {
p := NewProvider()
opts := p.Options()
if opts.Model != "gemini-2.5-flash" {
t.Errorf("Expected default model 'gemini-2.5-flash', got '%s'", opts.Model)
}
if opts.BaseURL != "https://generativelanguage.googleapis.com" {
t.Errorf("Expected default base URL 'https://generativelanguage.googleapis.com', got '%s'", opts.BaseURL)
}
}
func TestProvider_Generate_NoAPIKey(t *testing.T) {
p := NewProvider()
req := &ai.Request{
Prompt: "Hello",
SystemPrompt: "You are helpful",
}
_, err := p.Generate(context.Background(), req)
if err == nil {
t.Error("Expected error when API key is missing, got nil")
}
}
func TestProvider_Stream_NotImplemented(t *testing.T) {
p := NewProvider()
req := &ai.Request{
Prompt: "Hello",
}
_, err := p.Stream(context.Background(), req)
if !errors.Is(err, ai.ErrStreamingUnsupported) {
t.Fatalf("Stream error = %v, want ErrStreamingUnsupported", err)
}
}
func TestProvider_Registration(t *testing.T) {
m := ai.New("gemini", ai.WithAPIKey("test"))
if m == nil {
t.Fatal("ai.New('gemini') returned nil — provider not registered")
}
if m.String() != "gemini" {
t.Errorf("Expected 'gemini', got '%s'", m.String())
}
}
+196
View File
@@ -0,0 +1,196 @@
// Package groq implements the Groq model provider.
//
// Groq provides ultra-fast inference for open-weight models via an
// OpenAI-compatible chat completions endpoint.
//
// Usage:
//
// import _ "go-micro.dev/v6/ai/groq"
//
// m := ai.New("groq",
// ai.WithAPIKey("your-api-key"),
// )
package groq
import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"net/http"
"strings"
"go-micro.dev/v6/ai"
"go-micro.dev/v6/ai/internal/openaiapi"
)
func init() {
ai.Register("groq", func(opts ...ai.Option) ai.Model {
return NewProvider(opts...)
})
ai.RegisterStream("groq")
}
type Provider struct {
opts ai.Options
}
func NewProvider(opts ...ai.Option) *Provider {
options := ai.NewOptions(opts...)
if options.Model == "" {
options.Model = "llama-3.3-70b-versatile"
}
if options.BaseURL == "" {
options.BaseURL = "https://api.groq.com/openai"
}
return &Provider{opts: options}
}
func (p *Provider) Init(opts ...ai.Option) error {
for _, o := range opts {
o(&p.opts)
}
return nil
}
func (p *Provider) Options() ai.Options { return p.opts }
func (p *Provider) String() string { return "groq" }
func (p *Provider) Generate(ctx context.Context, req *ai.Request, opts ...ai.GenerateOption) (*ai.Response, error) {
var tools []map[string]any
for _, t := range req.Tools {
tools = append(tools, map[string]any{
"type": "function",
"function": map[string]any{
"name": t.Name,
"description": t.Description,
"parameters": map[string]any{
"type": "object",
"properties": t.Properties,
},
},
})
}
messages := []map[string]any{
{"role": "system", "content": req.SystemPrompt},
{"role": "user", "content": req.Prompt},
}
apiReq := map[string]any{
"model": p.opts.Model,
"messages": messages,
}
if len(tools) > 0 {
apiReq["tools"] = tools
}
resp, rawMessage, err := p.callAPI(ctx, apiReq)
if err != nil {
return nil, err
}
if len(resp.ToolCalls) == 0 {
return resp, nil
}
if p.opts.ToolHandler != nil {
followUpMessages := append(messages, map[string]any{
"role": "assistant",
"content": rawMessage["content"],
"tool_calls": rawMessage["tool_calls"],
})
for _, tc := range resp.ToolCalls {
content := p.opts.ToolHandler(ctx, tc).Content
followUpMessages = append(followUpMessages, map[string]any{
"role": "tool",
"tool_call_id": tc.ID,
"content": content,
})
}
followUpResp, _, err := p.callAPI(ctx, map[string]any{
"model": p.opts.Model,
"messages": followUpMessages,
})
if err == nil && followUpResp.Reply != "" {
resp.Answer = followUpResp.Reply
}
}
return resp, nil
}
func (p *Provider) Stream(ctx context.Context, req *ai.Request, opts ...ai.GenerateOption) (ai.Stream, error) {
return openaiapi.Stream(ctx, p.opts, req, "/v1/chat/completions")
}
func (p *Provider) callAPI(ctx context.Context, req map[string]any) (*ai.Response, map[string]any, error) {
reqBody, err := json.Marshal(req)
if err != nil {
return nil, nil, fmt.Errorf("failed to marshal request: %w", err)
}
apiURL := strings.TrimRight(p.opts.BaseURL, "/") + "/v1/chat/completions"
httpReq, err := http.NewRequestWithContext(ctx, http.MethodPost, apiURL, bytes.NewReader(reqBody))
if err != nil {
return nil, nil, fmt.Errorf("failed to create request: %w", err)
}
httpReq.Header.Set("Content-Type", "application/json")
httpReq.Header.Set("Authorization", "Bearer "+p.opts.APIKey)
httpResp, err := http.DefaultClient.Do(httpReq)
if err != nil {
return nil, nil, fmt.Errorf("API request failed: %w", err)
}
defer httpResp.Body.Close()
respBody, _ := io.ReadAll(httpResp.Body)
if httpResp.StatusCode != http.StatusOK {
return nil, nil, ai.NewHTTPError(httpResp, respBody)
}
var chatResp struct {
Choices []struct {
Message struct {
Content string `json:"content"`
ToolCalls []struct {
ID string `json:"id"`
Function struct {
Name string `json:"name"`
Arguments string `json:"arguments"`
} `json:"function"`
} `json:"tool_calls"`
} `json:"message"`
} `json:"choices"`
}
if err := json.Unmarshal(respBody, &chatResp); err != nil {
return nil, nil, fmt.Errorf("failed to parse response: %w", err)
}
if len(chatResp.Choices) == 0 {
return nil, nil, fmt.Errorf("no response from API")
}
choice := chatResp.Choices[0]
response := &ai.Response{Reply: choice.Message.Content}
for _, tc := range choice.Message.ToolCalls {
var input map[string]any
if err := json.Unmarshal([]byte(tc.Function.Arguments), &input); err != nil {
input = map[string]any{}
}
response.ToolCalls = append(response.ToolCalls, ai.ToolCall{
ID: tc.ID,
Name: tc.Function.Name,
Input: input,
})
}
rawMessage := map[string]any{
"content": choice.Message.Content,
"tool_calls": choice.Message.ToolCalls,
}
return response, rawMessage, nil
}
+96
View File
@@ -0,0 +1,96 @@
package groq
import (
"context"
"encoding/json"
"errors"
"io"
"net/http"
"net/http/httptest"
"testing"
"go-micro.dev/v6/ai"
)
func TestProvider_String(t *testing.T) {
if NewProvider().String() != "groq" {
t.Errorf("got %q", NewProvider().String())
}
}
func TestProvider_Defaults(t *testing.T) {
opts := NewProvider().Options()
if opts.Model != "llama-3.3-70b-versatile" {
t.Errorf("default model = %q", opts.Model)
}
if opts.BaseURL != "https://api.groq.com/openai" {
t.Errorf("default base URL = %q", opts.BaseURL)
}
}
func TestProvider_Init(t *testing.T) {
p := NewProvider()
if err := p.Init(ai.WithModel("m"), ai.WithAPIKey("k")); err != nil {
t.Fatal(err)
}
if p.Options().Model != "m" || p.Options().APIKey != "k" {
t.Error("Init did not apply options")
}
}
func TestProvider_Generate_NoAPIKey(t *testing.T) {
if _, err := NewProvider().Generate(context.Background(), &ai.Request{Prompt: "hi"}); err == nil {
t.Error("expected error without API key")
}
}
func TestProvider_Stream(t *testing.T) {
var sawStream bool
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/v1/chat/completions" {
t.Fatalf("path = %s, want /v1/chat/completions", r.URL.Path)
}
var body map[string]any
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
t.Fatalf("decode request: %v", err)
}
sawStream, _ = body["stream"].(bool)
w.Header().Set("Content-Type", "text/event-stream")
_, _ = w.Write([]byte("data: {\"choices\":[{\"delta\":{\"content\":\"hel\"}}]}\n\n"))
_, _ = w.Write([]byte("data: {\"choices\":[{\"delta\":{\"content\":\"lo\"}}]}\n\n"))
_, _ = w.Write([]byte("data: [DONE]\n\n"))
}))
defer ts.Close()
p := NewProvider(ai.WithAPIKey("test-key"), ai.WithBaseURL(ts.URL))
stream, err := p.Stream(context.Background(), &ai.Request{Prompt: "Hello"})
if err != nil {
t.Fatalf("Stream returned error: %v", err)
}
defer stream.Close()
if !sawStream {
t.Fatal("stream request did not set stream=true")
}
first, err := stream.Recv()
if err != nil || first.Reply != "hel" {
t.Fatalf("first chunk = %#v, %v; want hel", first, err)
}
second, err := stream.Recv()
if err != nil || second.Reply != "lo" {
t.Fatalf("second chunk = %#v, %v; want lo", second, err)
}
if _, err := stream.Recv(); !errors.Is(err, io.EOF) {
t.Fatalf("final error = %v, want EOF", err)
}
}
func TestProvider_Registration(t *testing.T) {
m := ai.New("groq", ai.WithAPIKey("test"))
if m == nil {
t.Fatal("provider not registered")
}
if m.String() != "groq" {
t.Errorf("got %q", m.String())
}
}
+45
View File
@@ -0,0 +1,45 @@
package ai
// History is a convenience for accumulating conversation messages
// with automatic truncation. Use it to build Request.Messages for
// multi-turn conversations.
//
// hist := ai.NewHistory(50)
// hist.Add("user", "hello")
// resp, _ := m.Generate(ctx, &ai.Request{Messages: hist.Messages(), Prompt: "next"})
// hist.Add("assistant", resp.Reply)
type History struct {
messages []Message
limit int
}
// NewHistory creates an empty History. limit controls the maximum
// number of messages retained (0 = unlimited).
func NewHistory(limit int) *History {
return &History{limit: limit}
}
// Add appends a message and truncates if over limit.
func (h *History) Add(role string, content any) {
h.messages = append(h.messages, Message{Role: role, Content: content})
if h.limit > 0 && len(h.messages) > h.limit {
h.messages = h.messages[len(h.messages)-h.limit:]
}
}
// Messages returns a copy of the accumulated messages.
func (h *History) Messages() []Message {
out := make([]Message, len(h.messages))
copy(out, h.messages)
return out
}
// Len returns the number of messages.
func (h *History) Len() int {
return len(h.messages)
}
// Reset clears all messages.
func (h *History) Reset() {
h.messages = nil
}
+62
View File
@@ -0,0 +1,62 @@
package ai
import "testing"
func TestHistory_Add(t *testing.T) {
h := NewHistory(0)
h.Add("user", "hello")
h.Add("assistant", "hi")
if h.Len() != 2 {
t.Errorf("len = %d, want 2", h.Len())
}
msgs := h.Messages()
if msgs[0].Role != "user" || msgs[0].Content != "hello" {
t.Errorf("first = %+v", msgs[0])
}
if msgs[1].Role != "assistant" || msgs[1].Content != "hi" {
t.Errorf("second = %+v", msgs[1])
}
}
func TestHistory_Truncation(t *testing.T) {
h := NewHistory(3)
for _, m := range []string{"a", "b", "c", "d", "e"} {
h.Add("user", m)
}
if h.Len() != 3 {
t.Errorf("len = %d, want 3", h.Len())
}
if h.Messages()[0].Content != "c" {
t.Errorf("first retained = %+v", h.Messages()[0])
}
}
func TestHistory_Reset(t *testing.T) {
h := NewHistory(0)
h.Add("user", "hello")
h.Reset()
if h.Len() != 0 {
t.Errorf("len after reset = %d", h.Len())
}
}
func TestHistory_SnapshotIsCopy(t *testing.T) {
h := NewHistory(0)
h.Add("user", "hello")
msgs := h.Messages()
msgs[0].Content = "mutated"
if h.Messages()[0].Content == "mutated" {
t.Error("snapshot returned reference, not copy")
}
}
func TestHistory_Unlimited(t *testing.T) {
h := NewHistory(0)
for i := 0; i < 100; i++ {
h.Add("user", "msg")
}
if h.Len() != 100 {
t.Errorf("len = %d, want 100", h.Len())
}
}
+65
View File
@@ -0,0 +1,65 @@
package ai
import "context"
// ImageModel provides an interface for image generation providers.
// Providers that support image generation implement this alongside
// or instead of Model. Use NewImage to construct, or type-assert
// a provider that implements both:
//
// p := atlascloud.NewProvider(ai.WithAPIKey(key))
// if ig, ok := p.(ai.ImageModel); ok {
// resp, _ := ig.GenerateImage(ctx, req)
// }
type ImageModel interface {
GenerateImage(ctx context.Context, req *ImageRequest, opts ...GenerateOption) (*ImageResponse, error)
String() string
}
// ImageRequest describes what image to generate.
type ImageRequest struct {
// Prompt is the text description of the image to generate.
Prompt string
// Model overrides the provider's default image model.
Model string
// Size of the generated image (e.g. "1024x1024"). Provider-specific.
Size string
// N is the number of images to generate. Defaults to 1.
N int
// Quality controls generation quality. Provider-specific (e.g. "low", "medium", "high").
Quality string
// OutputFormat sets the image format (e.g. "png", "jpeg"). Provider-specific.
OutputFormat string
}
// ImageResponse holds the generated images.
type ImageResponse struct {
Images []Image
}
// Image is a single generated image, returned as a URL, base64 data, or both
// depending on the provider and request options.
type Image struct {
// URL is a remote URL where the image can be fetched.
URL string
// Base64 is the base64-encoded image data.
Base64 string
}
// NewImageFunc creates a new ImageModel instance.
type NewImageFunc func(...Option) ImageModel
var imageProviders = make(map[string]NewImageFunc)
// RegisterImage registers an image generation provider.
func RegisterImage(name string, fn NewImageFunc) {
imageProviders[name] = fn
}
// NewImage creates a new ImageModel instance based on the provider name.
func NewImage(provider string, opts ...Option) ImageModel {
if fn, ok := imageProviders[provider]; ok {
return fn(opts...)
}
return nil
}
+117
View File
@@ -0,0 +1,117 @@
package openaiapi
import (
"bufio"
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"net/http"
"strings"
"go-micro.dev/v6/ai"
)
// Stream opens an OpenAI-compatible chat completions SSE stream.
func Stream(ctx context.Context, opts ai.Options, req *ai.Request, basePath string) (ai.Stream, error) {
messages := []map[string]any{{"role": "system", "content": req.SystemPrompt}}
for _, m := range req.Messages {
messages = append(messages, map[string]any{"role": m.Role, "content": m.Content})
}
if req.Prompt != "" {
messages = append(messages, map[string]any{"role": "user", "content": req.Prompt})
}
apiReq := map[string]any{
"model": opts.Model,
"messages": messages,
"stream": true,
"stream_options": map[string]any{"include_usage": true},
}
if opts.MaxTokens > 0 {
apiReq["max_tokens"] = opts.MaxTokens
}
reqBody, err := json.Marshal(apiReq)
if err != nil {
return nil, fmt.Errorf("failed to marshal stream request: %w", err)
}
apiURL := strings.TrimRight(opts.BaseURL, "/") + basePath
httpReq, err := http.NewRequestWithContext(ctx, http.MethodPost, apiURL, bytes.NewReader(reqBody))
if err != nil {
return nil, fmt.Errorf("failed to create stream request: %w", err)
}
httpReq.Header.Set("Content-Type", "application/json")
httpReq.Header.Set("Accept", "text/event-stream")
httpReq.Header.Set("Authorization", "Bearer "+opts.APIKey)
httpResp, err := http.DefaultClient.Do(httpReq)
if err != nil {
return nil, fmt.Errorf("stream API request failed: %w", err)
}
if httpResp.StatusCode != http.StatusOK {
defer httpResp.Body.Close()
respBody, _ := io.ReadAll(httpResp.Body)
return nil, fmt.Errorf("stream API error (%s): %s", httpResp.Status, string(respBody))
}
return &StreamReader{body: httpResp.Body, scanner: bufio.NewScanner(httpResp.Body)}, nil
}
// StreamReader reads OpenAI-compatible server-sent event chunks.
type StreamReader struct {
body io.ReadCloser
scanner *bufio.Scanner
closed bool
}
func (s *StreamReader) Recv() (*ai.Response, error) {
for s.scanner.Scan() {
line := strings.TrimSpace(s.scanner.Text())
if line == "" || strings.HasPrefix(line, ":") {
continue
}
if !strings.HasPrefix(line, "data:") {
continue
}
data := strings.TrimSpace(strings.TrimPrefix(line, "data:"))
if data == "[DONE]" {
return nil, io.EOF
}
var chunk struct {
Choices []struct {
Delta struct {
Content string `json:"content"`
} `json:"delta"`
} `json:"choices"`
Usage *struct {
PromptTokens int `json:"prompt_tokens"`
CompletionTokens int `json:"completion_tokens"`
TotalTokens int `json:"total_tokens"`
} `json:"usage"`
}
if err := json.Unmarshal([]byte(data), &chunk); err != nil {
return nil, fmt.Errorf("failed to parse stream chunk: %w", err)
}
if len(chunk.Choices) > 0 && chunk.Choices[0].Delta.Content != "" {
return &ai.Response{Reply: chunk.Choices[0].Delta.Content}, nil
}
if chunk.Usage != nil {
return &ai.Response{Usage: ai.Usage{
InputTokens: chunk.Usage.PromptTokens,
OutputTokens: chunk.Usage.CompletionTokens,
TotalTokens: chunk.Usage.TotalTokens,
}}, nil
}
}
if err := s.scanner.Err(); err != nil {
return nil, err
}
return nil, io.EOF
}
func (s *StreamReader) Close() error {
if s.closed {
return nil
}
s.closed = true
return s.body.Close()
}
+196
View File
@@ -0,0 +1,196 @@
// Package minimax implements the MiniMax model provider.
//
// MiniMax offers its flagship MiniMax-M3 model via an OpenAI-compatible
// chat completions endpoint.
//
// Usage:
//
// import _ "go-micro.dev/v6/ai/minimax"
//
// m := ai.New("minimax",
// ai.WithAPIKey("your-api-key"),
// )
package minimax
import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"net/http"
"strings"
"go-micro.dev/v6/ai"
"go-micro.dev/v6/ai/internal/openaiapi"
)
func init() {
ai.Register("minimax", func(opts ...ai.Option) ai.Model {
return NewProvider(opts...)
})
ai.RegisterStream("minimax")
}
type Provider struct {
opts ai.Options
}
func NewProvider(opts ...ai.Option) *Provider {
options := ai.NewOptions(opts...)
if options.Model == "" {
options.Model = "MiniMax-M3"
}
if options.BaseURL == "" {
options.BaseURL = "https://api.minimax.io"
}
return &Provider{opts: options}
}
func (p *Provider) Init(opts ...ai.Option) error {
for _, o := range opts {
o(&p.opts)
}
return nil
}
func (p *Provider) Options() ai.Options { return p.opts }
func (p *Provider) String() string { return "minimax" }
func (p *Provider) Generate(ctx context.Context, req *ai.Request, opts ...ai.GenerateOption) (*ai.Response, error) {
var tools []map[string]any
for _, t := range req.Tools {
tools = append(tools, map[string]any{
"type": "function",
"function": map[string]any{
"name": t.Name,
"description": t.Description,
"parameters": map[string]any{
"type": "object",
"properties": t.Properties,
},
},
})
}
messages := []map[string]any{
{"role": "system", "content": req.SystemPrompt},
{"role": "user", "content": req.Prompt},
}
apiReq := map[string]any{
"model": p.opts.Model,
"messages": messages,
}
if len(tools) > 0 {
apiReq["tools"] = tools
}
resp, rawMessage, err := p.callAPI(ctx, apiReq)
if err != nil {
return nil, err
}
if len(resp.ToolCalls) == 0 {
return resp, nil
}
if p.opts.ToolHandler != nil {
followUpMessages := append(messages, map[string]any{
"role": "assistant",
"content": rawMessage["content"],
"tool_calls": rawMessage["tool_calls"],
})
for _, tc := range resp.ToolCalls {
content := p.opts.ToolHandler(ctx, tc).Content
followUpMessages = append(followUpMessages, map[string]any{
"role": "tool",
"tool_call_id": tc.ID,
"content": content,
})
}
followUpResp, _, err := p.callAPI(ctx, map[string]any{
"model": p.opts.Model,
"messages": followUpMessages,
})
if err == nil && followUpResp.Reply != "" {
resp.Answer = followUpResp.Reply
}
}
return resp, nil
}
func (p *Provider) Stream(ctx context.Context, req *ai.Request, opts ...ai.GenerateOption) (ai.Stream, error) {
return openaiapi.Stream(ctx, p.opts, req, "/v1/chat/completions")
}
func (p *Provider) callAPI(ctx context.Context, req map[string]any) (*ai.Response, map[string]any, error) {
reqBody, err := json.Marshal(req)
if err != nil {
return nil, nil, fmt.Errorf("failed to marshal request: %w", err)
}
apiURL := strings.TrimRight(p.opts.BaseURL, "/") + "/v1/chat/completions"
httpReq, err := http.NewRequestWithContext(ctx, http.MethodPost, apiURL, bytes.NewReader(reqBody))
if err != nil {
return nil, nil, fmt.Errorf("failed to create request: %w", err)
}
httpReq.Header.Set("Content-Type", "application/json")
httpReq.Header.Set("Authorization", "Bearer "+p.opts.APIKey)
httpResp, err := http.DefaultClient.Do(httpReq)
if err != nil {
return nil, nil, fmt.Errorf("API request failed: %w", err)
}
defer httpResp.Body.Close()
respBody, _ := io.ReadAll(httpResp.Body)
if httpResp.StatusCode != http.StatusOK {
return nil, nil, ai.NewHTTPError(httpResp, respBody)
}
var chatResp struct {
Choices []struct {
Message struct {
Content string `json:"content"`
ToolCalls []struct {
ID string `json:"id"`
Function struct {
Name string `json:"name"`
Arguments string `json:"arguments"`
} `json:"function"`
} `json:"tool_calls"`
} `json:"message"`
} `json:"choices"`
}
if err := json.Unmarshal(respBody, &chatResp); err != nil {
return nil, nil, fmt.Errorf("failed to parse response: %w", err)
}
if len(chatResp.Choices) == 0 {
return nil, nil, fmt.Errorf("no response from API")
}
choice := chatResp.Choices[0]
response := &ai.Response{Reply: choice.Message.Content}
for _, tc := range choice.Message.ToolCalls {
var input map[string]any
if err := json.Unmarshal([]byte(tc.Function.Arguments), &input); err != nil {
input = map[string]any{}
}
response.ToolCalls = append(response.ToolCalls, ai.ToolCall{
ID: tc.ID,
Name: tc.Function.Name,
Input: input,
})
}
rawMessage := map[string]any{
"content": choice.Message.Content,
"tool_calls": choice.Message.ToolCalls,
}
return response, rawMessage, nil
}

Some files were not shown because too many files have changed in this diff Show More