%22%22%22A%20marimo%20notebook%20that%20serves%20an%20EBM%20to%20an%20agent%20with%20%60%60ebaml-mcp%60%60%20and%20calls%20the%20tools%20like%20a%20client%20does.%22%22%22%0A%0Aimport%20marimo%0A%0A__generated_with%20%3D%20%220.25.2%22%0Aapp%20%3D%20marimo.App(width%3D%22medium%22)%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20asyncio%0A%20%20%20%20import%20os%0A%20%20%20%20import%20socket%0A%20%20%20%20import%20sys%0A%20%20%20%20import%20tempfile%0A%20%20%20%20from%20pathlib%20import%20Path%0A%0A%20%20%20%20import%20marimo%20as%20mo%0A%20%20%20%20import%20numpy%20as%20np%0A%20%20%20%20import%20orjson%0A%20%20%20%20import%20polars%20as%20pl%0A%20%20%20%20import%20skops.io%0A%20%20%20%20from%20interpret.glassbox%20import%20ExplainableBoostingClassifier%2C%20ExplainableBoostingRegressor%0A%20%20%20%20from%20mcp%20import%20Client%2C%20StdioServerParameters%2C%20types%0A%20%20%20%20from%20mcp.client.session%20import%20ElicitationFnT%0A%0A%20%20%20%20return%20(%0A%20%20%20%20%20%20%20%20Client%2C%0A%20%20%20%20%20%20%20%20ElicitationFnT%2C%0A%20%20%20%20%20%20%20%20ExplainableBoostingClassifier%2C%0A%20%20%20%20%20%20%20%20ExplainableBoostingRegressor%2C%0A%20%20%20%20%20%20%20%20Path%2C%0A%20%20%20%20%20%20%20%20StdioServerParameters%2C%0A%20%20%20%20%20%20%20%20asyncio%2C%0A%20%20%20%20%20%20%20%20mo%2C%0A%20%20%20%20%20%20%20%20np%2C%0A%20%20%20%20%20%20%20%20orjson%2C%0A%20%20%20%20%20%20%20%20os%2C%0A%20%20%20%20%20%20%20%20pl%2C%0A%20%20%20%20%20%20%20%20skops%2C%0A%20%20%20%20%20%20%20%20socket%2C%0A%20%20%20%20%20%20%20%20sys%2C%0A%20%20%20%20%20%20%20%20tempfile%2C%0A%20%20%20%20%20%20%20%20types%2C%0A%20%20%20%20)%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%20The%20MCP%20server%0A%0A%20%20%20%20%60ebaml-mcp%60%20gives%20an%20agent%20a%20fitted%20EBM%20through%20the%0A%20%20%20%20%5BModel%20Context%20Protocol%5D(https%3A%2F%2Fmodelcontextprotocol.io).%20This%20notebook%20starts%20the%20real%20server%2C%20connects%20to%20it%0A%20%20%20%20as%20a%20client%20does%2C%20and%20calls%20each%20tool.%20You%20learn%20which%20tools%20exist%2C%20what%20they%20return%2C%20how%20to%20choose%20the%0A%20%20%20%20transport%2C%20how%20the%20server%20reports%20a%20problem%2C%20and%20how%20to%20connect%20Claude%20Code%20or%20Claude%20Desktop.%0A%0A%20%20%20%20-%20You%20need%20no%20data%20download%20and%20no%20key%3A%20the%20notebook%20fits%20a%20small%20EBM%20on%20made-up%20data.%0A%20%20%20%20-%20Everything%20outside%20the%20last%20button%20runs%20without%20a%20key%20and%20sends%20no%20request%20to%20an%20LLM.%0A%20%20%20%20-%20The%20last%20section%20sends%20one%20real%20request.%20The%20default%20model%20needs%20%60OPENROUTER_API_KEY%60.%0A%20%20%20%20-%20The%20notebook%20needs%20the%20%60mcp%60%20extra%3A%20%60pip%20install%20%22ebaml%5Bmcp%5D%22%60.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Fit%20and%20save%20a%20model%0A%0A%20%20%20%20The%20server%20loads%20a%20saved%20model%20and%2C%20if%20you%20want%2C%20a%20CSV%20file%20with%20rows%20to%20explain.%20The%20notebook%20fits%20a%20binary%0A%20%20%20%20classifier%20on%20three%20features%20and%20saves%20it%20with%20%60skops.io%60.%20A%20skops%20file%20runs%20no%20code%20when%20the%20server%20loads%20it%2C%0A%20%20%20%20and%20the%20server%20trusts%20only%20the%20EBM%20classes.%20Pass%20%60interactions%3D0%60%2C%20because%20%60explain_prediction%60%20works%20for%20a%0A%20%20%20%20model%20without%20interaction%20terms.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(ExplainableBoostingClassifier%2C%20Path%2C%20np%2C%20pl%2C%20skops%2C%20tempfile)%3A%0A%20%20%20%20workdir%20%3D%20Path(tempfile.mkdtemp(prefix%3D%22ebaml-mcp-%22))%0A%20%20%20%20random_generator%20%3D%20np.random.default_rng(0)%0A%20%20%20%20people%20%3D%20pl.DataFrame(%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22age%22%3A%20random_generator.integers(18%2C%2080%2C%20500)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22income%22%3A%20random_generator.normal(50%2C%2015%2C%20500).round(1)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22city%22%3A%20random_generator.choice(%5B%22north%22%2C%20%22south%22%5D%2C%20500)%2C%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20)%0A%20%20%20%20score%20%3D%20(%0A%20%20%20%20%20%20%20%20(people%5B%22age%22%5D.to_numpy()%20-%2040)%20%2F%2020%0A%20%20%20%20%20%20%20%20%2B%20(people%5B%22income%22%5D.to_numpy()%20-%2050)%20%2F%2015%0A%20%20%20%20%20%20%20%20%2B%20(people%5B%22city%22%5D.to_numpy()%20%3D%3D%20%22north%22)%0A%20%20%20%20%20%20%20%20%2B%20random_generator.normal(size%3D500)%0A%20%20%20%20)%0A%20%20%20%20approval_threshold%20%3D%200.5%0A%20%20%20%20approved%20%3D%20(score%20%3E%20approval_threshold).astype(int)%0A%20%20%20%20classifier%20%3D%20ExplainableBoostingClassifier(feature_names%3Dpeople.columns%2C%20interactions%3D0%2C%20random_state%3D0)%0A%20%20%20%20classifier.fit(people%2C%20approved)%0A%20%20%20%20model_file%20%3D%20workdir%20%2F%20%22model.skops%22%0A%20%20%20%20data_file%20%3D%20workdir%20%2F%20%22train.parquet%22%0A%20%20%20%20skops.io.dump(classifier%2C%20model_file)%0A%20%20%20%20people.write_parquet(data_file)%0A%20%20%20%20return%20approved%2C%20data_file%2C%20model_file%2C%20people%2C%20workdir%0A%0A%0A%40app.cell%0Adef%20_(approved%2C%20data_file%2C%20mo%2C%20model_file%2C%20people)%3A%0A%20%20%20%20mo.md(f%22%22%22%0A%20%20%20%20The%20notebook%20saved%20**%7Blen(people)%7D**%20rows%20in%20%60%7Bdata_file.name%7D%60%20and%20the%20model%20in%20%60%7Bmodel_file.name%7D%60.%0A%20%20%20%20The%20share%20of%20approved%20people%20is%20**%7Bapproved.mean()%3A.2f%7D**.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Start%20the%20server%20and%20list%20the%20tools%0A%0A%20%20%20%20A%20client%20starts%20%60ebaml-mcp%60%20as%20a%20child%20process%20and%20talks%20to%20it%20over%20standard%20input%20and%20output%20(the%20%60stdio%60%0A%20%20%20%20transport).%20The%20helper%20below%20does%20the%20same%20with%20the%20SDK%20of%20the%20protocol.%20It%20starts%20a%20new%20server%20for%20each%20call%0A%20%20%20%20and%20stops%20it%20when%20the%20call%20ends%2C%20so%20every%20call%20shows%20what%20a%20fresh%20client%20sees.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Client%2C%20ElicitationFnT%2C%20Path%2C%20StdioServerParameters%2C%20sys)%3A%0A%20%20%20%20%23%20the%20ebaml-mcp%20script%20that%20%60pip%20install%20%22ebaml%5Bmcp%5D%22%60%20puts%20next%20to%20the%20Python%20of%20this%20notebook%0A%20%20%20%20command%20%3D%20str(Path(sys.executable).parent%20%2F%20%22ebaml-mcp%22)%0A%0A%20%20%20%20def%20open_session(%0A%20%20%20%20%20%20%20%20*arguments%3A%20str%2C%0A%20%20%20%20%20%20%20%20env%3A%20dict%5Bstr%2C%20str%5D%20%7C%20None%20%3D%20None%2C%0A%20%20%20%20%20%20%20%20person%3A%20ElicitationFnT%20%7C%20None%20%3D%20None%2C%0A%20%20%20%20)%20-%3E%20Client%3A%0A%20%20%20%20%20%20%20%20%22%22%22Give%20a%20client%20of%20ebaml-mcp%2C%20started%20with%20the%20arguments.%20It%20stops%20the%20server%20when%20its%20block%20ends.%0A%0A%20%20%20%20%20%20%20%20%60%60person%60%60%20answers%20the%20questions%20that%20the%20server%20asks%2C%20as%20the%20person%20at%20a%20client%20does.%0A%0A%20%20%20%20%20%20%20%20Returns%0A%20%20%20%20%20%20%20%20-------%0A%20%20%20%20%20%20%20%20Client%0A%20%20%20%20%20%20%20%20%20%20%20%20The%20client.%20Use%20it%20in%20an%20%60%60async%20with%60%60%20block.%0A%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20return%20Client(%0A%20%20%20%20%20%20%20%20%20%20%20%20StdioServerParameters(command%3Dcommand%2C%20args%3Dlist(arguments)%2C%20env%3Denv)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20elicitation_callback%3Dperson%2C%0A%20%20%20%20%20%20%20%20)%0A%0A%20%20%20%20return%20command%2C%20open_session%0A%0A%0A%40app.cell%0Aasync%20def%20_(data_file%2C%20mo%2C%20model_file%2C%20open_session)%3A%0A%20%20%20%20async%20with%20open_session(%22--model%22%2C%20str(model_file)%2C%20%22--data%22%2C%20str(data_file))%20as%20listing_session%3A%0A%20%20%20%20%20%20%20%20listing%20%3D%20await%20listing_session.list_tools()%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20%22The%20server%20offers%20**%7Bcount%7D**%20tools%20without%20%60--llm%60%3A%5Cn%5Cn%7Brows%7D%22.format(%0A%20%20%20%20%20%20%20%20%20%20%20%20count%3Dlen(listing.tools)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20rows%3D%22%5Cn%22.join(f%22-%20%60%7Btool.name%7D%60%3A%20%7Btool.description.splitlines()%5B0%5D%7D%22%20for%20tool%20in%20listing.tools)%2C%0A%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Read%20the%20model%0A%0A%20%20%20%20An%20agent%20starts%20with%20%60get_model_summary%60%20and%20%60list_features%60.%20The%20summary%20names%20the%20kind%20of%20the%20model%20and%20the%0A%20%20%20%20interaction%20terms%20that%20the%20tools%20skip.%20The%20list%20shows%20the%20features%2C%20the%20most%20important%20first.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Aasync%20def%20_(data_file%2C%20model_file%2C%20open_session%2C%20orjson)%3A%0A%20%20%20%20async%20with%20open_session(%22--model%22%2C%20str(model_file)%2C%20%22--data%22%2C%20str(data_file))%20as%20read_session%3A%0A%20%20%20%20%20%20%20%20summary_result%20%3D%20await%20read_session.call_tool(%22get_model_summary%22%2C%20%7B%7D)%0A%20%20%20%20%20%20%20%20features_result%20%3D%20await%20read_session.call_tool(%22list_features%22%2C%20%7B%7D)%0A%20%20%20%20summary%20%3D%20orjson.loads(summary_result.content%5B0%5D.text)%0A%20%20%20%20features%20%3D%20orjson.loads(features_result.content%5B0%5D.text)%5B%22features%22%5D%0A%20%20%20%20summary%0A%20%20%20%20return%20(features%2C)%0A%0A%0A%40app.cell%0Adef%20_(features%2C%20mo)%3A%0A%20%20%20%20mo.ui.table(features%2C%20selection%3DNone%2C%20label%3D%22list_features%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20Pick%20a%20feature%20and%20a%20token%20budget.%20%60get_graph%60%20returns%20the%20text%20that%20an%20LLM%20reads.%20For%20a%20continuous%20feature%2C%0A%20%20%20%20the%20server%20merges%20bins%20until%20the%20estimated%20size%20is%20near%20the%20budget.%20A%20budget%20that%20is%20too%20small%20for%20the%20graph%0A%20%20%20%20gives%20a%20tool%20error.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(features%2C%20mo)%3A%0A%20%20%20%20feature_picker%20%3D%20mo.ui.dropdown(%0A%20%20%20%20%20%20%20%20%5Bfeature%5B%22name%22%5D%20for%20feature%20in%20features%5D%2C%0A%20%20%20%20%20%20%20%20value%3Dfeatures%5B0%5D%5B%22name%22%5D%2C%0A%20%20%20%20%20%20%20%20label%3D%22Feature%22%2C%0A%20%20%20%20)%0A%20%20%20%20budget_slider%20%3D%20mo.ui.slider(1000%2C%204000%2C%20step%3D500%2C%20value%3D2000%2C%20label%3D%22max_tokens%22%2C%20show_value%3DTrue)%0A%20%20%20%20mo.hstack(%5Bfeature_picker%2C%20budget_slider%5D%2C%20justify%3D%22start%22)%0A%20%20%20%20return%20budget_slider%2C%20feature_picker%0A%0A%0A%40app.cell%0Aasync%20def%20_(%0A%20%20%20%20budget_slider%2C%0A%20%20%20%20data_file%2C%0A%20%20%20%20feature_picker%2C%0A%20%20%20%20mo%2C%0A%20%20%20%20model_file%2C%0A%20%20%20%20open_session%2C%0A)%3A%0A%20%20%20%20async%20with%20open_session(%22--model%22%2C%20str(model_file)%2C%20%22--data%22%2C%20str(data_file))%20as%20graph_session%3A%0A%20%20%20%20%20%20%20%20graph_result%20%3D%20await%20graph_session.call_tool(%0A%20%20%20%20%20%20%20%20%20%20%20%20%22get_graph%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%22feature%22%3A%20feature_picker.value%2C%20%22max_tokens%22%3A%20budget_slider.value%7D%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20graph_text%20%3D%20graph_result.content%5B0%5D.text%0A%20%20%20%20mo.callout(graph_text%2C%20kind%3D%22danger%22)%20if%20graph_result.is_error%20else%20mo.md(%0A%20%20%20%20%20%20%20%20f%22**%7Blen(graph_text)%7D**%20characters.%5Cn%5Cn%60%60%60text%5Cn%7Bgraph_text%7D%5Cn%60%60%60%22%2C%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Explain%20one%20prediction%0A%0A%20%20%20%20%60explain_prediction%60%20takes%20the%20number%20of%20a%20row%20of%20the%20data%20file%20(%60row%60)%2C%20or%20the%20value%20of%20every%20feature%0A%20%20%20%20(%60instance%60).%20It%20computes%20the%20facts%20exactly%20from%20the%20scores%20of%20the%20model%3A%20the%20counterfactual%2C%20the%20sufficient%0A%20%20%20%20reason%20and%20the%20share%20of%20completions%20with%20the%20same%20prediction.%20The%20server%20calls%20no%20LLM.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo%2C%20people)%3A%0A%20%20%20%20row_slider%20%3D%20mo.ui.slider(0%2C%20len(people)%20-%201%2C%20value%3D0%2C%20label%3D%22row%22%2C%20show_value%3DTrue)%0A%20%20%20%20confidence_slider%20%3D%20mo.ui.slider(0.5%2C%200.99%2C%20step%3D0.01%2C%20value%3D0.95%2C%20label%3D%22confidence_level%22%2C%20show_value%3DTrue)%0A%20%20%20%20mo.hstack(%5Brow_slider%2C%20confidence_slider%5D%2C%20justify%3D%22start%22)%0A%20%20%20%20return%20confidence_slider%2C%20row_slider%0A%0A%0A%40app.cell%0Aasync%20def%20_(%0A%20%20%20%20confidence_slider%2C%0A%20%20%20%20data_file%2C%0A%20%20%20%20model_file%2C%0A%20%20%20%20open_session%2C%0A%20%20%20%20orjson%2C%0A%20%20%20%20row_slider%2C%0A)%3A%0A%20%20%20%20async%20with%20open_session(%22--model%22%2C%20str(model_file)%2C%20%22--data%22%2C%20str(data_file))%20as%20explain_session%3A%0A%20%20%20%20%20%20%20%20explain_result%20%3D%20await%20explain_session.call_tool(%0A%20%20%20%20%20%20%20%20%20%20%20%20%22explain_prediction%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%22row%22%3A%20row_slider.value%2C%20%22confidence_level%22%3A%20confidence_slider.value%7D%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20explanation%20%3D%20orjson.loads(explain_result.content%5B0%5D.text)%0A%20%20%20%20facts%20%3D%20explanation%5B%22facts%22%5D%0A%20%20%20%20return%20explanation%2C%20facts%0A%0A%0A%40app.cell%0Adef%20_(facts%2C%20mo)%3A%0A%20%20%20%20prediction%20%3D%20facts%5B%22prediction%22%5D%0A%20%20%20%20changes%20%3D%20facts%5B%22counterfactual%22%5D%5B%22changes%22%5D%0A%20%20%20%20mo.md(f%22%22%22%0A%20%20%20%20The%20model%20predicts%20the%20class%20**%7Bprediction%5B%22decision%22%5D%7D**%20with%20a%20probability%20of%20**%7Bprediction%5B%22output%22%5D%3A.3f%7D**%0A%20%20%20%20(interval%20%7Bprediction%5B%22lower%22%5D%3A.3f%7D%20to%20%7Bprediction%5B%22upper%22%5D%3A.3f%7D).%0A%0A%20%20%20%20-%20**Counterfactual.**%20The%20fewest%20changes%20that%20flip%20the%20prediction%3A%0A%20%20%20%20%20%20%7B%22%3B%20%22.join(f%22%7Bc%5B'feature'%5D%7D%20from%20%7Bc%5B'from_value'%5D%7D%20to%20%7Bc%5B'to_value'%5D%7D%22%20for%20c%20in%20changes)%20or%20%22none%20exists%22%7D.%0A%20%20%20%20-%20**Sufficient%20reason.**%20These%20features%20fix%20the%20prediction%3A%20%7B%22%2C%20%22.join(facts%5B%22sufficient_reason%22%5D%5B%22features%22%5D)%7D.%0A%20%20%20%20-%20**Completions.**%20Fix%20none%20of%20the%20features%2C%20and%20the%20share%20of%20completions%20with%20the%20same%20prediction%20is%0A%20%20%20%20%20%20**%7Bfacts%5B%22completions%22%5D%5B0%5D%5B%22share%22%5D%3A.2f%7D**.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(facts%2C%20mo)%3A%0A%20%20%20%20mo.ui.table(facts%5B%22contributions%22%5D%2C%20selection%3DNone%2C%20label%3D%22Contribution%20of%20each%20feature%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(explanation%2C%20mo)%3A%0A%20%20%20%20mo.accordion(%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22The%20same%20facts%20as%20the%20texts%20of%20the%20prompts%22%3A%20mo.md(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%5Cn%5Cn%22.join(f%22**%7Bname%7D**%5Cn%5Cn%60%60%60json%5Cn%7Btext%7D%5Cn%60%60%60%22%20for%20name%2C%20text%20in%20explanation%5B%22texts%22%5D.items())%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Edit%20the%20model%0A%0A%20%20%20%20An%20agent%20can%20also%20**edit**%20the%20model%20so%20that%20it%20meets%20a%20business%20requirement%2C%20for%20example%20%22the%20approval%20must%20not%0A%20%20%20%20fall%20when%20the%20age%20goes%20up%22.%20The%20edit%20tools%20call%20no%20LLM.%20The%20agent%20is%20the%20LLM%2C%20and%20the%20tools%20stay%20exact%20and%20free.%0A%20%20%20%20The%20server%20edits%20a%20copy%20and%20never%20changes%20the%20model%20file.%20Start%20it%20with%20%60--output-dir%60%20to%20turn%20on%20%60save_model%60.%0A%0A%20%20%20%20The%20working%20order%20protects%20the%20model%20from%20a%20harmful%20edit%3A%0A%0A%20%20%20%201.%20Read%20the%20graph%20with%20%60get_graph%60%20and%20the%20bins%20with%20%60list_bins%60.%0A%20%20%20%202.%20Call%20%60preview_edit%60.%20It%20shows%20the%20changed%20bins%2C%20the%20share%20of%20the%20training%20weight%20that%20they%20hold%20and%2C%20with%0A%20%20%20%20%20%20%20%60--data%60%2C%20how%20many%20rows%20change.%20It%20changes%20nothing.%0A%20%20%20%203.%20Call%20%60apply_edit%60%20with%20a%20**reason**%2C%20the%20business%20requirement%20that%20the%20edit%20serves.%20The%20history%20keeps%20it.%0A%20%20%20%204.%20Call%20%60save_model%60%20with%20a%20message.%20The%20server%20asks%20the%20person%20to%20confirm%20the%20edits%20and%20their%20reasons.%0A%0A%20%20%20%20The%20cell%20below%20runs%20the%20steps%20in%20one%20session.%20The%20edit%20is%20one%20JSON%20object.%20Its%20field%20%60kind%60%20names%20the%20edit.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Aasync%20def%20_(%0A%20%20%20%20ElicitationFnT%2C%0A%20%20%20%20data_file%2C%0A%20%20%20%20model_file%2C%0A%20%20%20%20open_session%2C%0A%20%20%20%20orjson%2C%0A%20%20%20%20types%2C%0A%20%20%20%20workdir%2C%0A)%3A%0A%20%20%20%20edit_output%20%3D%20workdir%20%2F%20%22edited%22%0A%20%20%20%20questions_of_the_server%3A%20list%5Bstr%5D%20%3D%20%5B%5D%0A%0A%20%20%20%20async%20def%20person_confirms(%20%20%23%20ruff%3A%20ignore%5Bunused-async%5D%20--%20the%20SDK%20awaits%20the%20callback%20of%20a%20client%0A%20%20%20%20%20%20%20%20_context%2C%0A%20%20%20%20%20%20%20%20params%3A%20types.ElicitRequestParams%2C%0A%20%20%20%20)%20-%3E%20types.ElicitResult%3A%0A%20%20%20%20%20%20%20%20%22%22%22Answer%20yes%2C%20as%20a%20person%20who%20read%20the%20edits%20does.%0A%0A%20%20%20%20%20%20%20%20Returns%0A%20%20%20%20%20%20%20%20-------%0A%20%20%20%20%20%20%20%20types.ElicitResult%0A%20%20%20%20%20%20%20%20%20%20%20%20The%20answer.%0A%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20questions_of_the_server.append(params.message)%0A%20%20%20%20%20%20%20%20return%20types.ElicitResult(action%3D%22accept%22%2C%20content%3D%7B%22confirm%22%3A%20True%7D)%0A%0A%20%20%20%20monotone_age%20%3D%20%7B%22kind%22%3A%20%22Monotonize%22%2C%20%22feature%22%3A%20%22age%22%2C%20%22direction%22%3A%20%22increasing%22%7D%0A%20%20%20%20neutral_north%20%3D%20%7B%0A%20%20%20%20%20%20%20%20%22kind%22%3A%20%22SetScores%22%2C%0A%20%20%20%20%20%20%20%20%22feature%22%3A%20%22city%22%2C%0A%20%20%20%20%20%20%20%20%22selection%22%3A%20%7B%22kind%22%3A%20%22Categories%22%2C%20%22names%22%3A%20%5B%22north%22%5D%7D%2C%0A%20%20%20%20%20%20%20%20%22value%22%3A%200.0%2C%0A%20%20%20%20%7D%0A%20%20%20%20edit_steps%20%3D%20%7B%7D%0A%20%20%20%20edit_confirm%3A%20ElicitationFnT%20%3D%20person_confirms%0A%20%20%20%20async%20with%20open_session(%0A%20%20%20%20%20%20%20%20%22--model%22%2C%0A%20%20%20%20%20%20%20%20str(model_file)%2C%0A%20%20%20%20%20%20%20%20%22--data%22%2C%0A%20%20%20%20%20%20%20%20str(data_file)%2C%0A%20%20%20%20%20%20%20%20%22--output-dir%22%2C%0A%20%20%20%20%20%20%20%20str(edit_output)%2C%0A%20%20%20%20%20%20%20%20person%3Dedit_confirm%2C%0A%20%20%20%20)%20as%20edit_session%3A%0A%0A%20%20%20%20%20%20%20%20async%20def%20edit_call(name%2C%20arguments)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20result%20%3D%20await%20edit_session.call_tool(name%2C%20arguments)%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20result.is_error%2C%20result.content%5B0%5D.text%0A%0A%20%20%20%20%20%20%20%20edit_steps%5B%22tools%22%5D%20%3D%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20tool.name%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20tool%20in%20(await%20edit_session.list_tools()).tools%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20%22edit%22%20in%20tool.name%20or%20tool.name%20in%20%7B%22list_bins%22%2C%20%22save_model%22%7D%0A%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20%20%20%20%20edit_steps%5B%22bins%22%5D%20%3D%20orjson.loads((await%20edit_call(%22list_bins%22%2C%20%7B%22feature%22%3A%20%22age%22%7D))%5B1%5D)%0A%20%20%20%20%20%20%20%20edit_steps%5B%22preview%22%5D%20%3D%20orjson.loads((await%20edit_call(%22preview_edit%22%2C%20%7B%22edit%22%3A%20monotone_age%7D))%5B1%5D)%0A%20%20%20%20%20%20%20%20edit_steps%5B%22apply%22%5D%20%3D%20orjson.loads(%0A%20%20%20%20%20%20%20%20%20%20%20%20(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20await%20edit_call(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22apply_edit%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22edit%22%3A%20monotone_age%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22reason%22%3A%20%22The%20approval%20must%20not%20fall%20when%20the%20age%20goes%20up.%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22expected_revision%22%3A%20%22original%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20%20%20%20%20)%5B1%5D%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20edit_steps%5B%22apply_second%22%5D%20%3D%20orjson.loads(%0A%20%20%20%20%20%20%20%20%20%20%20%20(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20await%20edit_call(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22apply_edit%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22edit%22%3A%20neutral_north%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22reason%22%3A%20%22The%20city%20must%20not%20decide%20the%20approval.%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22expected_revision%22%3A%20edit_steps%5B%22apply%22%5D%5B%22session%22%5D%5B%22head%22%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20%20%20%20%20)%5B1%5D%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20edit_steps%5B%22stale%22%5D%20%3D%20await%20edit_call(%0A%20%20%20%20%20%20%20%20%20%20%20%20%22apply_edit%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%22edit%22%3A%20neutral_north%2C%20%22reason%22%3A%20%22Too%20late.%22%2C%20%22expected_revision%22%3A%20%22original%22%7D%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20edit_steps%5B%22unknown_kind%22%5D%20%3D%20await%20edit_call(%0A%20%20%20%20%20%20%20%20%20%20%20%20%22apply_edit%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%22edit%22%3A%20%7B%22kind%22%3A%20%22Explode%22%7D%2C%20%22reason%22%3A%20%22A%20wrong%20call.%22%7D%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20edit_steps%5B%22graph_original%22%5D%20%3D%20(await%20edit_call(%22get_graph%22%2C%20%7B%22feature%22%3A%20%22city%22%2C%20%22revision%22%3A%20%22original%22%7D))%5B1%5D%0A%20%20%20%20%20%20%20%20edit_steps%5B%22graph_current%22%5D%20%3D%20(await%20edit_call(%22get_graph%22%2C%20%7B%22feature%22%3A%20%22city%22%7D))%5B1%5D%0A%20%20%20%20%20%20%20%20edit_steps%5B%22undo%22%5D%20%3D%20orjson.loads((await%20edit_call(%22undo_edit%22%2C%20%7B%7D))%5B1%5D)%0A%20%20%20%20%20%20%20%20edit_steps%5B%22redo%22%5D%20%3D%20orjson.loads((await%20edit_call(%22redo_edit%22%2C%20%7B%7D))%5B1%5D)%0A%20%20%20%20%20%20%20%20edit_steps%5B%22history%22%5D%20%3D%20orjson.loads((await%20edit_call(%22list_edits%22%2C%20%7B%7D))%5B1%5D)%0A%20%20%20%20%20%20%20%20edit_steps%5B%22save%22%5D%20%3D%20orjson.loads(%0A%20%20%20%20%20%20%20%20%20%20%20%20(await%20edit_call(%22save_model%22%2C%20%7B%22message%22%3A%20%22Approval%20rules%20of%20the%20lending%20policy%22%7D))%5B1%5D%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20return%20edit_output%2C%20edit_steps%2C%20questions_of_the_server%0A%0A%0A%40app.cell%0Adef%20_(edit_steps%2C%20mo)%3A%0A%20%20%20%20mo.md(f%22%22%22%0A%20%20%20%20The%20server%20offered%20these%20edit%20tools%3A%20%7B%22%2C%20%22.join(f%22%60%7Bname%7D%60%22%20for%20name%20in%20edit_steps%5B%22tools%22%5D)%7D.%0A%0A%20%20%20%20%60list_bins%60%20gave%20the%20bins%20of%20%60age%60%20with%20their%20number%2C%20edges%2C%20training%20weight%20and%20score.%0A%20%20%20%20The%20first%20bins%20are%20below.%20A%20bin%20number%20is%20what%20the%20selection%20%60Bins%60%20uses.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(edit_steps%2C%20mo)%3A%0A%20%20%20%20bins_view%20%3D%20%5B%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22number%22%3A%20info%5B%22number%22%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22label%22%3A%20info%5B%22label%22%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22score%22%3A%20round(info%5B%22score%22%5D%2C%203)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22weight%22%3A%20info%5B%22weight%22%5D%2C%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20for%20info%20in%20edit_steps%5B%22bins%22%5D%5B%22bins%22%5D%5B%3A8%5D%0A%20%20%20%20%5D%0A%20%20%20%20mo.ui.table(bins_view%2C%20selection%3DNone%2C%20label%3D%22list_bins%3A%20the%20first%20bins%20of%20age%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(edit_steps%2C%20mo)%3A%0A%20%20%20%20preview%20%3D%20edit_steps%5B%22preview%22%5D%0A%20%20%20%20effect%20%3D%20preview%5B%22effect_on_data%22%5D%0A%20%20%20%20report%20%3D%20preview%5B%22report%22%5D%0A%20%20%20%20mo.md(f%22%22%22%0A%20%20%20%20%60preview_edit%60%20changed%20nothing.%20The%20report%20says%3A%20*%7Bpreview%5B%22report_text%22%5D.splitlines()%5B0%5D%7D*%20It%20changes%0A%20%20%20%20**%7Blen(report%5B%22changes%22%5D)%7D**%20bins%2C%20and%20they%20hold%20**%7Breport%5B%22weight_share%22%5D%3A.1%25%7D**%20of%20the%20training%20weight.%0A%20%20%20%20The%20weighted%20mean%20of%20the%20graph%20moves%20by%20**%7Breport%5B%22weighted_mean_shift%22%5D%3A.3g%7D**.%0A%0A%20%20%20%20With%20%60--data%60%2C%20the%20preview%20also%20counts%20the%20rows%20that%20the%20edit%20changes%3A%20**%7Beffect%5B%22rows_with_changed_value%22%5D%7D**%20of%0A%20%20%20%20**%7Beffect%5B%22row_count%22%5D%7D**%20rows%2C%20and%20**%7Beffect%5B%22rows_with_changed_class%22%5D%7D**%20of%20them%20change%20class.%20Without%20%60--data%60%2C%0A%20%20%20%20the%20field%20is%20empty%20and%20a%20note%20says%20that%20nobody%20checked%20the%20effect.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(edit_steps%2C%20mo)%3A%0A%20%20%20%20edit_errors%20%3D%20%5B%0A%20%20%20%20%20%20%20%20%7B%22call%22%3A%20%22apply_edit%20with%20a%20stale%20expected_revision%22%2C%20%22message%22%3A%20edit_steps%5B%22stale%22%5D%5B1%5D%7D%2C%0A%20%20%20%20%20%20%20%20%7B%22call%22%3A%20%22apply_edit%20with%20an%20unknown%20kind%22%2C%20%22message%22%3A%20edit_steps%5B%22unknown_kind%22%5D%5B1%5D%7D%2C%0A%20%20%20%20%5D%0A%20%20%20%20mo.md(%22Two%20calls%20that%20the%20server%20refuses.%20Each%20message%20tells%20the%20agent%20how%20to%20repair%20the%20call%3A%22)%0A%20%20%20%20mo.ui.table(edit_errors%2C%20selection%3DNone%2C%20label%3D%22Tool%20errors%22%2C%20wrapped_columns%3D%5B%22message%22%5D)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(edit_steps%2C%20mo)%3A%0A%20%20%20%20undone_count%20%3D%20edit_steps%5B%22undo%22%5D%5B%22session%22%5D%5B%22edit_count%22%5D%0A%20%20%20%20redone_count%20%3D%20edit_steps%5B%22redo%22%5D%5B%22session%22%5D%5B%22edit_count%22%5D%0A%20%20%20%20mo.md(f%22%22%22%0A%20%20%20%20%60get_graph%60%20and%20the%20other%20read%20tools%20take%20%60revision%60%3A%20%60original%60%2C%20%60current%60%20or%20the%20id%20of%20a%20commit.%20A%20read%20of%20an%0A%20%20%20%20earlier%20revision%20never%20changes%20the%20model.%20The%20graph%20of%20%60city%60%20has%20**%7Blen(edit_steps%5B%22graph_original%22%5D)%7D**%20characters%0A%20%20%20%20at%20the%20original%20revision%20and%20**%7Blen(edit_steps%5B%22graph_current%22%5D)%7D**%20at%20the%20current%20one%2C%20and%20its%20first%20line%20says%0A%20%20%20%20which%20revision%20it%20shows.%0A%0A%20%20%20%20After%20%60undo_edit%60%20the%20head%20holds%20**%7Bundone_count%7D**%20edit%2C%20and%20after%20%60redo_edit%60%20it%20holds%20**%7Bredone_count%7D**%20edits.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(edit_steps%2C%20mo)%3A%0A%20%20%20%20history_view%20%3D%20%5B%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22id%22%3A%20commit%5B%22short_id%22%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22kind%22%3A%20commit%5B%22kind%22%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22feature%22%3A%20commit%5B%22feature%22%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22type%22%3A%20commit%5B%22edit_type%22%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22reason%22%3A%20commit%5B%22reason%22%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22reviewed%22%3A%20commit%5B%22reviewed%22%5D%2C%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20for%20commit%20in%20edit_steps%5B%22history%22%5D%5B%22commits%22%5D%0A%20%20%20%20%5D%0A%20%20%20%20mo.ui.table(history_view%2C%20selection%3DNone%2C%20label%3D%22list_edits%3A%20the%20history%20before%20the%20save%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(edit_output%2C%20edit_steps%2C%20mo%2C%20questions_of_the_server%3A%20list%5Bstr%5D)%3A%0A%20%20%20%20saved%20%3D%20edit_steps%5B%22save%22%5D%0A%20%20%20%20mo.md(f%22%22%22%0A%20%20%20%20%60save_model%60%20asked%20the%20person%20to%20confirm.%20The%20question%20that%20the%20client%20showed%3A%0A%0A%20%20%20%20%60%60%60text%0A%20%20%20%20%7Bquestions_of_the_server%5B0%5D%7D%0A%20%20%20%20%60%60%60%0A%0A%20%20%20%20The%20person%20answered%20yes%2C%20so%20the%20confirmation%20is%20%60%7Bsaved%5B%22confirmation%22%5D%7D%60.%20The%20server%20wrote%0A%20%20%20%20%60%7Bsaved%5B%22model_file%22%5D%7D%60%20and%20%60%7Bsaved%5B%22history_file%22%5D%7D%60%20into%20%60%7Bedit_output.name%7D%60%20and%20marked%20the%20edits%20as%20reviewed.%0A%20%20%20%20It%20never%20overwrites%20a%20file%2C%20and%20the%20model%20file%20of%20the%20server%20is%20unchanged.%20The%20next%20session%20continues%20the%20work%0A%20%20%20%20with%20%60--edits%60.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20A%20client%20that%20cannot%20ask%20a%20person%0A%0A%20%20%20%20A%20client%20without%20elicitation%20cannot%20show%20the%20question.%20Then%20%60save_model%60%20still%20saves%2C%20but%20the%20history%20marks%20each%0A%20%20%20%20edit%20as%20**not%20reviewed%20by%20a%20person**%2C%20so%20a%20reader%20of%20the%20history%20can%20see%20that%20nobody%20confirmed%20it.%20Tell%20the%20person%0A%20%20%20%20when%20this%20happens.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Aasync%20def%20_(data_file%2C%20model_file%2C%20open_session%2C%20orjson%2C%20workdir)%3A%0A%20%20%20%20unasked_output%20%3D%20workdir%20%2F%20%22unasked%22%0A%20%20%20%20async%20with%20open_session(%0A%20%20%20%20%20%20%20%20%22--model%22%2C%0A%20%20%20%20%20%20%20%20str(model_file)%2C%0A%20%20%20%20%20%20%20%20%22--data%22%2C%0A%20%20%20%20%20%20%20%20str(data_file)%2C%0A%20%20%20%20%20%20%20%20%22--output-dir%22%2C%0A%20%20%20%20%20%20%20%20str(unasked_output)%2C%0A%20%20%20%20)%20as%20unasked_session%3A%0A%20%20%20%20%20%20%20%20await%20unasked_session.call_tool(%0A%20%20%20%20%20%20%20%20%20%20%20%20%22apply_edit%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%22edit%22%3A%20%7B%22kind%22%3A%20%22ZeroTerm%22%2C%20%22feature%22%3A%20%22income%22%7D%2C%20%22reason%22%3A%20%22The%20model%20must%20not%20use%20the%20income.%22%7D%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20unasked_save%20%3D%20orjson.loads(%0A%20%20%20%20%20%20%20%20%20%20%20%20(await%20unasked_session.call_tool(%22save_model%22%2C%20%7B%22message%22%3A%20%22No%20income%22%7D)).content%5B0%5D.text%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20unasked_history%20%3D%20orjson.loads((unasked_output%20%2F%20unasked_save%5B%22history_file%22%5D).read_bytes())%0A%20%20%20%20unasked_reviewed%20%3D%20%5Bentry%5B%22reviewed%22%5D%20for%20entry%20in%20unasked_history%5B%22entries%22%5D%5D%0A%20%20%20%20unasked_save%5B%22confirmation%22%5D%2C%20unasked_reviewed%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Choose%20the%20transport%0A%0A%20%20%20%20The%20%60stdio%60%20transport%20suits%20a%20client%20on%20the%20same%20computer.%20Use%20%60--transport%20streamable-http%60%20when%20the%20client%0A%20%20%20%20runs%20elsewhere%2C%20for%20example%20in%20a%20container.%20Then%20choose%20the%20address%20with%20%60--host%60%20and%20the%20port%20with%20%60--port%60.%0A%20%20%20%20The%20server%20has%20no%20login.%20The%20default%20host%20%60127.0.0.1%60%20accepts%20this%20computer%20only%2C%20so%20change%20it%20only%20behind%20a%0A%20%20%20%20firewall%20or%20a%20proxy%20with%20authentication.%0A%0A%20%20%20%20The%20cell%20below%20starts%20the%20server%20on%20a%20free%20port%20and%20connects%20to%20it%20over%20HTTP.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Aasync%20def%20_(Client%2C%20asyncio%2C%20command%2C%20data_file%2C%20mo%2C%20model_file%2C%20socket)%3A%0A%20%20%20%20with%20socket.socket()%20as%20probe%3A%0A%20%20%20%20%20%20%20%20probe.bind((%22127.0.0.1%22%2C%200))%0A%20%20%20%20%20%20%20%20free_port%20%3D%20probe.getsockname()%5B1%5D%0A%20%20%20%20http_server%20%3D%20await%20asyncio.create_subprocess_exec(%0A%20%20%20%20%20%20%20%20command%2C%0A%20%20%20%20%20%20%20%20%22--model%22%2C%0A%20%20%20%20%20%20%20%20str(model_file)%2C%0A%20%20%20%20%20%20%20%20%22--data%22%2C%0A%20%20%20%20%20%20%20%20str(data_file)%2C%0A%20%20%20%20%20%20%20%20%22--transport%22%2C%0A%20%20%20%20%20%20%20%20%22streamable-http%22%2C%0A%20%20%20%20%20%20%20%20%22--host%22%2C%0A%20%20%20%20%20%20%20%20%22127.0.0.1%22%2C%0A%20%20%20%20%20%20%20%20%22--port%22%2C%0A%20%20%20%20%20%20%20%20str(free_port)%2C%0A%20%20%20%20%20%20%20%20stdout%3Dasyncio.subprocess.DEVNULL%2C%0A%20%20%20%20%20%20%20%20stderr%3Dasyncio.subprocess.DEVNULL%2C%0A%20%20%20%20)%0A%20%20%20%20http_names%3A%20list%5Bstr%5D%20%3D%20%5B%5D%0A%20%20%20%20try%3A%0A%20%20%20%20%20%20%20%20for%20_attempt%20in%20range(60)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20try%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20async%20with%20Client(f%22http%3A%2F%2F127.0.0.1%3A%7Bfree_port%7D%2Fmcp%22)%20as%20http_session%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20http_names%20%3D%20%5Btool.name%20for%20tool%20in%20(await%20http_session.list_tools()).tools%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20break%0A%20%20%20%20%20%20%20%20%20%20%20%20except%20(OSError%2C%20ExceptionGroup)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20await%20asyncio.sleep(0.5)%0A%20%20%20%20finally%3A%0A%20%20%20%20%20%20%20%20http_server.terminate()%0A%20%20%20%20%20%20%20%20await%20http_server.wait()%0A%20%20%20%20mo.md(f%22The%20HTTP%20server%20listened%20on%20%60http%3A%2F%2F127.0.0.1%3A%7Bfree_port%7D%2Fmcp%60%20and%20offered%3A%20%7B'%2C%20'.join(http_names)%7D.%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Serve%20each%20kind%20of%20model%0A%0A%20%20%20%20The%20read%20tools%20work%20for%20the%20three%20kinds%20of%20EBM.%20%60explain_prediction%60%20works%20for%20a%20binary%20classifier%20without%0A%20%20%20%20interaction%20terms%20only.%20The%20notebook%20fits%20a%20regressor%2C%20a%20multiclass%20classifier%20(low%2C%20mid%20and%20high%20income)%20and%20a%0A%20%20%20%20classifier%20with%20one%20interaction%20term.%20Then%20it%20asks%20each%20server%20for%20the%20summary%2C%20and%20for%20an%20explanation.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20ExplainableBoostingClassifier%2C%0A%20%20%20%20ExplainableBoostingRegressor%2C%0A%20%20%20%20Path%2C%0A%20%20%20%20np%2C%0A%20%20%20%20people%2C%0A%20%20%20%20skops%2C%0A%20%20%20%20workdir%2C%0A)%3A%0A%20%20%20%20older_than%20%3D%2045%0A%20%20%20%20income_target%20%3D%20people%5B%22income%22%5D.to_numpy()%0A%20%20%20%20income_band%20%3D%20np.array(%5B%22low%22%2C%20%22mid%22%2C%20%22high%22%5D)%5Bnp.digitize(people%5B%22income%22%5D.to_numpy()%2C%20%5B40%2C%2060%5D)%5D%0A%20%20%20%20other_models%20%3D%20%7B%0A%20%20%20%20%20%20%20%20%22regressor%22%3A%20ExplainableBoostingRegressor(feature_names%3D%5B%22age%22%2C%20%22city%22%5D%2C%20interactions%3D0%2C%20random_state%3D0).fit(%0A%20%20%20%20%20%20%20%20%20%20%20%20people.drop(%22income%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20income_target%2C%0A%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%22multiclass%20classifier%22%3A%20ExplainableBoostingClassifier(%0A%20%20%20%20%20%20%20%20%20%20%20%20feature_names%3D%5B%22age%22%2C%20%22city%22%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20interactions%3D0%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20random_state%3D0%2C%0A%20%20%20%20%20%20%20%20).fit(people.drop(%22income%22)%2C%20income_band)%2C%0A%20%20%20%20%20%20%20%20%22classifier%20with%20an%20interaction%22%3A%20ExplainableBoostingClassifier(%0A%20%20%20%20%20%20%20%20%20%20%20%20feature_names%3Dpeople.columns%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20interactions%3D1%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20random_state%3D0%2C%0A%20%20%20%20%20%20%20%20).fit(people%2C%20(people%5B%22age%22%5D.to_numpy()%20%3E%20older_than)%20%5E%20(people%5B%22city%22%5D.to_numpy()%20%3D%3D%20%22north%22))%2C%0A%20%20%20%20%7D%0A%20%20%20%20other_instances%20%3D%20%7B%0A%20%20%20%20%20%20%20%20%22regressor%22%3A%20people.drop(%22income%22).row(0%2C%20named%3DTrue)%2C%0A%20%20%20%20%20%20%20%20%22multiclass%20classifier%22%3A%20people.drop(%22income%22).row(0%2C%20named%3DTrue)%2C%0A%20%20%20%20%20%20%20%20%22classifier%20with%20an%20interaction%22%3A%20people.row(0%2C%20named%3DTrue)%2C%0A%20%20%20%20%7D%0A%20%20%20%20other_files%3A%20dict%5Bstr%2C%20Path%5D%20%3D%20%7B%7D%0A%20%20%20%20for%20kind_name%2C%20fitted%20in%20other_models.items()%3A%0A%20%20%20%20%20%20%20%20other_files%5Bkind_name%5D%20%3D%20workdir%20%2F%20f%22%7Bkind_name.replace('%20'%2C%20'_')%7D.skops%22%0A%20%20%20%20%20%20%20%20skops.io.dump(fitted%2C%20other_files%5Bkind_name%5D)%0A%20%20%20%20return%20other_files%2C%20other_instances%0A%0A%0A%40app.cell%0Aasync%20def%20_(%0A%20%20%20%20mo%2C%0A%20%20%20%20open_session%2C%0A%20%20%20%20orjson%2C%0A%20%20%20%20other_files%3A%20%22dict%5Bstr%2C%20Path%5D%22%2C%0A%20%20%20%20other_instances%2C%0A)%3A%0A%20%20%20%20kind_rows%20%3D%20%5B%5D%0A%20%20%20%20for%20row_label%2C%20row_file%20in%20other_files.items()%3A%0A%20%20%20%20%20%20%20%20async%20with%20open_session(%22--model%22%2C%20str(row_file))%20as%20kind_session%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20kind_summary%20%3D%20orjson.loads((await%20kind_session.call_tool(%22get_model_summary%22%2C%20%7B%7D)).content%5B0%5D.text)%0A%20%20%20%20%20%20%20%20%20%20%20%20kind_features%20%3D%20orjson.loads((await%20kind_session.call_tool(%22list_features%22%2C%20%7B%7D)).content%5B0%5D.text)%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22features%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20kind_explain%20%3D%20await%20kind_session.call_tool(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22explain_prediction%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%22instance%22%3A%20other_instances%5Brow_label%5D%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20kind_rows.append(%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22model%22%3A%20row_label%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22kind%22%3A%20kind_summary%5B%22kind%22%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22features%20with%20a%20graph%22%3A%20%22%2C%20%22.join(feature%5B%22name%22%5D%20for%20feature%20in%20kind_features)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22skipped%20terms%22%3A%20%22%2C%20%22.join(kind_summary%5B%22skipped_terms%22%5D)%20or%20%22none%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22explain_prediction%22%3A%20%22tool%20error%3A%20%22%20%2B%20kind_explain.content%5B0%5D.text.split(%22.%22)%5B0%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20kind_explain.is_error%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20else%20%22works%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20mo.ui.table(kind_rows%2C%20selection%3DNone%2C%20label%3D%22One%20server%20for%20each%20model%22%2C%20wrapped_columns%3D%5B%22explain_prediction%22%5D)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20When%20something%20is%20wrong%0A%0A%20%20%20%20A%20problem%20that%20the%20user%20can%20fix%20gives%20a%20message%20with%20the%20fix.%20The%20server%20reports%20a%20mistake%20of%20a%20tool%20call%20as%20a%0A%20%20%20%20tool%20error%2C%20so%20the%20agent%20can%20read%20it%20and%20try%20again.%20A%20problem%20at%20the%20start%20stops%20the%20server%2C%20and%20the%20client%0A%20%20%20%20sees%20a%20closed%20connection.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Aasync%20def%20_(%0A%20%20%20%20data_file%2C%0A%20%20%20%20mo%2C%0A%20%20%20%20model_file%2C%0A%20%20%20%20open_session%2C%0A%20%20%20%20other_files%3A%20%22dict%5Bstr%2C%20Path%5D%22%2C%0A)%3A%0A%20%20%20%20problems%20%3D%20%7B%7D%0A%20%20%20%20async%20with%20open_session(%22--model%22%2C%20str(model_file)%2C%20%22--data%22%2C%20str(data_file))%20as%20problem_session%3A%0A%20%20%20%20%20%20%20%20problems%5B%22Unknown%20feature%22%5D%20%3D%20await%20problem_session.call_tool(%22get_graph%22%2C%20%7B%22feature%22%3A%20%22height%22%7D)%0A%20%20%20%20%20%20%20%20problems%5B%22Row%20outside%20the%20data%22%5D%20%3D%20await%20problem_session.call_tool(%22explain_prediction%22%2C%20%7B%22row%22%3A%209999%7D)%0A%20%20%20%20%20%20%20%20problems%5B%22Both%20row%20and%20instance%22%5D%20%3D%20await%20problem_session.call_tool(%0A%20%20%20%20%20%20%20%20%20%20%20%20%22explain_prediction%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%22row%22%3A%200%2C%20%22instance%22%3A%20%7B%22age%22%3A%2030%7D%7D%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20async%20with%20open_session(%22--model%22%2C%20str(model_file))%20as%20nodata_session%3A%0A%20%20%20%20%20%20%20%20problems%5B%22Row%20without%20--data%22%5D%20%3D%20await%20nodata_session.call_tool(%22explain_prediction%22%2C%20%7B%22row%22%3A%200%7D)%0A%20%20%20%20async%20with%20open_session(%22--model%22%2C%20str(other_files%5B%22regressor%22%5D))%20as%20regressor_session%3A%0A%20%20%20%20%20%20%20%20problems%5B%22Explain%20a%20regressor%22%5D%20%3D%20await%20regressor_session.call_tool(%0A%20%20%20%20%20%20%20%20%20%20%20%20%22explain_prediction%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%22instance%22%3A%20%7B%22age%22%3A%2030%2C%20%22city%22%3A%20%22north%22%7D%7D%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20problem_rows%20%3D%20%5B%0A%20%20%20%20%20%20%20%20%7B%22situation%22%3A%20situation%2C%20%22tool%20error%22%3A%20result.is_error%2C%20%22message%22%3A%20result.content%5B0%5D.text%7D%0A%20%20%20%20%20%20%20%20for%20situation%2C%20result%20in%20problems.items()%0A%20%20%20%20%5D%0A%20%20%20%20mo.ui.table(problem_rows%2C%20selection%3DNone%2C%20label%3D%22Tool%20errors%22%2C%20wrapped_columns%3D%5B%22message%22%5D)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20Two%20more%20problems%20stop%20the%20server%20at%20the%20start.%20The%20server%20never%20loads%20a%20file%20that%20a%20tool%20names%3A%20only%20the%0A%20%20%20%20command%20line%20of%20the%20user%20names%20the%20files.%20A%20file%20that%20holds%20an%20object%20other%20than%20an%20EBM%20fails%20with%20a%20message%2C%0A%20%20%20%20and%20a%20skops%20file%20with%20another%20type%20fails%20because%20the%20loader%20trusts%20only%20the%20EBM%20classes.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Aasync%20def%20_(asyncio%2C%20command%2C%20mo%2C%20skops%2C%20workdir)%3A%0A%20%20%20%20not_a_model%20%3D%20workdir%20%2F%20%22not_a_model.skops%22%0A%20%20%20%20skops.io.dump(%7B%22this%22%3A%20%22is%20a%20dict%22%7D%2C%20not_a_model)%0A%20%20%20%20failed_server%20%3D%20await%20asyncio.create_subprocess_exec(%0A%20%20%20%20%20%20%20%20command%2C%0A%20%20%20%20%20%20%20%20%22--model%22%2C%0A%20%20%20%20%20%20%20%20str(not_a_model)%2C%0A%20%20%20%20%20%20%20%20stdout%3Dasyncio.subprocess.DEVNULL%2C%0A%20%20%20%20%20%20%20%20stderr%3Dasyncio.subprocess.PIPE%2C%0A%20%20%20%20)%0A%20%20%20%20_%2C%20error_output%20%3D%20await%20failed_server.communicate()%0A%20%20%20%20start_failure%20%3D%20error_output.decode().strip().splitlines()%5B-1%5D%0A%20%20%20%20mo.md(f%22The%20last%20line%20of%20the%20output%20of%20the%20server%3A%5Cn%5Cn%60%60%60text%5Cn%7Bstart_failure%7D%5Cn%60%60%60%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20The%20LLM%20tools%20need%20%60--llm%20PROVIDER%2FMODEL%60.%20A%20server%20that%20starts%20without%20a%20key%20for%20the%20provider%20answers%20a%20call%0A%20%20%20%20with%20the%20steps%20to%20fix%20it.%20The%20cell%20below%20starts%20the%20server%20with%20%60--llm%20openrouter%2Fopenrouter%2Ffree%60%20and%20no%20key%2C%0A%20%20%20%20so%20it%20sends%20no%20request.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Aasync%20def%20_(data_file%2C%20mo%2C%20model_file%2C%20open_session)%3A%0A%20%20%20%20async%20with%20open_session(%0A%20%20%20%20%20%20%20%20%22--model%22%2C%0A%20%20%20%20%20%20%20%20str(model_file)%2C%0A%20%20%20%20%20%20%20%20%22--data%22%2C%0A%20%20%20%20%20%20%20%20str(data_file)%2C%0A%20%20%20%20%20%20%20%20%22--llm%22%2C%0A%20%20%20%20%20%20%20%20%22openrouter%2Fopenrouter%2Ffree%22%2C%0A%20%20%20%20)%20as%20keyless_session%3A%0A%20%20%20%20%20%20%20%20keyless_tools%20%3D%20%5Btool.name%20for%20tool%20in%20(await%20keyless_session.list_tools()).tools%5D%0A%20%20%20%20%20%20%20%20keyless_result%20%3D%20await%20keyless_session.call_tool(%22describe_feature%22%2C%20%7B%22feature%22%3A%20%22age%22%7D)%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20f%22The%20server%20offered%20**%7Blen(keyless_tools)%7D**%20tools.%20The%20call%20of%20%60describe_feature%60%20answered%3A%5Cn%5Cn%22%0A%20%20%20%20%20%20%20%20f%22%60%60%60text%5Cn%7Bkeyless_result.content%5B0%5D.text%7D%5Cn%60%60%60%22%2C%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Connect%20a%20client%0A%0A%20%20%20%20Claude%20Code%20starts%20the%20server%20for%20you.%20Replace%20the%20paths%20with%20the%20files%20that%20you%20saved%3A%0A%0A%20%20%20%20%60%60%60bash%0A%20%20%20%20claude%20mcp%20add%20ebaml%20--%20ebaml-mcp%20--model%20%2Fpath%2Fto%2Fmodel.skops%20--data%20%2Fpath%2Fto%2Ftrain.parquet%0A%20%20%20%20%60%60%60%0A%0A%20%20%20%20Claude%20Desktop%20reads%20an%20entry%20in%20%60claude_desktop_config.json%60%3A%0A%0A%20%20%20%20%60%60%60json%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%22mcpServers%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%22ebaml%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%22command%22%3A%20%22ebaml-mcp%22%2C%0A%20%20%20%20%20%20%20%20%20%20%22args%22%3A%20%5B%22--model%22%2C%20%22%2Fpath%2Fto%2Fmodel.skops%22%2C%20%22--data%22%2C%20%22%2Fpath%2Fto%2Ftrain.parquet%22%5D%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%20%20%60%60%60%0A%0A%20%20%20%20A%20client%20usually%20starts%20the%20server%20with%20a%20small%20environment.%20To%20use%20%60--llm%60%2C%20give%20the%20client%20the%20key.%20In%20Claude%0A%20%20%20%20Code%2C%20add%20%60--env%20OPENROUTER_API_KEY%3D...%60%20to%20the%20command.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Put%20it%20in%20words%0A%0A%20%20%20%20The%20last%20cell%20sends%20**one%20real%20request**%20to%20the%20LLM%20through%20%60describe_feature%60.%20The%20server%20needs%0A%20%20%20%20%60OPENROUTER_API_KEY%60.%20Pass%20another%20%60PROVIDER%2FMODEL%60%20to%20%60--llm%60%20to%20use%20another%20model%2C%20as%20the%20documentation%20page%0A%20%20%20%20%22Choosing%20the%20model%22%20shows.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo%2C%20os)%3A%0A%20%20%20%20key_from_env%20%3D%20bool(os.environ.get(%22OPENROUTER_API_KEY%22))%0A%20%20%20%20api_key_input%20%3D%20None%20if%20key_from_env%20else%20mo.ui.text(kind%3D%22password%22%2C%20label%3D%22OpenRouter%20API%20key%22%2C%20full_width%3DTrue)%0A%20%20%20%20key_status%20%3D%20(%0A%20%20%20%20%20%20%20%20mo.callout(%22Loaded%20%60OPENROUTER_API_KEY%60%20from%20the%20environment.%22%2C%20kind%3D%22success%22)%0A%20%20%20%20%20%20%20%20if%20key_from_env%0A%20%20%20%20%20%20%20%20else%20mo.vstack(%5Bmo.callout(%22%60OPENROUTER_API_KEY%60%20is%20not%20set%20in%20the%20environment.%22%2C%20kind%3D%22warn%22)%2C%20api_key_input%5D)%0A%20%20%20%20)%0A%20%20%20%20key_status%0A%20%20%20%20return%20(api_key_input%2C)%0A%0A%0A%40app.cell%0Adef%20_(api_key_input%2C%20os)%3A%0A%20%20%20%20%23%20a%20typed%20key%20only%20lives%20in%20this%20process%3B%20the%20notebook%20passes%20it%20to%20the%20server%20that%20it%20starts%0A%20%20%20%20api_key%20%3D%20(%0A%20%20%20%20%20%20%20%20api_key_input.value%0A%20%20%20%20%20%20%20%20if%20api_key_input%20is%20not%20None%20and%20api_key_input.value%0A%20%20%20%20%20%20%20%20else%20os.environ.get(%22OPENROUTER_API_KEY%22%2C%20%22%22)%0A%20%20%20%20)%0A%20%20%20%20return%20(api_key%2C)%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20describe_button%20%3D%20mo.ui.run_button(label%3D%22Ask%20the%20LLM%20to%20describe%20the%20feature%22)%0A%20%20%20%20describe_button%0A%20%20%20%20return%20(describe_button%2C)%0A%0A%0A%40app.cell%0Aasync%20def%20_(%0A%20%20%20%20api_key%2C%0A%20%20%20%20data_file%2C%0A%20%20%20%20describe_button%2C%0A%20%20%20%20feature_picker%2C%0A%20%20%20%20mo%2C%0A%20%20%20%20model_file%2C%0A%20%20%20%20open_session%2C%0A%20%20%20%20os%2C%0A)%3A%0A%20%20%20%20mo.stop(not%20describe_button.value%2C%20mo.md(%22*Press%20the%20button%20to%20send%20the%20request.*%22))%0A%20%20%20%20mo.stop(not%20api_key%2C%20mo.callout(%22Set%20%60OPENROUTER_API_KEY%60%20first.%22%2C%20kind%3D%22warn%22))%0A%20%20%20%20%23%20the%20server%20needs%20the%20key%20in%20its%20own%20environment%2C%20because%20a%20client%20starts%20it%20with%20a%20small%20one%0A%20%20%20%20async%20with%20open_session(%0A%20%20%20%20%20%20%20%20%22--model%22%2C%0A%20%20%20%20%20%20%20%20str(model_file)%2C%0A%20%20%20%20%20%20%20%20%22--data%22%2C%0A%20%20%20%20%20%20%20%20str(data_file)%2C%0A%20%20%20%20%20%20%20%20%22--llm%22%2C%0A%20%20%20%20%20%20%20%20%22openrouter%2Fopenrouter%2Ffree%22%2C%0A%20%20%20%20%20%20%20%20env%3D%7B%22PATH%22%3A%20os.environ%5B%22PATH%22%5D%2C%20%22OPENROUTER_API_KEY%22%3A%20api_key%7D%2C%0A%20%20%20%20)%20as%20llm_session%3A%0A%20%20%20%20%20%20%20%20llm_result%20%3D%20await%20llm_session.call_tool(%22describe_feature%22%2C%20%7B%22feature%22%3A%20feature_picker.value%7D)%0A%20%20%20%20mo.callout(llm_result.content%5B0%5D.text%2C%20kind%3D%22danger%22%20if%20llm_result.is_error%20else%20%22neutral%22)%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
cb6bdfa396c0f289f65fc5fe6e37a0de